Code Monkey home page Code Monkey logo

rtc-chatroom's Introduction

English | 简体中文

Introduction

Overview

   P2P multi-person video chat room based on WebRTC can make multi-person video calls, share screens, switch devices & start and stop, send messages, and also support disconnection and reconnection, video recording, picture editing and other functions. The code supporting the realization of RTC related functions is packaged as an SDK, and the API document of this SDK will be given later. For example, video recording, picture editing and other functions I package as related hooks or custom commands.

   The data generated by the client is transmitted directly through the WebRTC protocol without the need to worry about privacy issues. The server is only responsible for forwarding the SDP to establish the WebRTC connection. The server can be deployed on the public network and the client can be deployed on the public network.

Presentation

image.png

YoutubePreview

Start

npm

npm install

npm run start

yarn

yarn

yarn start

pnpm

pnpm install

pnpm start

RTCClient()

Syntax

new RTCClient(options)

Parameters

options

  • configuration:RTCConfiguration
  • constraints:MediaStreamConstraints
  • socketConfig:
    • host:domain or ip
    • port?:number
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

binding events

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

unbind event

shareDisplayMedia(): Promise

turn on video sharing

cancelShareDisplayMedia(): void

cancel video sharing

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

join room

leave(): void

leave the room

getDevicesInfoList(): Promise<MediaDeviceInfo[]>

get device list

getVideoDeviceInfo(): Promise

get currently used video input device information

getAudioDeviceInfo(): Promise

get information about the currently used audio input device

channelSendMesage(): void

send messages using RTCDataChannel data channel

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

switch device media track

replaceVideoTrack(deviceId: string): void

switch video media track

replaceAudioTrack(deviceId: string): void

switch audio media tracks

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

switch device status

disableAudio(): void

disable microphone

enableAudio(): void

enable microphone

disableVideo(): void

disable camera

enableVideo(): void

enable camera

getLocalStream(): Promise

get local media stream

getDisplayStream(): Promise

get shared screen media stream

close(): void

close the rtcclient instance

Events

connectorInfoListChange

triggered when the list of connected clients changes or updates

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

displayStreamChange

triggered when the shared screen media stream changes

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

localStreamChange

triggered when the local media stream changes

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

message

triggered when the RTCDataChannel data channel receives data

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

rtc-chatroom's People

Contributors

milletlovemouse avatar

Stargazers

 avatar xzyl4303 avatar rgf avatar zshuai avatar Profile avatar Mr.Alien avatar jack avatar  avatar Konmer avatar 俞小姐与茉莉清茶 avatar  avatar  avatar  avatar  avatar Vanisper avatar  avatar  avatar liuhongliang avatar  avatar ilwoo Nam avatar  avatar  avatar  avatar  avatar 一路向北 avatar  avatar  avatar

Watchers

 avatar  avatar

rtc-chatroom's Issues

关于MediaRecorder媒体录制这块,应该需要对audiotracks进行合并成一个音轨,然后再录制吧

//useVideoRecorder.ts
 if (audioTracks) {
    audioTracks.forEach(t => stream.addTrack(t))
  }

下面这种方式

// 音轨合并
      if (audioTracks) {
        const audioContext = new AudioContext()
        const dest = audioContext.createMediaStreamDestination()
        // 多个tracks 创建 多个 stream
        audioTracks.forEach(
          (tracks) => {
            const stream = new MediaStream()
            stream.addTrack(tracks)
            // 轨道合并到 dest
            audioContext.createMediaStreamSource(stream).connect(dest)
          }
        )
        // 输出合并完成的 tracks
        stream.addTrack(dest.stream.getTracks()[0])
        console.log('tracks stream', dest.stream.getTracks()[0])
      }

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.