I'm using NativeScript and have implemented Pusher-Java Library as a dependency, I can successfully connect and subscribe to my Pusher channel, but I have truble adding a SubscriptionEventListener to my channel,
Here is my code which connects to pusher using java library in Nativescript:
module.exports = {
connect:function(app_key, channel_name, event_name) {
PusherOptions = com.pusher.client.PusherOptions;
Pusher = com.pusher.client.Pusher;
Channel = com.pusher.client.channel.Channel;
SubscriptionEventListener = com.pusher.client.channel.SubscriptionEventListener;
PusherEvent = com.pusher.client.channel.PusherEvent;
var options = new PusherOptions().setCluster("eu");
var pusher = new Pusher(app_key, options);
pusher.connect();
var channel = new Channel(pusher.subscribe(channel_name));
}
};
And here is the Java code for binding SubscriptionEventListener to the channel:
channel.bind("my-event", new SubscriptionEventListener() {
@Override
public void onEvent(PusherEvent event) {
System.out.println("Received event with data: " + event.toString());
}
});
now how can I bind this using Javascript!? I've tried anything I could come up with, but still couldn't bind the SubscriptionEventListener to channel with Javascript,
thank you
UPDATE
I'm using this method, which is expected to work and also @Manoj has answered down here:
channel.bind(event_name,
new SubscriptionEventListener({
onEvent: function(event) {
console.log(event.toString());
}
})
);
But it doesn't work and I get this error:
java.lang.RuntimeException: Unable to start activity ComponentInfo{org.nativescript.plugintestproject/com.tns.NativeScriptActivity}: com.tns.NativeScriptException: Calling js method onCreate failed
System.err: Error: Building UI from XML. @app-root.xml:1:1
System.err: > java.lang.AbstractMethodError: abstract method "void com.pusher.client.channel.Channel.bind(java.lang.String, com.pusher.client.channel.SubscriptionEventListener)"
System.err: com.tns.Runtime.callJSMethodNative(Native Method)