客户端发送和接收消息 > TypeScript
 

TypeScript

初始化GoEasy对象

集成goeasy.js sdk

import GoEasy = require('./goeasy-1.0.17.js');

//初始化GoEasy对象
let goEasy = new GoEasy({
  host: 'hangzhou.goeasy.io',//应用所在的区域地址: [hangzhou.goeasy.io |singapore.goeasy.io]
  appkey: 'my_appkey',//替换为您的应用appkey
  onConnected: () => {
      console.log('连接成功!')
  },
  onDisconnected: () => {
      console.log('连接断开!')
  },
  onConnectFailed: (error) => {
      console.log('连接失败或错误!')
  }
});

接收消息

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

发送消息

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

其他相关

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

results matching ""

    No results matching ""