Code Monkey home page Code Monkey logo

demo-web-sdk's Introduction

demo-web-sdk

Demostration of Rong Web SDK.

融云 web SDK 如何使用

文档参考

初始化web sdk ,此项必须设置

使用融云 web SDK 发消息之前必须利用申请的appkey进行初始化,只有在初始化之后才能使用RongIMClient.getInstance()方法得到实例.如只想使用 web SDK 请参考 SDK_Demo.html

RongIMClient.init("appkey");

设置链接状态监听器,此项必须设置

RongIMClient.setConnectionStatusListener({  
     onChanged: function (status) {  
         window.console.log(status.getValue(), status.getMessage(), new Date()) 
     }  
}); 

链接融云服务器,此项必须设置

此方法为异步方法,请确定链接成功之后再执行其他操作。成功返回登录人员id失败则返回失败枚举对象

RongIMClient.connect("token", {
     onSuccess: function (userid) {
         window.console.log("connected,userid=" + userid)
     },
     onError: function (x) {
         window.console.log(x.getMessage())
     }
});

设置消息监听器,此项必须设置

所有接收的消息都通过此监听器进行处理,可以通过message.getMessageType()和RongIMClient.MessageType枚举对象来判断消息类型

RongIMClient.getInstance().setOnReceiveMessageListener({
     onReceived: function (message) {
         //message为RongIMMessage子类实例
         console.log(message.getContent());
     }
});

得到RongIMClient实例对象

var ins = RongIMClient.getInstance();

设置私人会话类型

var contype = RongIMClient.ConversationType.PRIVATE;

例如注册某个元素点击事件(举例)

element.onclick = function () {
//调用实例的发送消息方法
     ins.sendMessage(contype, "targetId", RongIMClient.TextMessage.obtain("发送消息内容"), null, {
           onSuccess: function () {
                //发送成功逻辑处理
           },
           onError: function (data) {
                //发送失败逻辑处理
                console.log(data.getValue(),data.getMessage())
           }
       });
};

web sdk是全异步的,所以发送消息之前确保链接成功

demo-web-sdk's People

Contributors

arielyang avatar yataozhang avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.