Skip to content
This repository has been archived by the owner on Jul 16, 2024. It is now read-only.

Commit

Permalink
ULMS-3162 Updated agent
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkonst committed Jul 5, 2024
1 parent e7fa185 commit 527308d
Show file tree
Hide file tree
Showing 8 changed files with 287 additions and 619 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,5 @@ dist
.tern-port

.idea

.env*
16 changes: 7 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@ Options:
-r, --room-id Conference room id [string] [required]
--relay-only Use only "relay" ICE candidates [boolean]
--stun STUN server URL [string] [required]
--telemetry Telemetry app name [string]
--telemetry-interval Telemetry interval (ms) [number] [default: 5000]
--turn TURN server URL [string] [required]
--turn-password TURN password [string] [required]
--turn-username TURN username [string] [required]
-u, --uri MQTT broker URI [string] [required]
-ulms HTTP API endpoint for ULMS [string] [required]
--vc, --video-codec Codec name for video (SDP)
[string] [choices: "VP8", "VP9"] [default: "VP8"]
--help Show help [boolean]
Expand All @@ -43,26 +42,25 @@ Options:
ACCESS_TOKEN=foobar
BROKER_URI=wss://example.org/
CONFERENCE_API_ENDPOINT=https://example.org/api
CONFERENCE_APP_NAME=conference.example.org
CONFERENCE_ROOM_ID=ea3f9fd1-3356-43b4-b709-b7cfc563ea59
STUN_URL=stun:stun.example.org:3478
TELEMETRY_APP_NAME=telemetry.example.org
TURN_PASSWORD=password
TURN_URL=turn:example.org:3478
TURN_USERNAME=username
TURN_PASSWORD=password
ULMS_API_ENDPOINT=https://example.org/api
ULMS_CLASSROOM_ID=ea3f9fd1-3356-43b4-b709-b7cfc563ea59

