第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會有你想問的

Nativescript,如何在Javascript中使用這個(gè)java eventListener?

Nativescript,如何在Javascript中使用這個(gè)java eventListener?

滄海一幻覺 2023-09-20 14:30:39
我正在使用 NativeScript 并已實(shí)現(xiàn) Pusher-Java 庫作為依賴項(xiàng),我可以成功連接并訂閱我的 Pusher 頻道,但我無法向我的頻道添加 SubscriptionEventListener,這是我的代碼,它使用 Nativescript 中的 java 庫連接到推送器: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));    }};以下是將 SubscriptionEventListener 綁定到通道的 Java 代碼:channel.bind("my-event", new SubscriptionEventListener() {    @Override    public void onEvent(PusherEvent event) {        System.out.println("Received event with data: " + event.toString());    }});現(xiàn)在我如何使用 Javascript 綁定它???我已經(jīng)嘗試了所有我能想到的方法,但仍然無法使用 Javascript 將 SubscriptionEventListener 綁定到通道,謝謝更新我正在使用這種方法,預(yù)計(jì)會起作用,@Manoj 也在這里回答了:channel.bind(event_name,    new SubscriptionEventListener({        onEvent: function(event) {            console.log(event.toString());        }    }));但它不起作用,我收到此錯(cuò)誤:java.lang.RuntimeException: Unable to start activity ComponentInfo{org.nativescript.plugintestproject/com.tns.NativeScriptActivity}: com.tns.NativeScriptException: Calling js method onCreate failedSystem.err: Error: Building UI from XML. @app-root.xml:1:1System.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)
查看完整描述

3 回答

?
桃花長相依

TA貢獻(xiàn)1860條經(jīng)驗(yàn) 獲得超8個(gè)贊

有幾件事:

  1. 為什么不直接使用 nativescript-pusher 插件呢?它已經(jīng)存在了...

  2. 第二,如果你不想使用它;為什么不借用代碼,因?yàn)樗窃?Apache 2.0 許可證下的。


不過,要具體回答你的問題:

const sel = new com.pusher.client.channel.SubscriptionEventListener( {

            onEvent: function(channel, event, data) {

                 console.log("Channel:", channel, "Event", event, "received event with data: " + data.toString());

            }

          } );


首先,在創(chuàng)建事件時(shí),您確實(shí)應(yīng)該使用 FULL 命名空間(這使得創(chuàng)建的內(nèi)容一目了然)。

其次,你的原型onEvent是錯(cuò)誤的。根據(jù)文檔,它是Channel, Event, Data傳遞給它的參數(shù)。


查看完整回答
反對 回復(fù) 2023-09-20
?
萬千封印

TA貢獻(xiàn)1891條經(jīng)驗(yàn) 獲得超3個(gè)贊

SubscriptionEventListener是一個(gè)接口,您應(yīng)該實(shí)現(xiàn)方法并將實(shí)例傳遞給綁定方法,如文檔中所示。


channel.bind("my-event",?

? ?new SubscriptionEventListener({

? ? onEvent: function(event) {

? ? ? ? console.log("Received event with data: " + event.toString());

? ? }

? ?})

);


查看完整回答
反對 回復(fù) 2023-09-20
?
慕村9548890

TA貢獻(xiàn)1884條經(jīng)驗(yàn) 獲得超4個(gè)贊

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;

        PusherEvent = com.pusher.client.channel.PusherEvent;

        SubscriptionEventListener = com.pusher.client.channel.SubscriptionEventListener;

        ChannelEventListener = com.pusher.client.channel.ChannelEventListener;


        const options = new PusherOptions().setCluster("eu");

        const pusher = new Pusher(app_key, options);


        pusher.connect();


        const channel = new Channel(pusher.subscribe(channel_name));

        const connectedChannel = pusher.getChannel(channel_name);


        let sel = new SubscriptionEventListener({

            onEvent: function(event) {

                console.log(event);

            }

        });


        connectedChannel.bind(event_name, sel);

    }

};


查看完整回答
反對 回復(fù) 2023-09-20
  • 3 回答
  • 0 關(guān)注
  • 140 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號