npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jarvis_rtc_client

v1.3.22

Published

Jarvis Rtc 客户端库

Downloads

37

Readme

Jarvis Rtc client

安装依赖: https://www.npmjs.com/package/jarvis_rtc_client

安装最新版本

npm i jarvis_rtc_client -S
yarn add jarvis_rtc_client -S

快速接入

// 引入依赖包
import JarvisRtcClient from "JarvisRtcClient"

let config = {
    // 自定义扩展参数
    extra: {
        name: '<name>',
        userId: '<userId>',
        other: '....',
        other2: '....'
    },
    session: {
        // 是否接受数据传输(必须为true)
        data: true,
        // 是否启用视频
        audio: false,
        // 是否启用音频
        video: false
    }
}

// 房间唯一id
let roomId = "xxx"

// 用于保存房间内所有在线用户列表信息
let roomUserList = []

// 连接host, 必须以 "/" 结尾
let connectionHost = "http://localhost:7001/"

RtcClient = new JarvisRtcClient(connectionHost, roomId, config);
// 打开调试模式
RtcClient.debug = true
RtcClient.on("onUserStatusChanged", this, useList => roomUserList = useList)
RtcClient.on("onMessage", this, msgObject => {})
RtcClient.on("onConnectionSuccess", this, () => {
    // todo 连接成功, 回调处理...
})

RtcClient.open()

方法

实例化 JarvisRtcClient

实例化JarvisRtcClient之前, 必须在构造函数中传入配置参数, 参数示例如下:

let config = {
    // 自定义扩展参数
    extra: {
        name: '<name>',
        userId: '<userId>',
        other: '....',
        other2: '....'
    },
    session: {
        // 是否接受数据传输(必须为true)
        data: true,
        // 是否启用视频
        audio: false,
        // 是否启用音频
        video: false
    }
}
/**
* connectionHost: 通讯服务端的host, 例如: http://localhost:7001/, 注意, 必须以 "/" 结尾
* roomId: 要进入或创建 的房间id, 客户端生成并传入
* config: 连接配置参数
*/
let RtcClient = new JarvisRtcClient(<connectionHost>, <roomId>, <config>)

open

建立连接

let RtcClient = new JarvisRtcClient(host, roomId, config);

RtcClient.on("onConnectionSuccess", this, () => {
    // connection success , do something...
})

RtcClient.open()

通过监听 onConnectionSuccess 事件, 加入连接成功后的逻辑

发送文本消息

连接成功后, 可以通过send方法发送通讯报文, 报文必须为字符串.
接收并处理消息, 可监听 onMessage 事件进行处理

let msgObject = {
    type: "M01",
    participant: null,
    from: that.userId,
    name: that.name,
    // data: { rtv: '' },
    data: "消息内容",
    time: new Date().getTime()
}
RtcClient.send(JSON.stringify(msgObject))

| Param | 中文 | 类型 | 描述 | |---|---|---|---| | type | 报文类型 | String | M01: 普通消息 | | participant | 通道id | String | 通讯用户id, 统称 通道id | | from | 发送消息用户id | String | 平台用户id | | name | 发送者昵称 | String | 平台用户昵称 | | time | 发送时间 | Long | 当前发送时间 | | data | 发送消息体 | String/Object | 客户端自定义的消息体 |

disconnect

断开连接

当用户主动断开连接时, 可调用该方法与服务断断开连接

RtcClient.disconnect()

事件

事件监听通用配置:
如想监听 onUserStatusChanged 事件, 只需要添加如下代码即可:

/**
* eventName: 监听的事件名称
* self: 当前函数的作用域 this, 一搬传this即可
* callback: 事件回调函数
*/
RtcClient.on("onUserStatusChanged", that, useList => that.roomUserList = useList)

当用户状态改变时(上线或者离线), 服务端会通过该事件通知客户端. 客户端不需要维护当前房间的用户列表, 只需要监听 onUserStatusChanged事件, 并把回调的列表参数(用户列表)展现出来, 就可以了

示例demo:

// 该数组为当前房间内所有的用户列表信息
let roomUserList = []
RtcClient.on("onUserStatusChanged", that, useList => that.roomUserList = useList)

useList item示例:

[
	{
		status: "online",
		isEmcee: true,
		participant: "",
		extra: {
    		userId: "",
    		name: "",
    		mail: ""
		}
	}
]

extra为用户建立连接前, 实例化时通过 config 配置的, 配置详情请点击这里

| Name | Type | Mark | |---|---|---| | status | String | 用户状态: "offline", "online" | | isEmcee | Boolean | 是否主持人 | | participant | String | 通讯用户id, 统称 通道id | | extra | Object | | | extra.userId | String | 用户id | | extra.name | String | 用户昵称 | | extra.mail | String | 用户邮箱 |

建立连接并连接正常时, 如房间内的其他用户发送消息, 则会在该事件中响应

客户端连接成功回调事件, 当用户加入房间或者创建房间成功, 都会通过该事件回调