Don't understand how to structurize this java code to work in typescript(javascript):
channel.join().receive("ok", new IMessageCallback() {
#Override
public void onMessage(Envelope envelope) {
System.out.println("JOINED with " + envelope.toString());
}
});
Code found here: https://github.com/eoinsha/JavaPhoenixChannels
Was thinking about something like this:
var phoenix = (org as any).phoenixframework.channels;
var callback = new phoenix.IMessageCallback({
onMessage: function (arg) {
console.log('callback');
}
});
channel.join().receive("ok", callback);
It compiles successfully and no errors are thrown, but I don't get my callback when I join the channel.
Any insights appreciated!
-- UPDATE
Turns out I was doing it correctly, problem in connection lied elsewhere, thanks all who pitched in! :)
If you want to implement a Java interface you can use the following syntax.
var clickListener = android.view.View.OnClickListener({
onClick: function (view) {
// Do something on click
}
});
You can refer to the documentation article about android runtime and the data conversion techniques
I'd like to add to Nick Iliev's answer
The correct way to extend the interface in question is the following
var callback = new org.phoenixframework.channels.IMessageCallback({
onMessage: function (arg) {
console.log('callback');
}
});
You need to specify the full class name, that includes package + class name (org.phoenixframework.channels + IMessageCallback)
Related
I was trying to find information on the web and could not know exactly what a helper was and what it was used for. if someone could answer me. I found this example on the web:
// controller.js
callServer: function(cmp, helper) {
helper.callServer();
}
//helper.js ()
callServer: function(cmp, helper) {
var action = cmp.get("c.getAccounts");
$A.enqueueAction(action);
}
I am having problems with my Unity3D calling Firebase Functions function. My code is actually copied from https://firebase.google.com/docs/functions/callable.
My function code is following: (just copied this file actually)
https://github.com/firebase/quickstart-js/blob/a579893cfa33121952aeed9069c1554ed4e65b7e/functions/functions/index.js#L44-L50
and in Unity I have this:
//Create the arguments to the callable function.
var data = new Dictionary<string, object>();
data["text"] = "message";
data["push"] = true;
//Call the function and extract the operation from the result.
var function = FirebaseFunctions.DefaultInstance.GetHttpsCallable("addMessage");
function.CallAsync(data).ContinueWith((task) => {
if (task.IsFaulted)
{
foreach (var inner in task.Exception.InnerExceptions)
{
if (inner is FunctionsException)
{
Debug.Log(inner.Message);
}
}
}
else
{
Debug.Log("Finished: " + task.Result.Data);
}
});
But I am getting this result:
Response is not valid JSON object.
What am I doing wrong?
Thank you for your help!!!
I was still working on that problem and suddenly it worked. I dont know why to be honest, because the could looks exactely the same and I did not change anything on that.
I plowed through the docs and haven't found a solution yet. The app is loosely based on the "sayHello"-example from their docs but every time the code runs the warning Method handler for /eventComm.DatabaseRPC/InsertSingleDocument expected but not provided is returned.
My proto file:
service DatabaseRPC {
rpc InsertSingleDocument (Doc) returns (Doc) {}
}
message Doc {
required string name = 1;
required int32 id = 2;
}
My gRPC Server:
function InsertSingleDocument (call, callback) {
callback(null, {
name: 'Hello ',
id: 1
})
}
let server = new grpc.Server()
server.addProtoService(protoDef.DatabaseRPC.service, {
InsertSingleDocument: InsertSingleDocument
})
server.bind('0.0.0.0:50051', grpc.ServerCredentials.createInsecure())
server.start()
What is the problem with this code? Of course I already tried to google the error but found no solution
To conform with JavaScript naming conventions, methods should be provided with the first letter lowercased:
server.addProtoService(protoDef.DatabaseRPC.service, {
insertSingleDocument: InsertSingleDocument
})
You can see this in the Hello World example you linked. The method is declared as SayHello in the proto file, but is passed to the server as sayHello.
Note: I agree that this is confusing, and I will try to improve the situation.
I'm creating an Office Add-in and am having trouble with the javascript file.getFileAsync method in Word Online (Word 2013 desktop is fine).
I'm using sample code from github...
https://github.com/OfficeDev/office-js-docs/blob/master/docs/word/get-the-whole-document-from-an-add-in-for-powerpoint-or-word.md
My code looks like this...
function getFile() {
Office.context.document.getFileAsync(Office.FileType.Text,
{ sliceSize: 65536},
function (result) {
if (result.status == Office.AsyncResultStatus.Succeeded) {
// Get the File object from the result.
var myFile = result.value;
var state = {
file: myFile,
counter: 0,
sliceCount: myFile.sliceCount
};
getSlice(state);
}
});
}
function getSlice(state) {
state.file.getSliceAsync(state.counter, function (result) {
if (result.status == Office.AsyncResultStatus.Succeeded) {
sendSlice(result.value, state);
state.file.closeAsync();
}
else if(result.status == 'failed')
state.file.closeAsync();
});
}
Before calling file.getSliceAsync the data looks good - myFile.sliceCount is 1. The result function is never called and no errors are thrown in the console.
Thanks for any help you can provide!
UPDATE: this issue is fixed and live. Please try it again it must work now.
thanks!
---------------- ORIGINAL ANSWER JUST FOR REFERENCE ----------------------------
Yes, there is a regression right now in Word Online preventing the code to run successfully. The specific issue is that the file.getSliceAsync method is never calling the call-back function. This only happens with the TEXT type, if you want to get the docx or pdf this should work ok. This issue will be fixed in a couple of weeks.
You have an alternative if you want to get the text of the document you can use the new APIs for Word check out this sample:
Word.run(function(context) {
var myBody = context.document.body;
context.load(myBody);
return context.sync()
.then(function(){
console.log(myBody.text);
});
});
Hope this helps!
Thanks for reporting this issue!
Juan.
Given the following code, I have managed to write a test by making use of QUnit for the first part but was unable to test finder.doRoutefinding. How can I 'mock'the function finder.doRoutefinding? (Mockjax cannot be used here since no ajax calls are involved)
`finder.doSelectDestination = function(address)
{
finder.destination = address;
finder.doRoutefinding(
finder.departure,
finder.destination,
finder.whenRouteLoaded,
finder.showRoute);
}
test('Destination Selector',
function()
{
address="London";
finder.doSelectDestination(address);
equal(pathfinder.destination,address, "Succesful Destination Selection");
}
);
There are caveats, but you could simply replace the function with your mock:
var originalDoRoutefinding = finder.doRoutefinding;
finder.doRoutefinding = function() {
// Mock code here.
};
// Test code here.
finder.doRoutefinding = originalDoRoutefinding;
If that kind of thing works for you, you might consider using a library like Sinon.JS.