urtc-im

0.3.4 • Public • Published

im-sdk-web


安装

npm install urtc-im 

or

<script src= "http://urtcsdk.cn-bj.ufileos.com/UCloudIMSdk_web.js"></script>

一、Client 类

Client 类包含以下方法:

1. 构建函数

用于创建一个 URTC Client 对象,示例代码:

import urtc_im from '../@sdk';
let {Client,setServers } = urtc_im;
new Client(AppId);

参数说明

  • AppId: string 类型,必传,可从 UCloud 控制台查看

2.joinRoom 方法

加入房间,示例代码:

client.joinRoom(RoomId, UserId, UserType, UserName, onSuccess, onFailure)

参数说明

  • RoomId: string 类型,必传,可从 UCloud 控制台查看
  • UserId: string 类型,必传,用户 ID
  • UserType: string 类型 (admin 或者 default),必传,用户角色
  • onSuccess: function 类型,选传,方法调用成功时执行的回调函数,函数说明如下
function onSuccess(data,roomInfo) {}
data 为用户信息对象和房间信息
{
    roomInfo,
    adminList,
    defaultList,
}
  • onFailure: 选传,函数类型,方法调用失败时执行的回调函数。
function(Err) {}

Err 为错误信息

3 close 方法

离开房间,关闭 IM,示例代码:

client.sendMsg(
    '测试',
    function(data){
        console.log(data)
    },
    function(err){
        console.log(err)
    }
)

4 sendMsg 方法

发送聊天消息,示例代码:

client.sendMsg(
    msg,
    onSuccess,
    onError,
)

参数说明

  • msg: string 类型,必传,聊天文字
  • onSuccess: function 类型,选传,方法调用成功时执行的回调函数,函数说明如下
function onSuccess(data) {}
  • onFailure: 选传,函数类型,方法调用失败时执行的回调函数。

5 sendGlobal 方法

推送广播,示例代码:

参数说明

参考 sendMsg

6 authCall 方法

推送广播,示例代码:

client.authCall(
    flag,
    onSuccess,
    onError,
)

参数说明

  • flag, string 类型 (open or close), 开始 or 关闭房间连麦的权限,管理员角色设置
  • onSuccess,onError 参考 sendMsg

7 getUser 方法

当前用户信息,示例代码:

const result = client.getUser()

返回值说明

  • result: User 类型,类型说明如下

User:

{
  UserId: string ,  // 为用户 ID
  UserType: string, // 用户类型
  UserName: string, // 用户名称
}

8 getAdminUsers 方法

获取房间 admin 用户,示例代码:

const result = client.getAdminUsers()

返回值说明

  • result: Array 类型

9 getDefaultUsers 方法

获取房间 default 用户,示例代码:

const result = client.getDefaultUsers()

返回值说明

  • result: Array 类型

10 getWhiteboard 方法

获取房间白板信息

const result = client.getWhiteboard();

返回值说明

  • result: Array 类型,类型说明如下
{
    uuid: string,  加入白板 id
    token: string, 加入白板 token
} 

11 on 方法

给事件绑定监听函数,示例代码:

client.on(EventType, Listener(data))

参数说明

  • EventType: string 类型, 必传,目前有 | "Msg" 收到消息 | "Ban" 禁言 | "Id" 白板 ID 推送 | "Broadcast" 广播 | "Users" 用户加入 data object 新加入用户信息数组,object.AdminUsers 管理员列表 & object.defaultUsers 普通用户列表 | "Bulletin" 公告 | "CallAuth" 连麦权限 | "CallApply" 发起上麦申请 | "CallReply" 上麦回复 | "CustomContent" 自定义消息 | "CustomContentPeers"; 点对点自定义消息 这些事件可绑定监听函数 | "SendMsgFail" 发送消息失败监听 (data) => { data.errIndex: 发送失败的序号,data.chatList 更新过的历史消息列表}
  • Listener: function 类型,事件监听函数

12 off 方法

解除绑定事件的监听函数,示例代码:

client.off(EventType, Listener)

参数说明

  • EventType: 参见 on 方法
  • Listener: 为调用 on 方法时绑定的监听函数

13 sendNotice 方法

发布公告(公告信息可在获取房间信息中获取),示例代码:

client.off(EventType, Listener)

参数说明

  • EventType: 参见 on 方法
  • Listener: 为调用 on 方法时绑定的监听函数

14 sendCustomMsg 方法

发布自定义消息(公告信息可在获取房间信息中获取),示例代码:

client.sendCustomMsg(
    type,
    content,
    onSuccess,
    onError
)

参数说明

  • type: string 类型,自定义 type 值
  • content: string 类型,自定义消息主体

15 sendCustomPeerMsg 方法

发布点对点自定义消息(公告信息可在获取房间信息中获取),示例代码:

client.sendCustomPeerMsg(
    userId,
    type,
    content,
    onSuccess,
    onError
)

参数说明

  • userId: string 类型, 接收方 id
  • type: string 类型,自定义 type 值
  • content: string 类型,自定义消息主体

