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

hy-rtc-core

v1.38.0

Published

Hy-RTC

Downloads

249

Readme

hy-rtc-core 核心模块

负责功能

  • [x] 连接MQTT服务
  • [x] 加入房间
  • [x] 退出房间
  • [ ] 发送指令
  • [x] 初始化时设置摄像头、麦克风
  • [x] 进入房间切换摄像头
  • [ ] 获取媒体流的基础信息(网速、编解码格式...)
  • [x] 浏览器支持情况检查
  • [ ] MQTT断线、异常处理
  • [x] 暂停|恢复推流
  • [ ] 设置生产视频码率、分辨率、帧率
  • [ ] 设置生产音频采样率、码率
  • [ ] 浏览器直播录制
  • [ ] 获取房间内成员列表

调用代码示例

https://gitee.com/szhuayu/test-core-sdk.git

更新内容

【1.25.0】20230824 新增 - replaceAudioStream 用于替换音频流 新增 checkDeviceStatus 方法

【1.18.0】20230206

新增 - getRoomRecvStatus 获取媒体房间内,接收情况状态。

【1.17.0】20220524 修复 - 开启多个设备时云台控制无法使用的BUG。

【1.16.0】20220302 新增 printSendTransportStats、printRecvTransportStats、printAudioProducerStats、printVideoProducerStats、printConsumerStats

【1.15.0】20220113 新增 - consumerResumed、consumerPaused事件新增kind字段,用于告知被暂停的是什么类型。

新增 - audioProducerCreated、videoProducerCreated 事件新增track字段,返回的是可以播放的轨道,可用于本地播放使用。

新增 - join方法中可传入localPlayElement,produce创建完成后,会在该元素中进行本地播放。

新增 - replaceVideoTrack方法新增facingMode字段,传入user(前置摄像头)、environment(后置摄像头)。

【1.14.0】20220110 新增 - canPlay 新增videoPushing、audioPushing字段。

【1.13.1】20220106 新增 - consumerPaused、consumerResumed事件,新增clientId、audioPush、videoPush参数。

【1.13.0】20220106 新增 - videoConsumerPaused、videoConsumerResume方法,用于暂停、恢复视频画面。

新增 - consumerPaused、consumerResumed事件。

【1.12.0】20211220 新增 - join方法中新增appData自定义字段。

【1.11.0】20211217 优化 - produce中开启zeroRtpOnPause参数,在暂停时不发送rtp数据。

【1.10.0】20211214 新增 - audioProducerCreated、videoProducerCreated 音频视频producer创建时的事件。

【1.9.1】20211208 优化 - 注释rtc对象中的 consumerPaused consumerResume 方法 修复 - 暴露consumerPaused consumerResume 方法

【1.9.0】20211208 优化 - 注释rtc对象中的 consumerPaused consumerResume 方法 修复 - 没有打开麦克风的BUG

【1.8.1】20211110

  • 新增 newClients事件

【1.7.0】20211109

  • 优化 GB28181拉起画面时,canPlay的逻辑处理。
  • 新增 disconnect方法,主动断开MQ连接

【1.6.0】20211102

  • 修复 多个直播时exitRoom方法异常

【1.5.3】20211013

  • 修复 修改云台控制指令调用方式

【1.5.2】20211012

  • 优化 修改云台控制指令 control

【1.5.1】20211012

  • 新增云台控制 notificationDeviceControl

【1.3.1】20210917

  • 修复 - audioProducerBroken 事件触发流程

【1.3.0】20210917

  • 新增 - audioConsumerPaused、audioConsumerResume 方法
  • 新增 - audioProducerBroken、audioProducerPaused、audioProducerResumed 事件通知

【1.2.2】20210915

  • 修复 - 修复 exitRoom方法

【1.2.0】20210831

  • 修复 - 新加入设备时,上一个流会断开的BUG。
  • 新增 - canPlay事件新增roomId、appData字段。
  • 新增 - newClient事件新增roomId、appData字段。
  • 新增 - clientClosed事件新增roomId、appData字段。
  • 新增 - roomClosed事件
  • 新增 - 新增更换音频方法replaceAudioTrack
  • 修改 - 退出房间调用文档

接入流程

// npm 依赖包安装
yarn add hy-rtc-core --save

// 在需要使用的页面引入
import { HyRtcCore } from 'hy-rtc-core'

