GoEasyIM SDK - 集成和初始化

建立连接

    import GoEasyIM from 'goeasy-im'

    var options = {
        host:"hangzhou.goeasy.io",  //应用所在的区域地址: [hangzhou.goeasy.io, 新加坡暂不支持IM,敬请期待]
        appkey:"您的common key"
    };

     //初始化
    var im  = GoEasyIM.getInstance(options);

    var user = {
        id:"001",
        data:'{"avatar":"/www/xxx.png","nickname":"Neo"}' //用于上下线提醒和查询在线用户列表时,扩展更多的属性
    }   

     //建立连接
    var promise = im.connect(user);

    promise.then(function() {
        console.log("Connection successful.");
    }).catch(function(error) {
        console.log("Failed to connect GoEasy, code:"+error.code+ ",error:"+error.content);
    });

监听网络连接成功

触发条件:

  • 与GoEasy建立连接成功
  • 断网后自动重连成功后

监听

      var onConnected = function(){
        console.log("GoEasy has been connected");
      };        

        //监听连接成功事件
      im.on(GoEasyIM.EVENT.CONNECTED,onConnected);

results matching ""

    No results matching ""