Appcelerator Hyperloop use TiApplication Class - titanium

I am trying to use Hyperloop to use the isCurrentActivityInForeground method inside org.appcelerator.titanium.TiApplication
https://github.com/appcelerator/titanium_mobile/blob/master/android/titanium/src/java/org/appcelerator/titanium/TiApplication.java
I have tried the following and some other ways but I am unable to require the class - Any suggestions?
var TiApplicationClass = require('org.appcelerator.titanium.TiApplication');
var TiApplication = new TiApplicationClass;
var isInForeground = TiApplication.isCurrentActivityInForeground();
Ti.API.log("isInForeground");
Ti.API.log(isInForeground);
PS. I have asked in the slack channels multiple times but no help

I think benCoding.Android.Tools module is what you need: https://github.com/benbahrenburg/benCoding.Android.Tools
if (OS_ANDROID) {
var platformTools = require('bencoding.android.tools').createPlatform(),
wasInForeGround = true;
setInterval(function() {
var isInForeground = platformTools.isInForeground();
if (wasInForeGround !== isInForeground) {
Ti.App.fireEvent(isInForeground ? 'resumed' : 'paused');
wasInForeGround = isInForeground;
}
}, 3000);
}
Sample code credits to Fokke Zandbergen: http://www.tidev.io/2014/01/28/paused-resumed-events-on-android/

The internal SDK classes are not accessible via Hyperloop so far. But I like the idea! Can you create a ticket the Appcelerator JIRA so it can be scheduled?

Related

Dialogflow .NET core, C# - detect intent not working

I want to invoke DetectIntent programatically.
I am using Google.Cloud.Dialogflow.V2 - Client libraries.
using Google.Cloud.Dialogflow.V2;
var query = new QueryInput
{
Text = new TextInput
{
Text = text,
LanguageCode = "en-us"
}
};
var sessionId = "1234567890";
var agent = "myAgentName";
var creds = GoogleCredential.FromFile("JSONFileName");
Channel channel = new Channel(
SessionsClient.DefaultEndpoint.Host, SessionsClient.DefaultEndpoint.Port, creds.ToChannelCredentials());
var client = SessionsClient.Create(channel);
DetectIntentRequest request = new DetectIntentRequest
{
SessionAsSessionName = new SessionName("smartresort-facebook-bot-fgvjh", "1111"),
QueryInput = query,
};
DetectIntentResponse response = client.DetectIntent(request);
With above code I am getting error as below
I am already using same JSON file in node js code and it is working fine. So in nodejs detect intent code is working fine. I am trying to do the same in .NET core.
After this I have tried another code snippet.
var client = SessionsClient.Create();
var response = client.DetectIntent(
session: new SessionName("smartresort-facebook-bot-fgvjh", "1234567890"),
queryInput: new QueryInput()
{
Text = new TextInput()
{
Text = text,
LanguageCode = "en-us"
}
}
);
I am not trying to write fulfillment which would be called after the intent is detected. I am trying to write the code before intent is detected. So I want to give a call to detect intent and then process the response based on which intent is detected.
Check my answer here, It is an example on how to integrate Dialogflow with .Net Core based on a working sample. If you still have more questions let me know and I will be happy to help!

Some problems with testing Akka.net