// 初始化
this.rtc = new HyRtcCore({
    useSSL: true,
    host: 'hy-rtc-mqtt-server.huayu-soft.com',
    port: 443,
    path: '/ws',
    clientId: this.clientId,
    username: this.clientId,
    password: '123456',
    appId: '8d48d600a930f2c3acea7b5bc697a7a9',
    appKey: '368480924a6c78e2e8681551a7cf4c21'
  })

// 事件监听
this.rtc.eventEmit('事件名称', () => {})

// 发起连接
this.rtc.connect()

// 主动断开连接
this.rtc.disconnect()

SDK 操作

/**
* 加入房间
* 返回Room对象
* */
  this.room = await this.rtc.join({
    roomId: 'r001',
    videoPush: true,
    audioPush: true,
    tag: 'a',
    consumeTags: ['a']
  })
  
/**
 * 退出房间
 * */
exitRoom () {
  this.room.exitRoom()
}

/**
 * notificationDeviceControl
 * @param params
 *
 左上:PTZ_LEFT_UP
 上:PTZ_UP
 右上:PTZ_RIGHT_UP
 左:PTZ_LEFT
 右:PTZ_RIGHT
 左下:PTZ_LEFT_DOWN
 下:PTZ_DOWN
 右下:PTZ_RIGHT_DOWN
 放大:PTZ_ZOOM_IN
 缩小:PTZ_ZOOM_OUT
 停止PTZ指令:PTZ_STOP(停止操作无需speed参数)
 聚焦-近:FI_FOCUS_NEAR
 聚焦-远:FI_FOCUS_FAR
 光圈-缩小:FI_IRIS_ZOOM_OUT
 光圈-放大:FI_IRIS_ZOOM_IN
 停止FI指令:FI_STOP(停止操作无需speed参数)
 * speed
 *  速度,整型;取值范围:1~8
 */
notificationDeviceControl (params) {
    this.room.notificationDeviceControl({
        command: 'PTZ_LEFT',
        clientId: '123456789',
        speed: 4
    })
}
  
/**
 * 获取运行环境信息
 */
async checkDeviceSupport () {
  const envInfo = await this.rtc.checkDeviceSupport()
  console.log('envInfo', envInfo)
}

/**
 * 获取本机媒体设备列表
 * kind类型: 视频输入 videoinput 音频输入 audioinput
 */
async getMediaDevices () {
  console.log(await this.rtc.getMediaDevices('videoinput'))
}

/*
* 设置生产时的视频输入源(可选)
* 使用getMediaDevices方法获取本机媒体设备后传入
* 此方法在joinRoom前调用
**/
this.rtc.setVideoInput(inputVideo)

/*
* 设置生产时的视频输入源(可选)
* 使用getMediaDevices方法获取本机媒体设备后传入
* 此方法在joinRoom前调用
**/
this.rtc.setAudioInput(inputAudio)

/*
* 在生产时更换视频输入源(可选)
* 使用getMediaDevices方法获取本机媒体设备后传入
* 此方法在joinRoom后调用
**/
this.rtc.replaceVideoTrack(inputVideo, facingMode)

/**
 * 在生产时更换音频输入源(可选)
 * 使用getMediaDevices方法获取本机媒体设备后传入
 * 此方法在joinRoom后调用
 */
this.rtc.replaceAudioTrack(inputAudio)

/**
 * 获取音频话语权
 * 半双工模式时,恢复麦克风时的操作
 */
this.rtc.audioConsumerResume().then(() => {
  console.log('获取话语权成功')
}).catch(err => {
  console.log('err', err)
})

/**
 * 释放音频话语权
 * 半双工模式时,关闭麦克风时的操作
 */
this.rtc.audioConsumerPaused().then(() => {
  console.log('释放话语权成功')
}).catch(err => {
  console.log('err', err)
})

/**
 * 获取视频话语权
 * 半双工模式时,恢复摄像头时的操作
 */
this.rtc.videoConsumerResume().then(() => {
  console.log('获取话语权成功')
}).catch(err => {
  console.log('err', err)
})

/**
 * 释放视频话语权
 * 半双工模式时,关闭摄像头时的操作
 */
this.rtc.videoConsumerPaused().then(() => {
  console.log('释放话语权成功')
}).catch(err => {
  console.log('err', err)
})