16 applyCall 方法

发起连麦请求,示例代码:

client.applyCall(
    userId,
    flag,
    onSuccess,
    onError
)

参数说明

  • userId: string 类型, 接收方 id
  • flag: string 类型,apply 申请 or cancel 取消
  • onSuccess 成功回调
  • onError 失败回调

17 replyCall 方法

连麦回复请求,示例代码:

client.replyCall(
    userId,
    flag,
    onSuccess,
    onError
)

参数说明

  • userId: string 类型, 接收方 id
  • flag: string 类型,agree 同意 or refuse 拒绝

18 getRoomInfo 方法

获取房间信息,示例代码:

const result = client.getRoomInfo()

返回值说明

  • result: object 类型,类型说明如下
{
    RoomId: string,     //房间 id
    Bulletin: string,   //房间公告
    CallOperation: string,  //房间连麦权限
    applayList: string, //房间连麦列表
}

19 getHistoryChat 方法

获取房间信息,示例代码:

client.getHistoryChat(
    time,
    onSuccess,
    onError
)

参数说明

  • time: number 聊天开始时间戳(单位:s)

20 banRoom 方法

禁言功能,管理员可用:

client.banRoom(
    BanType,
    userId,
    onSuccess,
    onError
)

参数说明

  • banType type 必填 ban or unban 开启或解除禁言
  • userId: string 必填 用户 ID,填写是指定用户禁言,填写 null 则为房间禁言

21 createWhite 方法

创建白板

client.createWhite(
    onSuccess(data) => {
        let {uuid,token} = data 
    },
    onError
)

二、version 属性

version 属性用于显示当前 sdk 的版本


三、setServers 方法

可配置 URTC_IM 服务的域名

let {Client,setServers } = urtc_im;
setServers({
    api:'http://localhost:8080'
});

4、ExamClient 对象


ExamClient 类包含以下方法:

1. 构建函数

用于创建一个 ExamClient 对象,示例代码:

import  {ExamClient } from '../@sdk';
new ExamClient(AppId);

参数说明

  • AppId: string 类型,必传,可从 UCloud 控制台查看

2.add 方法

添加题目,示例代码:

ExamClient.add(
    Name: string,
    Desc: string,
    Questions: Array<Ques>,
    onSuccess,
    onFailure,
)

参数说明

  • Name: string 类型,必传 题目名称
  • Desc: string 类型,必传,题目描述
  • Questions: Ques 数组 问题类型
  • onSuccess: function 类型,选传,方法调用成功时执行的回调函数,函数说明如下
Ques: {
    Type: string;
    Title: string;
    Choices: Array<Cho>;
    RightAnswer: string;
}
Cho: {
    Sn: string;
    Desc: string;
    IsRight: boolean;
}

3 getExamList 方法

获取题目列表:

ExamClient.getExamList(
    function(data){
        //题目数组
        console.log(data)
    },
    function(err){
        console.log(err)
    }
)

4 describe 方法

发送聊天消息,示例代码:

ExamClient.getDescribe(
    ExamId,
    onSuccess,
    onError,
)

参数说明

  • ExamId: string 类型,必传 题目 ID
  • onSuccess: function 类型,选传,方法调用成功时执行的回调函数,函数说明如下
function onSuccess(data) {}
  • onFailure: 选传,函数类型,方法调用失败时执行的回调函数。

5 start 方法

开启答题,示例代码:

ExamClient.start(
    RoomId,
    ExamId,
    onSuccess, //这里返回下面用的 ExamRecordId
    onError,
)

6 submit 方法

提交答题,示例代码:

ExamClient.submit(
    RoomId: string,
    UserId: string,
    ExamId: string,
    ExamRecordId: string,
    SubmitTime: number,
    Answers: Array<Ans>,
    onSuccess?: (data?: any) => any,
    onError,
)

Ans{
    QuestionId: string; //问题 id
    UserAnswer: string; // 答案
}

7 stop 方法

提交答题,示例代码:

ExamClient.stop(
    RoomId: string,
    ExamId: string,
    ExamRecordId: string,
    onSuccess?: (data?: any) => any,
    onError,
)

7 getStat 方法

获取题目对错统计数据,示例代码:

ExamClient.getStat(
    RoomId: string,
    ExamId: string,
    ExamRecordId: string,
    onSuccess?: (data?: any) => any,
    onError,
)

8 delExam 方法

删除题目 传入 ExamId

examClient.delExam(
        ExamId,
        function(e){
            console.error("stat >>> " ,e)
        }
    )
}

参数说明

  • ExamId: string 类型,必传 题目 ID
  • onSuccess: function 类型,选传,方法调用成功时执行的回调函数,函数说明如下
function onSuccess(data) {}
  • onFailure: 选传,函数类型,方法调用失败时执行的回调函数。

Package Sidebar

Install

npm i urtc-im

Weekly Downloads

2

Version

0.3.4

License

ISC

Unpacked Size

82.9 kB

Total Files

3

Last publish

Collaborators

  • zhangjizhe