Version Akka.NET v1.3.8
Version Akka.TestKit.NUnit3 v1.3.2
Version NUnit v3.10.1
Platform Windows 10
I have an actor of the following kind:
public class BranchUsersActor : ReceiveActor
{
public BranchUsersActor()
{
Receive<UserBeingOnline>((online) =>
{
var userActorName = $"user_{online.UserId}";
if (Context.Child(userActorName).Equals(ActorRefs.Nobody))
{
var user = Context.ActorOf(UserActor.Props(online.UserId, online.BranchId), userActorName);
user.Tell(online);
}
});
}
public static Props Props(LoggingTags tags)
{
return Akka.Actor.Props.Create(() => new BranchUsersActor(tags));
}
}
When testing this actor, I expect that I will have a child actor.
I'm writing the next test to check this situation (using the NUnit framework):
[Test]
public void Test()
{
var branchUserActor = Sys.ActorOf(BranchUsersActor.Props());
branchUserActor.Tell(UserBeingOnline.Create(userId, branchId));
var expectedChildActor = Sys.ActorSelection($"{actorPath}/user_{userId.AkkaPrepare()}")
.ResolveOne(TimeSpan.FromSeconds(1)).Result;
Assert.IsNotNull(expectedChildActor);
}
I expect that within a second I will receive the child actor on the specified path, but I get ActorNotFoundExpection.
If I'm doing something like this:
[Test]
public void Test()
{
var branchUserActor = Sys.ActorOf(BranchUsersActor.Props());
branchUserActor.Tell(UserBeingOnline.Create(userId, branchId));
Task.Delay(100).ContinueWith(_ =>
{
var expectedChildActor = Sys.ActorSelection($"{actorPath}/user_{userId.AkkaPrepare()}")`enter code here`
.ResolveOne(TimeSpan.FromSeconds(1)).Result;
}
Assert.IsNotNull(expectedChildActor);
}
This works fine, but 1 of 10 times the test falls, because I get an ActorNotFoundException.
But I wonder why the first option does not work the way I expect?
Am I doing something wrong?
Thanks in advance for the answer.
branchUserActor.Tell(UserBeingOnline.Create(userId, branchId));
var expectedChildActor = Sys.ActorSelection($"{actorPath}/user_{userId.AkkaPrepare()}")
.ResolveOne(TimeSpan.FromSeconds(1)).Result;
The problem here is that when you're telling UserBeingOnline, you're triggering an asynchronous action - a message has been send to branchUserActor, but it may not have been processed right away. In the meantime you're calling resolve one, which tells actor system to find a child of branchUserActor - a child, which is not yet there, since the parent didn't handle the message yet.
You can use AwaitAssert(() => Assert.IsNotNull(ResolveChild())) method to work with that.

Why the function "onaddstream" is never called?

Hello I followed this tutorial to create a simple webrtc example.
https://www.webrtc-experiment.com/docs/WebRTC-PeerConnection.html .
So look my JFFiddle:
https://jsfiddle.net/xzspquew/9/
and tell me please why I can't enter to the function onaddstream ? The console.log("this function is called") is neved called. Why ?
navigator.getUserMedia({audio:false, video:true}, success, error)
var pc = new RTCPeerConnection()
var pc2 = new RTCPeerConnection()
pc.onaddstream = function(event) {
console.log("this function is called")
var video2 = document.getElementById("video2")
video2.src = window.URL.createObjectURL(event.stream)
video2.play()
}
document.querySelector("#repondre").addEventListener('click', function repondre() {
var answer = prompt("Please enter your sdp remote offer");
console.log(answer)
pc2.setRemoteDescription(JSON.parse(answer))
pc2.createAnswer(successanswerrtc, errorrtc)
})
function successanswerrtc(answersdp) {
pc2.setLocalDescription(answersdp)
console.log(JSON.stringify(answersdp))
pc.setRemoteDescription(answersdp)
}
function sucessrtc(offersdp) {
pc.setLocalDescription(offersdp)
alert(JSON.stringify(offersdp))
console.log(JSON.stringify(offersdp))
}
function errorrtc(err) {
console.log("error" + err)
}
function success(stream) {
var video1 = document.getElementById("video1")
video1.src = window.URL.createObjectURL(stream)
video1.play()
pc.createOffer(sucessrtc, errorrtc)
}
function error() {
console.log("error")
}
That tutorial appears to be outdated. Perhaps https://webrtc.org/start/#demos-and-samples
According to MDN documentation, it has been deprecated:
https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/onaddstream
This property has been removed from the specification; you should now use RTCPeerConnection.ontrack to watch for track events instead. It is included here in order to help you adapt existing code and understand existing samples, which may not be up-to-date yet.
It looks you are trying with an outdated demo,
Try this demo from WebRTC official samples
In your fiddle you didn't handled the candidates & streams properly .
If you are making a call from pc to pc2, you need to add stream to pc by calling pc.addstream(stream) then pc2.onaddstream or pc2.onaddtrack method will triggered.
I updated your fiddle https://jsfiddle.net/8mchrc3v/1/

Configure UniCastBus in NServiceBus using IWantToRunBeforeConfigurationIsFinalized

I would like to "hook in" and tweak configuration to UnicastBus and was looking at doing this using IWantToRunBeforeConfigurationIsFinalized.
I would like to tweak/set the value for: ForwardReceivedMessagesTo. Any ideas on how that should be done?
Unfortunately due to a bug (see https://github.com/Particular/NServiceBus/issues/1960), the only possible way is to programmatically replace the whole UnicastBusConfig, eg:
class Foo : IProvideConfiguration<UnicastBusConfig>
{
public UnicastBusConfig GetConfiguration()
{
var unicastBusConfig = new UnicastBusConfig
{
ForwardReceivedMessagesTo = "FooBar",
};
unicastBusConfig.MessageEndpointMappings = new MessageEndpointMappingCollection();
unicastBusConfig.MessageEndpointMappings.Add(...);
return unicastBusConfig;
}
}
But that is quite ugly :(

log4javascript - obtain history of messages programmatically?

I'm looking into using a javascript logging framework in my app.
I quite like the look of log4javascript (http://log4javascript.org/) but I have one requirement which I'm not sure that it satisfies.
I need to be able to ask the framework for all messages which have been logged.
Perhaps I could use an invisible InPageAppender (http://log4javascript.org/docs/manual.html#appenders) to log to a DOM element, then scrape out the messages from that DOM element - but that seems pretty heavy.
Perhaps I need to write my own "InMemoryAppender"?
There's an ArrayAppender used in log4javascript's unit tests that stores all log messages it receives in an array accessible via its logMessages property. Hopefully it should show up in the main distribution in the next version. Here's a standalone implementation:
var ArrayAppender = function(layout) {
if (layout) {
this.setLayout(layout);
}
this.logMessages = [];
};
ArrayAppender.prototype = new log4javascript.Appender();
ArrayAppender.prototype.layout = new log4javascript.NullLayout();
ArrayAppender.prototype.append = function(loggingEvent) {
var formattedMessage = this.getLayout().format(loggingEvent);
if (this.getLayout().ignoresThrowable()) {
formattedMessage += loggingEvent.getThrowableStrRep();
}
this.logMessages.push(formattedMessage);
};
ArrayAppender.prototype.toString = function() {
return "[ArrayAppender]";
};
Example use:
var log = log4javascript.getLogger("main");
var appender = new ArrayAppender();
log.addAppender(appender);
log.debug("A message");
alert(appender.logMessages);