微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

我如何在移动设备中集成 pubnub

如何解决我如何在移动设备中集成 pubnub

我正在尝试整合 pubnub(用 pubnub 替换 socket.io)。在下面我展示了代码。它在 pc 上工作正常。但在移动设备中它不起作用。我也没有收到错误。任何身体可以告诉我做错了什么。 到目前为止,我一直试图用我的 pubnub 连接替换套接

import PubNub from 'pubnub';
import { PubNubProvider,usePubNub } from 'pubnub-react';
 
const pubnub = new PubNub({
   publishKey: 'xxxxxxxxxxxx',subscribeKey: 'xxxxxxxxxxx'
});
//leave Table when close window
const closingCode = () => {
    sendMsg("leaveTable");
    return null;
};

class App extends Component {
    constructor(props) {
        super(props);
        this.state = {
            isOpen: false
        };
        this.receiveMsg = []
    }
    
        window.onbeforeunload = closingCode;
        // Read res from service via Socket IO
        // socket.on("message",receiveMsg);
        socket.on("message",text => {
            let params = text.split("|"); //.map(p => Base64.Decode(p)); // we are not using b64 Now
            let message = params.shift(); // message,eg. playerSitOut,clearTable

            this.receiveMsg.push(message);
            this.props.updateMessage({ message,params });
        });
         
      
     
   pubnub.addListener({ message: function (m) {
   const channelName = m.channel; // Channel on which the message was published
   const channelGroup = m.subscription; // Channel group or wildcard subscription match (if exists)
   const pubTT = m.timetoken; // Publish timetoken
   const msg = m.message; // Message payload
    const publisher = m.publisher; // Message publisher/  } });
        //pubnub.subscribe();
      
    }

   

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。