wrtc-agent \
-c web.john-doe.example.org \
--classroom-id "${ULMS_CLASSROOM_ID}" \
-e ${CONFERENCE_API_ENDPOINT} \
-n ${CONFERENCE_APP_NAME} \
-P ${ACCESS_TOKEN} \
-r ${CONFERENCE_ROOM_ID} \
--relay-only \
--stun ${STUN_URL} \
--telemetry ${TELEMETRY_APP_NAME} \
--telemetry-interval 10000 \
--turn ${TURN_URL} \
--turn-username ${TURN_USERNAME} \
--turn-password ${TURN_PASSWORD} \
-u ${BROKER_URI}
-u ${BROKER_URI} \
--ulms ${ULMS_API_ENDPOINT}
```
86 changes: 25 additions & 61 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
require('isomorphic-fetch')
require('regenerator-runtime/runtime')

const process = require('process')
const debounce = require('lodash/debounce')

const { argv } = require('yargs')
Expand All @@ -16,16 +15,15 @@ const { argv } = require('yargs')
description: 'Client id for mqtt-client',
type: 'string'
},
'e': {
alias: 'endpoint',
'classroom-id': {
demandOption: true,
description: 'HTTP API endpoint for Conference client',
description: 'ULMS classroom id',
type: 'string'
},
'n': {
alias: 'name',
'e': {
alias: 'endpoint',
demandOption: true,
description: 'Conference app name',
description: 'HTTP API endpoint for Conference client',
type: 'string'
},
'P': {
Expand All @@ -49,15 +47,6 @@ const { argv } = require('yargs')
description: 'STUN server URL',
type: 'string'
},
'telemetry': {
description: 'Telemetry app name',
type: 'string'
},
'telemetry-interval': {
default: 5000,
description: 'Telemetry interval (ms)',
type: 'number'
},
'turn': {
demandOption: true,
description: 'TURN server URL',
Expand All @@ -79,6 +68,11 @@ const { argv } = require('yargs')
description: 'MQTT broker URI',
type: 'string'
},
'ulms': {
demandOption: true,
description: 'HTTP API endpoint for ULMS client',
type: 'string'
},
'vc': {
alias: 'video-codec',
choices: ['VP8', 'VP9'],
Expand All @@ -90,25 +84,23 @@ const { argv } = require('yargs')
.help()
/* eslint-enable quote-props */

// const { createPeerStatsMonitor, stats2metrics } = require('./lib/metrics')
const { createClient } = require('./lib/mqtt')
const { Peer, transformOffer } = require('./lib/peer')

// args
const {
classroomId,
clientId,
endpoint,
name: appName,
password,
roomId,
relayOnly,
stun,
// telemetry: telemetryAppName,
// telemetryInterval,
turn,
turnPassword,
turnUsername,
uri,
ulms: ulmsEndpoint,
videoCodec
} = argv

Expand All @@ -125,7 +117,6 @@ const iceTransportPolicy = relayOnly ? 'relay' : 'all'

let activeRtcStream = null
let peer = null
let peerStats = null

function listRtcStreamAll (client, roomId) {
const LIST_LIMIT = 25
Expand Down Expand Up @@ -186,7 +177,7 @@ function startListening (client, mqttClient, activeRtcStream, agentLabel) {

signalList = []

client.createRtcSignal(handleId, signals, undefined, agentLabel)
client.createTrickleSignal(handleId, signals)
.catch(errorCallback)
}

Expand All @@ -208,41 +199,18 @@ function startListening (client, mqttClient, activeRtcStream, agentLabel) {
}
)

// if (telemetryAppName) {
// peerStats = createPeerStatsMonitor(peer._peer, 1000, (stats) => {
// const payload = stats2metrics(stats)
// const data = {}
//
// payload.forEach(metric => data[metric.metric] = metric.value)
//
// process.send({ agentLabel, state: 'active', metrics: data })
//
// // console.log(`===[${agentLabel}]===`)
// // payload.forEach(metric => console.log(`${metric.metric}: \t\t\t${metric.value}`))
// // console.log('[stats]', payload)
//
// // metricsTable[agentLabel] = data
//
// // console.table(metricsTable)
// })
// }

client.connectRtc(activeRtcId, agentLabel)
.then((response) => {
handleId = response.handle_id

return peer.createOffer(listenerOptions)
})
peer.createOffer(listenerOptions)
.then(offer => {
const newOffer = transformOffer(offer, { videoCodec })

return client.createRtcSignal(handleId, newOffer, undefined, agentLabel)
.then((response) => ({ response, offer: newOffer }))
})
.then(({ response, offer }) => {
return peer.setOffer(offer)
.then(() => peer.setAnswer(response.jsep))
return client.createSignal(activeRtcId, newOffer)
.then((response) => {
handleId = response.handle_id

return { response, offer: newOffer }
})
})
.then(({ response, offer }) => peer.setOffer(offer).then(() => peer.setAnswer(response.jsep)))
.catch(error => console.debug('[startListening] error', error))
}

Expand All @@ -252,14 +220,10 @@ function stopListening () {

peer = null
}

if (peerStats) {
peerStats = null
}
}

createClient({ agentLabel, appName, clientId, endpoint, password, uri })
.then(({ conferenceClient, httpConferenceClient, mqttClient }) => {
createClient({ agentLabel, clientId, endpoint, password, ulmsEndpoint, uri })
.then(({ brokerClient, httpConferenceClient, mqttClient, ulmsClient }) => {
function isStreamActive (stream) {
const { time } = stream

Expand All @@ -286,7 +250,7 @@ createClient({ agentLabel, appName, clientId, endpoint, password, uri })
}
}

conferenceClient.on('rtc_stream.update', (event) => {
brokerClient.on('rtc_stream.update', (event) => {
const { id, rtc_id, sent_by, time } = event.data // eslint-disable-line camelcase

console.group(`[event:${event.type}]`)
Expand All @@ -299,7 +263,7 @@ createClient({ agentLabel, appName, clientId, endpoint, password, uri })
handleStream(event.data)
})

httpConferenceClient.enterRoom(roomId, agentLabel)
ulmsClient.enterClassroom(classroomId, agentLabel)
.then(() => {
console.log('[READY]')

Expand Down
Loading

0 comments on commit 527308d

Please sign in to comment.