diff --git a/README.md b/README.md index b6a6e3e..82c1337 100644 --- a/README.md +++ b/README.md @@ -103,6 +103,17 @@ $ curl -X POST "http://localhost:3010/api/v1/meeting" -H "authorization: mirotal $ curl -X POST "https://sfu.mirotalk.org/api/v1/meeting" -H "authorization: mirotalksfu_default_secret" -H "Content-Type: application/json" ``` +## Direct Join + +- You can also `join` directly to your `room` by going to https://sfu.mirotalksfu.org/join?room=test&name=mirotalksfu&audio=0&video=0 + +| Params | Description | Value | +| ------ | ---------------------- | ----------------- | +| room | Room Id | test | +| name | Your name | mirotalksfu | +| audio | Enable / Disable audio | 0/1 or true/false | +| video | Enable / Disable video | 0/1 or true/false | + ## Notes - Run the project on a `Linux or Mac` system as the `mediasoup` installation could have issues on `Windows`. diff --git a/app/src/Server.js b/app/src/Server.js index 2588b3d..b4ab0ac 100644 --- a/app/src/Server.js +++ b/app/src/Server.js @@ -34,7 +34,7 @@ const hostCfg = { protected: config.hostProtected, username: config.hostUsername, password: config.hostPassword, - authenticated: true, + authenticated: !config.hostProtected, }; const apiBasePath = '/api/v1'; // api endpoint path @@ -93,7 +93,11 @@ app.get(['/login'], (req, res) => { // set new room name and join app.get(['/newroom'], (req, res) => { - res.sendFile(path.join(__dirname, '../../', 'public/view/newroom.html')); + if (hostCfg.authenticated) { + res.sendFile(path.join(__dirname, '../../', 'public/view/newroom.html')); + } else { + res.sendFile(path.join(__dirname, '../../', 'public/view/login.html')); + } }); // if not allow video/audio @@ -108,6 +112,18 @@ app.get(['/privacy'], (req, res) => { // no room name specified to join 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 + 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) { + res.sendFile(path.join(__dirname, '../../', 'public/view/Room.html')); + return; + } + } res.redirect('/'); }); diff --git a/public/js/Room.js b/public/js/Room.js index 3badb71..62b87fa 100644 --- a/public/js/Room.js +++ b/public/js/Room.js @@ -29,13 +29,12 @@ let participantsCount = 0; let rc = null; let producer = null; -let peer_name = 'peer_' + getRandomNumber(5); +let room_id = getRoomId(); +let peer_name = getPeerName(); let peer_geo = null; let peer_info = null; -let room_id = location.pathname.substring(6); let isEnumerateDevices = false; - let isAudioAllowed = false; let isVideoAllowed = false; let isScreenAllowed = false; @@ -59,16 +58,6 @@ let isButtonsVisible = false; const socket = io(); -function getRandomNumber(length) { - let result = ''; - let characters = '0123456789'; - let charactersLength = characters.length; - for (let i = 0; i < length; i++) { - result += characters.charAt(Math.floor(Math.random() * charactersLength)); - } - return result; -} - function initClient() { if (!DetectRTC.isMobileDevice) { setTippy('shareButton', 'Share the room', 'right'); @@ -121,6 +110,30 @@ function setTippy(elem, content, placement) { }); } +// #################################################### +// GET ROOM ID +// #################################################### + +function getRoomId() { + let qs = new URLSearchParams(window.location.search); + let queryRoomId = qs.get('room'); + let roomId = queryRoomId ? queryRoomId : location.pathname.substring(6); + if (roomId == '') { + roomId = makeId(12); + } + return roomId; +} + +function makeId(length) { + let result = ''; + let characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; + let charactersLength = characters.length; + for (let i = 0; i < length; i++) { + result += characters.charAt(Math.floor(Math.random() * charactersLength)); + } + return result; +} + // #################################################### // ENUMERATE DEVICES // #################################################### @@ -220,6 +233,11 @@ function appenChild(device, el) { // SOME PEER INFO // #################################################### +function getPeerName() { + let qs = new URLSearchParams(window.location.search); + return qs.get('name'); +} + function getPeerInfo() { peer_info = { detect_rtc_version: DetectRTC.version, @@ -254,6 +272,14 @@ function getPeerGeoLocation() { function whoAreYou() { console.log('04 ----> Who are you'); + if (peer_name) { + checkMedia(); + getPeerInfo(); + shareRoom(); + joinRoom(peer_name, room_id); + return; + } + Swal.fire({ allowOutsideClick: false, allowEscapeKey: false, @@ -307,6 +333,16 @@ function handleVideo(e) { setColor(startVideoButton, isVideoAllowed ? 'white' : 'red'); } +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; +} + // #################################################### // SHARE ROOM // ####################################################