5.0.10 • Published 5 years ago
the-rtc-client v5.0.10
the-rtc-client
Client for the-rtc
Installation
$ npm install the-rtc-client --save
Usage
Setup Server
'use strict'
const theRTC = require('../../the-rtc')
// const theRTC = require('the-rtc')
async function tryExample() {
const rtc = theRTC({
stun: {
url: 'stun:stun.l.google.com:19302'
},
turn: {
url: 'turn:your.turn.servers.here',
secret: 'xxxxxxxxxxxxxxxx',
expiry: 86400
},
topology: 'sfu',
})
const port = 3000
await rtc.listen(port)
console.log(`Example RTC Server listening: http://localhost:${port}`)
}
tryExample().catch((err) => console.error(err))
Create Clients
'use strict'
const { TheRTCClient } = require('../lib')
document.addEventListener('DOMContentLoaded', async () => {
const url = 'http://localhost:3000'
const video01 = document.getElementById('video01')
const video02 = document.getElementById('video02')
const video03 = document.getElementById('video03')
const video04 = document.getElementById('video04')
const video01Title = document.getElementById('video01-title')
const video02Title = document.getElementById('video02-title')
const video03Title = document.getElementById('video03-title')
const video04Title = document.getElementById('video04-title')
const c1 = new TheRTCClient({
info: { userName: 'This is client01' },
mediaConstrains: { audio: false, video: true },
onLocal: ({ stream, info, rid }) => {
video01Title.innerText = info.userName
setVideoStream(video01, stream)
},
onRemote: ({ stream, info, rid }) => {
video02Title.innerText = info.userName
setVideoStream(video02, stream)
}
})
const c2 = new TheRTCClient({
info: { userName: 'This is client02' },
mediaConstrains: { audio: false, video: true },
onLocal: ({ stream, info, rid }) => {
video03Title.innerText = info.userName
setVideoStream(video03, stream)
},
onRemote: ({ stream, info, rid, peer }) => {
video04Title.innerText = info.userName
setVideoStream(video04, stream)
}
})
await c1.connect(url)
await c2.connect(url)
const roomName = 'room01'
const setVideoStream = (video, stream) => {
if (!stream) {
console.warn(`No stream`)
return
}
const knownId = video.srcObject && video.srcObject.id
if (knownId === stream.id) {
return
}
video.srcObject = stream
}
await c1.join(roomName)
await c2.join(roomName)
{
const unsubscribe = c2.subscribe('greeting', ({ from, payload }) => {
console.log('c2 received greeting', from, payload)
unsubscribe()
})
}
{
const unsubscribe = c1.subscribe('greeting', ({ from, payload }) => {
console.log('c1 received greeting', from, payload)
unsubscribe()
})
}
setTimeout(() => {
void c1.publish('greeting', { msg: 'hi, i am c1' })
void c2.publish('greeting', { msg: 'hi, i am c2' })
}, 500)
})
API Guide
License
This software is released under the MIT License.
Links
5.0.10
5 years ago
5.0.9
5 years ago
5.0.8
5 years ago
5.0.7
5 years ago
5.0.6
5 years ago
5.0.5
5 years ago
5.0.4
5 years ago
5.0.3
5 years ago
5.0.2
5 years ago
5.0.1
5 years ago
4.0.11
5 years ago
4.0.10
5 years ago
4.0.9
5 years ago
4.0.8
5 years ago
4.0.7
5 years ago
4.0.6
6 years ago
4.0.5
6 years ago
4.0.4
6 years ago
4.0.3
6 years ago
4.0.2
6 years ago
4.0.1
6 years ago
4.0.0
6 years ago
3.0.1
6 years ago
3.0.0
6 years ago
1.0.17
6 years ago
1.0.16
6 years ago
1.0.15
6 years ago
1.0.14
6 years ago
1.0.13
6 years ago
1.0.12
6 years ago
1.0.11
6 years ago
1.0.10
6 years ago
1.0.9
6 years ago
1.0.8
6 years ago
1.0.7
6 years ago
1.0.6
6 years ago
1.0.4
6 years ago
1.0.1
6 years ago