Commit 07e1851c0a39366ba7daa78489149a66413ea18c
1 parent
71d0ba62
互动云/3.4 聊天室JSSDK接口文档
Showing
1 changed file
with
82 additions
and
0 deletions
7. 互动云/3.4 聊天室JSSDK接口.md
0 → 100644
| 1 | +/* Title: 3.4 聊天室JSSDK接口 */ | |
| 2 | +### 聊天室JSSDK接口 | |
| 3 | +----- | |
| 4 | +#### URL: http://resweb.cnliveimg.com/sites/cnlive/im_cnlive.min.js | |
| 5 | +----- | |
| 6 | +#### 参数说明 类型(JSON) | |
| 7 | +``` | |
| 8 | +{ | |
| 9 | + roomId: '20130816144416',//聊天室房间ID(必填) | |
| 10 | + jid: addNumber(6),//聊天系统用户URI(非必填,不填采用匿名登录) | |
| 11 | + pwd: addNumber(6),//密码(非必填,不填采用匿名登录) | |
| 12 | + nickname: '哈哈',//进入聊天室的昵称 | |
| 13 | + onMessage: function(msg) { //消息接收回到函数,msg即消息体(必填) | |
| 14 | + console.log(msg); | |
| 15 | + }, | |
| 16 | + rawInputLog: function(data) { //接收日志(非必填) | |
| 17 | + console.log("RECV:"+data); | |
| 18 | + }, | |
| 19 | + rawOuputLog: function(data) { //发送日志(非必填) | |
| 20 | + console.log("SEND:"+data); | |
| 21 | + }, | |
| 22 | + onConnect:function(status){ //连接状态 回到函数(非必填) | |
| 23 | + if(status == Strophe.Status.CONNFAIL) { | |
| 24 | + console.log("connection fail......"); | |
| 25 | + } else if(status == Strophe.Status.AUTHFAIL) { | |
| 26 | + console.log("login fail......"); | |
| 27 | + } else if(status == Strophe.Status.DISCONNECTED) { | |
| 28 | + console.log("connection cutDown......"); | |
| 29 | + } else if(status == Strophe.Status.CONNECTED || status == Strophe.Status.ATTACHED) { | |
| 30 | + console.log("start chat......"); | |
| 31 | + } | |
| 32 | + } | |
| 33 | +}; | |
| 34 | + | |
| 35 | +``` | |
| 36 | +----- | |
| 37 | +#### 接口方法 | |
| 38 | +----- | |
| 39 | +##### 加入聊天室 | |
| 40 | +``` | |
| 41 | + IM.start({ | |
| 42 | + onMessage: function(msg) { | |
| 43 | + $("body").append(JSON.stringify(msg)); | |
| 44 | + }, | |
| 45 | + roomId: '20130816144416', | |
| 46 | + nickname: 'dfdddgdf1dddgfdf', | |
| 47 | + rawInputLog: function(data) { | |
| 48 | + console.log("RECV:" + data); | |
| 49 | + }, | |
| 50 | + rawOuputLog: function(data) { | |
| 51 | + console.log("SEND:" + data); | |
| 52 | + }, | |
| 53 | + onConnect: function(status) { | |
| 54 | + if(status == Strophe.Status.CONNFAIL) { | |
| 55 | + console.log("connection fail......"); | |
| 56 | + | |
| 57 | + } else if(status == Strophe.Status.AUTHFAIL) { | |
| 58 | + console.log("login fail......"); | |
| 59 | + | |
| 60 | + } else if(status == Strophe.Status.DISCONNECTED) { | |
| 61 | + console.log("connection cutDown......"); | |
| 62 | + } else if(status == Strophe.Status.CONNECTED || status == Strophe.Status.ATTACHED) { | |
| 63 | + console.log("start chat......") | |
| 64 | + } | |
| 65 | + } | |
| 66 | + }); | |
| 67 | +``` | |
| 68 | +----- | |
| 69 | +##### 禁止触发接收回调函数 | |
| 70 | +``` | |
| 71 | + IM.stopAccept(); | |
| 72 | +``` | |
| 73 | +----- | |
| 74 | +##### 打开触发接收回调函数 | |
| 75 | +``` | |
| 76 | + IM.restartAccept(); | |
| 77 | +``` | |
| 78 | +----- | |
| 79 | +##### 手动关闭连接 | |
| 80 | +``` | |
| 81 | + IM.stop(); | |
| 82 | +``` | |
| 0 | 83 | \ No newline at end of file | ... | ... |