From c99fdb3a0a3937b7421f3bbc3349f34143df606c Mon Sep 17 00:00:00 2001 From: Miroslav Pejic Date: Fri, 21 Jan 2022 22:02:58 +0100 Subject: [PATCH] [mirotalksfu] - add param notify to API join --- README.md | 7 ++++--- app/api/join/join.js | 1 + app/api/join/join.php | 9 +++++---- app/api/join/join.py | 1 + app/api/join/join.sh | 2 +- app/api/swagger.yaml | 3 +++ app/src/Server.js | 5 +++-- app/src/ServerApi.js | 4 +++- public/js/Room.js | 40 +++++++++++++++++++++++++++++++--------- public/js/RoomClient.js | 2 ++ 10 files changed, 54 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 21744d4b..12392288 100644 --- a/README.md +++ b/README.md @@ -102,14 +102,14 @@ $ docker-compose down $ curl -X POST "http://localhost:3010/api/v1/meeting" -H "authorization: mirotalksfu_default_secret" -H "Content-Type: application/json" $ curl -X POST "https://sfu.mirotalk.org/api/v1/meeting" -H "authorization: mirotalksfu_default_secret" -H "Content-Type: application/json" # The response will give you a entrypoint / URL for the direct join to the meeting. -$ curl -X POST "http://localhost:3010/api/v1/join" -H "authorization: mirotalksfu_default_secret" -H "Content-Type: application/json" --data '{"room":"test","name":"mirotalksfu","audio":"0","video":"0"}' -$ curl -X POST "https://sfu.mirotalk.org/api/v1/join" -H "authorization: mirotalksfu_default_secret" -H "Content-Type: application/json" --data '{"room":"test","name":"mirotalksfu","audio":"0","video":"0"}' +$ curl -X POST "http://localhost:3010/api/v1/join" -H "authorization: mirotalksfu_default_secret" -H "Content-Type: application/json" --data '{"room":"test","name":"mirotalksfu","audio":"0","video":"0","notify":"0"}' +$ curl -X POST "https://sfu.mirotalk.org/api/v1/join" -H "authorization: mirotalksfu_default_secret" -H "Content-Type: application/json" --data '{"room":"test","name":"mirotalksfu","audio":"0","video":"0","notify":"0"}' ``` ## Direct Join - You can also `join` directly to your `room` by going to -- https://sfu.mirotalk.org/join?room=test&name=mirotalksfu&audio=0&video=0 +- https://sfu.mirotalk.org/join?room=test&name=mirotalksfu&audio=0&video=0¬ify=0 | Params | Type | Description | | ------ | ------- | ---------------- | @@ -117,6 +117,7 @@ $ curl -X POST "https://sfu.mirotalk.org/api/v1/join" -H "authorization: mirotal | name | string | your name | | audio | boolean | enable / disable | | video | boolean | enable / disable | + | notify | boolean | enable / disable | ## Notes diff --git a/app/api/join/join.js b/app/api/join/join.js index 1e9c0bb7..7735fd78 100644 --- a/app/api/join/join.js +++ b/app/api/join/join.js @@ -17,6 +17,7 @@ function getResponse() { name: 'mirotalksfu', audio: true, video: true, + notify: true, }), }); } diff --git a/app/api/join/join.php b/app/api/join/join.php index 4ebc08f5..d03cffd1 100644 --- a/app/api/join/join.php +++ b/app/api/join/join.php @@ -16,10 +16,11 @@ $headers = [ curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $data = array( - "room" => "test", - "name" => "mirotalksfu", - "audio" => true, - "video" => true, + "room" => "test", + "name" => "mirotalksfu", + "audio" => true, + "video" => true, + "notify" => true, ); $data_string = json_encode($data); diff --git a/app/api/join/join.py b/app/api/join/join.py index ef0e3d7b..5a73a529 100644 --- a/app/api/join/join.py +++ b/app/api/join/join.py @@ -14,6 +14,7 @@ data = { "name": "mirotalksfu", "audio": "true", "video": "true", + "notify": "true", } response = requests.post( diff --git a/app/api/join/join.sh b/app/api/join/join.sh index 86a49b55..6a2732df 100755 --- a/app/api/join/join.sh +++ b/app/api/join/join.sh @@ -6,5 +6,5 @@ MIROTALK_URL="http://localhost:3010/api/v1/join" curl $MIROTALK_URL \ --header "authorization: $API_KEY" \ --header "Content-Type: application/json" \ - --data '{"room":"test","name":"mirotalksfu","audio":"1","video":"1"}' \ + --data '{"room":"test","name":"mirotalksfu","audio":"1","video":"1","notify":"1"}' \ --request POST \ No newline at end of file diff --git a/app/api/swagger.yaml b/app/api/swagger.yaml index 176b1c71..fd58ae33 100644 --- a/app/api/swagger.yaml +++ b/app/api/swagger.yaml @@ -48,6 +48,7 @@ paths: - name - audio - video + - notify properties: room: type: string @@ -57,6 +58,8 @@ paths: type: boolean video: type: boolean + notify: + type: boolean consumes: - 'application/json' produces: diff --git a/app/src/Server.js b/app/src/Server.js index 3e30779c..ebebdced 100644 --- a/app/src/Server.js +++ b/app/src/Server.js @@ -113,12 +113,13 @@ app.get(['/privacy'], (req, res) => { app.get('/join/', (req, res) => { if (hostCfg.authenticated && Object.keys(req.query).length > 0) { log.debug('Direct Join', req.query); - // http://localhost:3010/join?room=test&name=mirotalksfu&audio=1&video=1 + // http://localhost:3010/join?room=test&name=mirotalksfu&audio=1&video=1¬ify=1 let roomName = req.query.room; let peerName = req.query.name; let peerAudio = req.query.audio; let peerVideo = req.query.video; - if (roomName && peerName && peerAudio && peerVideo) { + let notify = req.query.notify; + if (roomName && peerName && peerAudio && peerVideo && notify) { res.sendFile(path.join(__dirname, '../../', 'public/view/Room.html')); return; } diff --git a/app/src/ServerApi.js b/app/src/ServerApi.js index 06ca6845..c1b58517 100644 --- a/app/src/ServerApi.js +++ b/app/src/ServerApi.js @@ -30,7 +30,9 @@ module.exports = class ServerApi { '&audio=' + data.audio + '&video=' + - data.video + data.video + + '¬ify=' + + data.notify ); } }; diff --git a/public/js/Room.js b/public/js/Room.js index 71f4696b..81c2fe03 100644 --- a/public/js/Room.js +++ b/public/js/Room.js @@ -31,6 +31,8 @@ let producer = null; let room_id = getRoomId(); let peer_name = getPeerName(); +let notify = getNotify(); + let peer_geo = null; let peer_info = null; @@ -231,14 +233,28 @@ function appenChild(device, el) { } // #################################################### -// SOME PEER INFO +// API CHECK // #################################################### +function getNotify() { + let qs = new URLSearchParams(window.location.search); + let notify = qs.get('notify'); + if (notify) { + let queryNotify = notify === '1' || notify === 'true'; + if (queryNotify != null) return queryNotify; + } + return true; +} + function getPeerName() { let qs = new URLSearchParams(window.location.search); return qs.get('name'); } +// #################################################### +// SOME PEER INFO +// #################################################### + function getPeerInfo() { peer_info = { detect_rtc_version: DetectRTC.version, @@ -276,7 +292,7 @@ function whoAreYou() { if (peer_name) { checkMedia(); getPeerInfo(); - shareRoom(); + notify ? shareRoom() : sound('joined'); joinRoom(peer_name, room_id); return; } @@ -305,7 +321,7 @@ function whoAreYou() { }, }).then(() => { getPeerInfo(); - shareRoom(); + notify ? shareRoom() : sound('joined'); joinRoom(peer_name, room_id); }); @@ -336,12 +352,18 @@ function handleVideo(e) { function checkMedia() { let qs = new URLSearchParams(window.location.search); - let audio = qs.get('audio').toLowerCase(); - let video = qs.get('video').toLowerCase(); - let queryPeerAudio = audio === '1' || audio === 'true'; - let queryPeerVideo = video === '1' || video === 'true'; - if (queryPeerAudio != null) isAudioAllowed = queryPeerAudio; - if (queryPeerVideo != null) isVideoAllowed = queryPeerVideo; + let audio = qs.get('audio'); + let video = qs.get('video'); + if (audio) { + audio = audio.toLowerCase(); + let queryPeerAudio = audio === '1' || audio === 'true'; + if (queryPeerAudio != null) isAudioAllowed = queryPeerAudio; + } + if (video) { + video = video.toLowerCase(); + let queryPeerVideo = video === '1' || video === 'true'; + if (queryPeerVideo != null) isVideoAllowed = queryPeerVideo; + } } // #################################################### diff --git a/public/js/RoomClient.js b/public/js/RoomClient.js index b340f4d1..46fa3f8f 100644 --- a/public/js/RoomClient.js +++ b/public/js/RoomClient.js @@ -920,6 +920,8 @@ class RoomClient { async consume(producer_id, peer_name, peer_info) { this.getConsumeStream(producer_id).then( function ({ consumer, stream, kind }) { + console.log('CONSUMER', consumer); + this.consumers.set(consumer.id, consumer); if (kind === 'video') {