/**
* 获取当前房间内的参数信息
* 返回当前房间内所有的接收情况
* 接口返回设备列表数组,里面有带appData对象,可自由根据业务情况进行展示
* 显示的参数有很多,根据实际情况作为展示。
*/

this.room.getRoomRecvStatus().then((res) => {
    
})

事件

【连接成功】open

this.rtc.mediaClient('open', () => {})

canPlay事件处理逻辑

/**
 * 设备可进行播放时触发,sdk内部会判断是否音视频流都准备完毕,准备完毕时触发该事件
 * 需要开发者自行放入元素中进行播放
 * @param remoteClient 远端设备对象
 * id 对方ID
 * consumers 消费对象
 * videoPush 具有视频流
 * audioPush 具有音频流
 * roomId 房间ID
 * consumer 最新的一条流,只有GB28181类型时会返回
 */
this.rtc.eventEmit.on('canPlay', (remoteClient) => {
    // 设备可进行播放时触发,sdk内部会判断是否音视频流都准备完毕,准备完毕时触发该事件
    const { id, consumers, roomId } = remoteClient
    const stream = new MediaStream()
    const videoEle = document.querySelector(`#monitor-video-${id}`)
    videoEle.srcObject = stream
    consumers.forEach(consumer => {
      stream.addTrack(consumer.track)
    })
    videoEle.play()
})

clientClosed事件处理逻辑

/**
* 设备退出房间时的事件
* @param clientId 设备ID
* 收到该事件时,需将原有的播放器移除
*/
this.rtc.eventEmit.on('clientClosed', ({ clientId, roomId }) => {
  const videoEle = document.querySelector(`#monitor-video-${clientId}`)
  videoEle.remove()
})

newClient 事件处理逻辑

/**
* 有新用户加入时的事件
* @param clientId 设备ID
* 收到该事件时,需将先创建播放器
*/
this.rtc.eventEmit.on('newClient', ({ clientId, roomId }) => {
  // 创建video标签
  const container = document.getElementById('remote-video-container')
  const videoElement = document.createElement('video')
  videoElement.setAttribute('controls', 'true')
  videoElement.id = `monitor-video-${clientId}`
  videoElement.className = 'play-element'
  container.append(videoElement)
})

newClients 事件处理逻辑

/*
* 返回已存在在房间中的设备,SDK内已将数组遍历后,使用newClient事件进行返回
*/
this.rtc.eventEmit.on('newClients', clients => {})

roomClosed 事件处理逻辑

/**
* 有房间关闭事件
* @param roomId 房间ID
*/
this.rtc.eventEmit.on('newClient', ({ roomId }) => {
  console.log('roomId', roomId)
})

audioProducerBroke 事件处理逻辑

/**
* 音频话语权被抢断
* @param id 音频ProduceId
*/
this.rtc.eventEmit.on('audioProducerBroken', () => {
  console.log('audioProducerBroken')
})

audioProducerResumed 事件处理逻辑

/**
* 获取音频话语权事件
* @param id 音频ProduceId
*/
this.rtc.eventEmit.on('audioProducerResumed', () => {
  console.log('audioProducerResumed')
})

audioProducerPaused 事件处理逻辑

/**
* 暂停音频话语权事件
* @param id 音频ProduceId
*/
this.rtc.eventEmit.on('audioProducerPaused', () => {
  console.log('audioProducerPaused')
})

consumerPaused 事件处理逻辑

/**
* 暂停话语权事件
kind 被暂停的类型
*/
this.rtc.eventEmit.on('consumerPaused', ({clientId,audioPush,videoPush,kind}) => {
  console.log('consumerPaused')
})

consumerResumed 事件处理逻辑

/**
* 暂停话语权事件
kind 被暂停的类型
*/
this.rtc.eventEmit.on('consumerResumed', ({clientId,audioPush,videoPush,kind}) => {
  console.log('consumerResumed')
})

audioProducerCreated 事件处理逻辑

/**
* 音频生产者创建完成
*/
this.rtc.eventEmit.on('audioProducerCreated', ({roomId,track}) => {
  console.log('audioProducerCreated')
})

videoProducerCreated 事件处理逻辑

/**
 * 视频生产者创建完成
 */
this.rtc.eventEmit.on('videoProducerCreated', ({roomId,track}) => {
  console.log('videoProducerCreated')
})