@webtrit/webtrit-signaling
v0.5.3
Published
WebTrit Signaling Client on TypeScript
Downloads
38
Readme
WebTrit Signaling Client
WebTrit Signaling Client is basic implementation of WebTrit Signaling Protocol on TypeScript.
Installing
Using npm:
npm install @webtrit/webtrit-signaling
Using jsDelivr CDN:
<script src="https://cdn.jsdelivr.net/npm/@webtrit/webtrit-signaling@latest/dist/webtrit-signaling.js"></script>
Using unpkg CDN:
<script src="https://unpkg.com/@webtrit/webtrit-signaling@latest/dist/webtrit-signaling.js"></script>
Example
import WebtritSignaling from '@webtrit/webtrit-signaling'
// Websocket URL of WebTrit Core (the URL must use the scheme `ws` or `wss`)
const url = '<WebTrit Core url>'
// Token to identify user's session on WebTrit Core
const token = '<token>'
const webtritSignalingClient = new WebtritSignaling({
eventCallback: (signalingEvent) => {
console.log('>> eventCallback: ${signalingEvent}')
},
errorCallback: (error) => {
console.log('>> errorCallback: ${error}')
},
disconnectedCallback: (reason, code) => {
console.log('>> disconnectedCallback: with code: ${code} and reason: ${reason}')
},
connectedCallback: (event) => {
console.log('>> connectedCallback: ${event}')
}
})
webtritSignalingClient.connect({
url,
token,
})
await new Promise(r => setTimeout(r, 2000))
console.log('Wait StateEvent')
await new Promise(r => setTimeout(r, 5000))
console.log('Disconnecting')
webtritSignalingClient.disconnect();
await new Promise(r => setTimeout(r, 3000))
Send outgoing call request
await webtritSignalingClient.execute('outgoing_call', {
line: 0,
call_id: 'qwertyuiop',
number: '1234567890',
jsep: sdp,
})
To generate call_id
for outgoing call request could be used next method:
call_id = webtritSignalingClient.generateCallId()
Source code examples
In examples
folder containing 2 scripts that used webtrit_signaling_ts
to communicate with webtrit_core
.
demo
- simple script this initializes callback and alert if the connection is established or failed;test
- the script receives a call and depending on configuration decline or answer, or make a call to a specific called number.
Retrieve token from webtrit_core
curl -X POST \
-H "Content-Type: application/json" \
-d '{"identifier":"web-12345", "login":"<login>", "password":"<password>", "type":"web"}' \
http://<webtrit_core server>/api/v1/session
Environment variables for demo
example
TOKEN
- access tokenURL
- webtrit signaling server URL in format:http://<webtrit_core server>/api/v1/session
test
example
For this script are two options for transferring configuration parameters. Through environment variables or through URL parameters
Environment variables for test
example
ID
- unique identificator of script in status data, requiredTOKEN
- access tokenURL
- webtrit signaling server URL in format:ws://<webtrit_core server>/api/v1/session
, default:ws://localhost:4000/signaling/v1
CALLED_NUMBER
- the number to calledVIDEO_CALL
- make a video calltrue
or without videofalse
, default:false
INCOMING_CALL_DURATION
- the middle value of incoming call duration in seconds, for details see section: call duration possible values, default:-2
OUTGOING_CALL_DURATION
- the middle value of outgoing call duration in seconds, for details see section: call duration possible values, default:-2
INCOMING_CALL_DEVIATION
- deviation from middle value real call duration randomized in range from (INCOMING_CALL_DURATION - INCOMING_CALL_DEVIATION) to (INCOMING_CALL_DURATION + INCOMING_CALL_DEVIATION), default:0
OUTGOING_CALL_DEVIATION
- deviation from middle value real call duration randomized in range from (OUTGOING_CALL_DURATION - OUTGOING_CALL_DEVIATION) to (OUTGOING_CALL_DURATION + OUTGOING_CALL_DEVIATION), default:0
PAUSE_BETWEEN_CALL
- pause between outgoing call,0
- no pause,>0
- pause in seconds, default:1s
INTERVAL
- the interval of peerConnection statistic retrieve in seconds, default:1s
URL parameters for test
example
id
- unique identificator of script in status data, requiretoken
- access tokenurl
- webtrit signaling server URL in format:ws://<webtrit_core server>/api/v1/session
, default:ws://localhost:4000/signaling/v1
called
- the number to calledvideo
- make a video calltrue
or without videofalse
, default:false
in_duration
- the middle value of incoming call duration in seconds, for details see section: call duration possible values, default:-2
out_duration
- the middle value of outgoing call duration in seconds, for details see section: call duration possible values, default:-2
in_deviation
- deviation from middle value real call duration randomized in range from (INCOMING_CALL_DURATION - INCOMING_CALL_DEVIATION) to (INCOMING_CALL_DURATION + INCOMING_CALL_DEVIATION), default:0
out_deviation
- deviation from middle value real call duration randomized in range from (OUTGOING_CALL_DURATION - OUTGOING_CALL_DEVIATION) to (OUTGOING_CALL_DURATION + OUTGOING_CALL_DEVIATION), default:0
pause
- pause between outgoing call,0
- no pause,>0
- pause in seconds, default:1s
stats_interval
- the interval of peerConnection statistic retrieve in seconds, default:1s
Call duration possible values
-2
- outgoing do not make/incoming drop-1
- infinity outgoing or incoming call0
- outgoing call with 0 duration>0
- call duration in seconds