Uni-app

初始化GoEasy对象

集成goeasy.js sdk

// 在main.js里初始化全局的GoEasy对象
Vue.prototype.$goEasy = new GoEasy({
    host: "hangzhou.goeasy.io", //应用所在的区域地址: 【hangzhou.goeasy.io | singapore.goeasy.io】
    appkey: "my_appkey", //替换为您的应用appkey
    onConnected: function() {
        console.log('连接成功!')
    },
    onDisconnected: function() {
        console.log('连接断开!')
    },
    onConnectFailed: function(error) {
        console.log('连接失败或错误!')
    }
});

接收消息

this.$goEasy.subscribe({
    channel: "my_channel", //替换为您自己的channel
    onMessage: function (message) {
        alert("Channel:" + message.channel + " content:" + message.content);
    }
});

发送消息

this.$goEasy.publish({
    channel: "my_channel", //替换为您自己的channel
    message: "Hello, GoEasy!" //替换为您想要发送的消息内容
});

其他相关

集成goeasy.js
HTML
微信小程序
React-Native
Vue
React
AngularJS
RequireJS

results matching ""

    No results matching ""