Code Monkey home page Code Monkey logo

rtc-client's Introduction

RTCClient()

Syntax

new RTCClient(options)

Parameters

options

  • configuration: RTCConfiguration
  • constraints: MediaStreamConstraints
  • socketConfig:
    • host: 域名或者ip
    • port?: 端口
import RTCClient from 'rtc-client';

const host = 'https://127.0.0.1'
const port = 3000

const rtc = new RTCClient({
  configuration: {
    iceServers: [
      {
        urls: `turn:stun.l.google.com:19302`,
        username: "webrtc",
        credential: "turnserver",
      },
    ],
  },
  constraints: {
    audio: true,
    video: true
  },
  socketConfig: {
    host,
    port,
  }
})

Instance methods

on(type: string, listener: function): void

绑定event事件

off(type: string, listener: function): void

解除绑定event事件

shareDisplayMedia(): Promise

开启视频共享

cancelShareDisplayMedia(): void

取消视频共享

join(data: { username: string, roomname: string }): void

加入房间

leave(): void

离开房间

getDevicesInfoList(): Promise<MediaDeviceInfo[]>

获取设备列表

getVideoDeviceInfo(): Promise

获取当前使用的视频输入设备信息

getAudioDeviceInfo(): Promise

获取当前使用的音频输入设备信息

channelSendMesage(): void

使用RTCDataChannel数据通道发送消息

replaceTrack(deviceId: string, kind: 'video' | 'audio'): void

切换设备媒体轨道

replaceVideoTrack(deviceId: string): void

切换视频媒体轨道

replaceAudioTrack(deviceId: string): void

切换音频媒体轨道

deviceSwitch(state: boolean, kind: 'video' | 'audio'): void

切换设备状态

disableAudio(): void

禁用麦克风

enableAudio(): void

启用麦克风

disableVideo(): void

禁用摄像头

enableVideo(): void

启用摄像头

getLocalStream(): Promise

获取本地媒体流

getDisplayStream(): Promise

获取共享屏幕媒体流

close(): void

关闭rtcclient实例

Events

connectorInfoListChange

当与连接的客户端列表发生改变或者更新时触发

rtc.on('connectorInfoListChange', (data) => {
  console.log('onConnectorInfoListChange', data);
})

displayStreamChange

当共享屏幕媒体流发生变化时触发

rtc.on('displayStreamChange', async (stream) => {
  displayStream = stream
})

localStreamChange

当本地媒体流发生变化时触发

rtc.on('localStreamChange', async (stream) => {
  localStream = stream
})

message

当RTCDataChannel数据通道接收到数据时触发

rtc.on('message', async (message: MessageItem) =>{
  message.isSelf = false
  messageList.push(message)
  console.log(message);
})

rtc-client's People

Contributors

milletlovemouse avatar

Stargazers

Vanisper avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.