敬告:此 demo 演示为开放测试页面,仅用于开发者快速测试体验应用功能,请严格遵守开发者协议,威尼斯人888-5845vip威尼斯电子游戏。
♦ js-sdk 引用方式:
♦ 普通网页 script 方式加载:下载最新版 ,请在页面上调用 jsbridge 接口之前引用 jsbridge-mini.js 库;
♦ js module 方式引用:npm install ym-jsbridge
♦ 融云 - / sdk;
♦ 接入应用;
♦ js api 接入步骤:
♦ 1. 执行 jsbridge.rc.init 初始化融云系统;
♦ 2. 执行 jsbridge.rc.setuserinfolistener 设置用户资料监听器;
♦ 3. 执行 jsbridge.rc.connect 连接服务器;
♦ 4. 调用业务接口;
基础
• 调用融云其他 api 接口之前需先执行初始化,只需执行一次。
• 参考官方说明 https://www.rongcloud.cn/docs/android.html#integration_init
jsbridge.rc.init({
//在融云上创建应用获得的 app key
//注意:开发环境 与 生产环境 的 app key 是不同的
appkey : "8luwapkv8bqil",
//是否启用离线推送功能
//需配置推送功能:融云后台 - im 服务 - 应用标识 - 设置推送
enablepush: true
}, function(succ) {
alert(succ ? "成功" : "失败");
});
jsbridge.rc.setuserinfo({
//用户id
userid : "yimenapp2",
//昵称
username : "userid 的昵称",
//头像
useravatar: "http://pics.sc.chinaz.com/files/pic/icons128/5104/3.png"
});
alert("已设置");
• 当 app 要显示用户信息(昵称,头像)的时候会调用此监听器,参数 userid 指示要显示哪个用户的信息;
• 请在回调函数内调用 jsbridge.rc.setuserinfo 设置用户信息;
jsbridge.rc.setuserinfolistener(function(userid) {
//userid 用户id
console.log(userid);
//从服务器获取用户信息,调用 setuserinfo 设置昵称和头像
jsbridge.rc.setuserinfo({
userid : userid,
username : "userid 的昵称",
useravatar: "http://pics.sc.chinaz.com/files/pic/icons128/5104/3.png" //userid 的头像
});
});
alert("已设置");
• 成功连接到融云服务器后才能正常调用其他业务接口。
• 参考官方说明 https://www.rongcloud.cn/docs/android.html#integration_connect
• 服务器端接口 https://www.rongcloud.cn/docs/server.html#user_get_token
//用执行服务器端接口 user.register(user) 拿到的 token 连接服务器
// https://www.rongcloud.cn/docs/server_sdk_api/user/user.html#register
jsbridge.rc.connect({
//yimenapp
//调用融云服务器端接口获取到的用户 token
//参考 https://www.rongcloud.cn/docs/server.html#user_get_token
token : "dloijyj0kc5aba68y0chjtf0gmkrswihfwmcwqh7svaltzgqdnpv9oz0fkoxqaff4jpvy7se8tmyvlnbmtl3ma==",
//用户昵称
username : "闲张三",
//用户头像
useravatar: "http://pics.sc.chinaz.com/files/pic/icons128/5104/3.png",
//可选,字符串类型,视频解析度与帧率,默认 vd_480x640_15f
//仅用于视频会话
callvideoprofile: "vd_480x640_15f"
}, function(succ, message) {
alert(succ ? "成功" : "失败:\n" message);
});
/**
callvideoprofile 属性支持以下字符串:
字符串 支持平台
vd_144x176_15f android & ios
vd_144x176_24f android
vd_144x176_30f android
vd_144x256_15f android
vd_144x256_24f android
vd_144x256_30f android
vd_240x240_15f android
vd_240x240_24f android
vd_240x240_30f android
vd_240x320_15f android & ios
vd_240x320_24f android
vd_240x320_30f android
vd_360x480_15f android & ios
vd_360x480_24f android
vd_360x480_30f android
vd_360x640_15f android & ios
vd_360x640_24f android
vd_360x640_30f android
vd_368x640_15f android
vd_368x640_24f android
vd_368x640_30f android
vd_480x640_15f android & ios (默认)
vd_480x640_24f android
vd_480x640_30f android
vd_480x720_15f android & ios
vd_480x720_24f android
vd_480x720_30f android
vd_480x854_15f android
vd_480x854_24f android
vd_480x854_30f android
vd_720x1280_15f android & ios
vd_720x1280_24f android
vd_720x1280_30f android
vd_1080x1920_15f android
vd_1080x1920_24f android
vd_1080x1920_30f android
**/
• 成功连接到融云服务器后才能正常调用其他业务接口。
• 参考官方说明 https://www.rongcloud.cn/docs/android.html#integration_connect
//用执行服务器端接口 user.register(user) 拿到的 token 连接服务器
// https://www.rongcloud.cn/docs/server_sdk_api/user/user.html#register
jsbridge.rc.connect({
//yimenapp2
token: "w32pgrighahmh26vmkrxq42wpo2 ax21vvoa1b6apxlc5/bkuadzumetotpsnvxz2lbdfvokzahphvb7rvtxzkzd9zqglua5",
//用户昵称
username : "忙李四",
//用户头像
useravatar: "http://pics.sc.chinaz.com/files/pic/icons128/5105/0.png"
}, function(succ, message) {
alert(succ ? "成功" : "失败:\n" message);
});
• 成功连接到融云服务器后才能正常调用其他业务接口。
• 参考官方说明 https://www.rongcloud.cn/docs/android.html#integration_connect
//用执行服务器端接口 user.register(user) 拿到的 token 连接服务器
// https://www.rongcloud.cn/docs/server_sdk_api/user/user.html#register
jsbridge.rc.connect({
//yimen_user3
token: "xhmn0ttzzkgjswbr2rxgro2wpo2 ax21vvoa1b6apxlc5/bkuadzulefdnkh25p0ivnfgwkkf89za nufdtouaolvx8l gtp",
//用户昵称
username : "枯叶碟",
//用户头像
useravatar: "http://pics.sc.chinaz.com/files/pic/icons128/7422/m13.png"
}, function(succ, message) {
alert(succ ? "成功" : "失败:\n" message);
});
• 参考官方说明 https://www.rongcloud.cn/docs/android.html#integration_disconnect
jsbridge.rc.disconnect(function(succ) {
alert(succ ? "成功" : "失败");
});
• 参考官方说明 https://www.rongcloud.cn/docs/android.html#integration_disconnect
jsbridge.rc.logout(function(succ) {
alert(succ ? "成功" : "失败");
});
im 即时通讯
• 开启会话
• 参考官方说明 https://www.rongcloud.cn/docs/android.html#integration_conversation_list_config
//开启会话
jsbridge.rcim.startconversation({
//必须,数字类型,会话类型
conversationtype: 1,
//必须,字符串类型,会话对象,根据不同的 conversationtype,可能是用户id、群组id 或 聊天室id
targetid: "yimenapp",
//可选,字符串类型,会话标题
title : "聊起来1~~"
}, function(succ) {
if (!succ) alert("失败");
});
/**
会话类型说明(conversationtype):
1 : private
2 : discussion
3 : group
4 : chatroom
5 : customer_service
6 : system
7 : app_public_service
8 : public_service
9 : push_service
11: encrypted
12: rtc_room
**/
• 开启会话
• 参考官方说明 https://www.rongcloud.cn/docs/android.html#integration_conversation_list_config
//开启会话
jsbridge.rcim.startconversation({
//必须,数字类型,会话类型
conversationtype: 1,
//必须,字符串类型,会话对象,根据不同的 conversationtype,可能是用户id、群组id 或 聊天室id
targetid: "yimenapp2",
//可选,字符串类型,会话标题
title : "聊起来2~~"
}, function(succ) {
if (!succ) alert("失败");
});
• 打开全部类型的会话列表
• 参考官方说明 https://www.rongcloud.cn/docs/android.html#integration_conversation_list_config
//打开全部类型的会话列表
jsbridge.rcim.startconversationlist({
//可选,数字数组,指定需要展开显示的会话类型(会话列表默认为分组聚合(折叠)显示,这里指定不折叠(展开)显示的会话类型,参见 startconversation 方法
flat: [2, 3, 5]
}, function(succ) {
if (!succ) alert("失败");
});
• 打开某种类型会话列表
• 参考官方说明 https://www.rongcloud.cn/docs/android.html#integration_conversation_list_config
//打开单个类型的会话列表
jsbridge.rcim.startsubconversationlist({
//必须,数字类型,打开单个类型的会话列表,会话类型 startconversation 方法
conversationtype: 1
}, function(succ) {
if (!succ) alert("失败");
});
• 获取未读消息数量
jsbridge.rcim.unreadmessagecount(function(count) {
alert(count " 条未读");
});
音视频通话
• 发起单人通话
• 参考官方说明 https://www.rongcloud.cn/docs/ios_callkit.html#start_call
jsbridge.rccall.startsinglecall({
//通话对方用户 id
targetid: "yimenapp",
//true - 视频通话,false - 音频通话
video : true
}, function(succ) {
if (!succ) alert("失败");
});
• 发起单人通话
• 参考官方说明 https://www.rongcloud.cn/docs/ios_callkit.html#start_call
jsbridge.rccall.startsinglecall({
//通话对方用户 id
targetid: "yimenapp2",
//true - 视频通话,false - 音频通话
video : true
}, function(succ) {
if (!succ) alert("失败");
});
• 发起多人通话
• 参考官方说明 https://www.rongcloud.cn/docs/ios_callkit.html#start_call
jsbridge.rccall.startmulticall({
//通话对方用户 id
targetid: "yimenapp2",
//true - 视频通话,false - 音频通话
video : true,
//会话类型
conversationtype: 1,
//参与者用户 id 列表
userids : ["yimenapp2", "yimen_user3"]
}, function(succ) {
if (!succ) alert("失败");
});
/**
会话类型(conversationtype):
1 : private 私聊
2 : discussion 讨论组
3 : group 群组
4 : chatroom 聊天室
5 : customer_service
6 : system
7 : app_public_service
8 : public_service
9 : push_service
11: encrypted
12: rtc_room
**/