Skip to content
Snippets Groups Projects
Commit 003e05f5 authored by Simon Döring's avatar Simon Döring
Browse files

Add optional passwords

parent 46db272f
Branches
No related tags found
No related merge requests found
document.addEventListener('DOMContentLoaded', function() {
var server = 'https://' + window.location.hostname + ':8089/janus'; var server = 'https://' + window.location.hostname + ':8089/janus';
var janus = null; var janus = null;
...@@ -8,24 +11,24 @@ var opaqueId = 'camera-receiver-' + Janus.randomString(12); ...@@ -8,24 +11,24 @@ var opaqueId = 'camera-receiver-' + Janus.randomString(12);
var room = 1000; var room = 1000;
var source = null; var source = null;
var connectClicked = false; var passwordSubmitClicked = false;
var urlParams = new URLSearchParams(window.location.search); var passwordButton = document.getElementById('noVNC_password_button');
var roomParam = urlParams.get('room'); var passwordInput = document.getElementById('noVNC_password_input');
if (roomParam != null && !isNaN(roomParam)) { var currentPassword = '';
room = parseInt(roomParam); var pin = '';
} else {
console.log('Got no valid room in URL search params, using default room ' + room);
}
document.addEventListener('DOMContentLoaded', function() { passwordInput.addEventListener('input', function(event) {
currentPassword = event.target.value;
});
var connectButton = document.getElementById('noVNC_connect_button'); passwordButton.onclick = function() {
connectButton.onclick = function() { pin = currentPassword;
connectButton.onclick = null; passwordSubmitClicked = true;
connectClicked = true;
}; };
parseRoomFromURL();
Janus.init({ debug: true, callback: function() { Janus.init({ debug: true, callback: function() {
if (!Janus.isWebrtcSupported()) { if (!Janus.isWebrtcSupported()) {
alert('No WebRTC support... '); alert('No WebRTC support... ');
...@@ -42,11 +45,11 @@ document.addEventListener('DOMContentLoaded', function() { ...@@ -42,11 +45,11 @@ document.addEventListener('DOMContentLoaded', function() {
videoroomHandle = pluginHandle; videoroomHandle = pluginHandle;
Janus.log('Plugin attached! (' + videoroomHandle.getPlugin() + ', id=' + videoroomHandle.getId() + ')'); Janus.log('Plugin attached! (' + videoroomHandle.getPlugin() + ', id=' + videoroomHandle.getId() + ')');
if (connectClicked) { if (passwordSubmitClicked) {
joinRoom(); joinRoom();
} else { } else {
connectButton.onclick = function() { passwordButton.onclick = function() {
connectButton.onclick = null; pin = currentPassword;
joinRoom(); joinRoom();
}; };
} }
...@@ -67,13 +70,13 @@ document.addEventListener('DOMContentLoaded', function() { ...@@ -67,13 +70,13 @@ document.addEventListener('DOMContentLoaded', function() {
} }
}); });
}}); }});
});
function handleMessagePublisher(msg, jsep) { function handleMessagePublisher(msg, jsep) {
var event = msg['videoroom']; var event = msg['videoroom'];
if (event) { if (event) {
if (event === 'joined') { if (event === 'joined') {
Janus.log('Successfully joined room ' + msg['room'] + ' with ID ' + msg['id']); Janus.log('Successfully joined room ' + msg['room'] + ' with ID ' + msg['id']);
passwordButton.onclick = null;
var publishers = msg['publishers']; var publishers = msg['publishers'];
if (publishers && publishers.length !== 0) { if (publishers && publishers.length !== 0) {
newRemoteFeed(publishers[0]['id']); newRemoteFeed(publishers[0]['id']);
...@@ -89,7 +92,11 @@ function handleMessagePublisher(msg, jsep) { ...@@ -89,7 +92,11 @@ function handleMessagePublisher(msg, jsep) {
video.remove(); video.remove();
} }
} else if (msg['error']) { } else if (msg['error']) {
alert(msg['error']); if (msg['error_code'] === 433) {
console.error('Janus: wrong pin "' + pin + '" for room ' + room);
return;
}
alert('Error message: ' + msg['error'] + '.\nError object: ' + JSON.stringify(msg, null, 2));
} }
} }
} }
...@@ -110,7 +117,8 @@ function newRemoteFeed(id) { ...@@ -110,7 +117,8 @@ function newRemoteFeed(id) {
request: 'join', request: 'join',
room, room,
ptype: 'listener', ptype: 'listener',
feed: id feed: id,
pin
}; };
remoteFeedHandle.send({ message: listen }); remoteFeedHandle.send({ message: listen });
}, },
...@@ -169,7 +177,20 @@ function joinRoom() { ...@@ -169,7 +177,20 @@ function joinRoom() {
var register = { var register = {
request: 'join', request: 'join',
room, room,
ptype: 'publisher' ptype: 'publisher',
pin
}; };
videoroomHandle.send({ message: register }); videoroomHandle.send({ message: register });
} }
function parseRoomFromURL() {
var urlParams = new URLSearchParams(window.location.search);
var roomParam = urlParams.get('room');
if (roomParam != null && !isNaN(roomParam)) {
room = parseInt(roomParam);
} else {
console.log('Got no valid room in URL search params, using default room ' + room);
}
}
});
...@@ -7,6 +7,9 @@ ...@@ -7,6 +7,9 @@
<link rel="stylesheet" href="camera-sender.css"> <link rel="stylesheet" href="camera-sender.css">
</head> </head>
<body> <body>
<div>
Leave the pin empty if the rooms has none set.
</div>
<select id="room-select"> <select id="room-select">
<option value="1001">VNC 1</option> <option value="1001">VNC 1</option>
<option value="1002">VNC 2</option> <option value="1002">VNC 2</option>
...@@ -22,10 +25,11 @@ ...@@ -22,10 +25,11 @@
<option value="stdres-16:9">640x360</option> <option value="stdres-16:9">640x360</option>
<option value="hires-16:9">1280x720</option> <option value="hires-16:9">1280x720</option>
</select> </select>
<input type="password" id="pin-input" placeholder="Room pin" />
<button id="start" disabled>Start</button> <button id="start" disabled>Start</button>
<button id="stop" disabled>Stop</button> <button id="stop" disabled>Stop</button>
<form id="bandwidth-form"> <form id="bandwidth-form">
<label>A bandwidth cap can be set here. 0 or negative means unlimited.</label> <label>A bandwidth cap can be set here. 0 or negative means no cap.</label>
<br /> <br />
<input type="text" id="bandwidth-input" placeholder="New bitrate [in kbit/s]" /> <input type="text" id="bandwidth-input" placeholder="New bitrate [in kbit/s]" />
<input type="submit" id="bandwidth-submit" value="Change" disabled /> <input type="submit" id="bandwidth-submit" value="Change" disabled />
......
...@@ -30,6 +30,7 @@ document.addEventListener('DOMContentLoaded', function() { ...@@ -30,6 +30,7 @@ document.addEventListener('DOMContentLoaded', function() {
startButton.onclick = function() { startButton.onclick = function() {
var roomSelect = document.getElementById('room-select'); var roomSelect = document.getElementById('room-select');
var resSelect = document.getElementById('res-select'); var resSelect = document.getElementById('res-select');
var pinInput = document.getElementById('pin-input');
startButton.setAttribute('disabled', ''); startButton.setAttribute('disabled', '');
roomSelect.setAttribute('disabled', ''); roomSelect.setAttribute('disabled', '');
resSelect.setAttribute('disabled', ''); resSelect.setAttribute('disabled', '');
...@@ -39,8 +40,9 @@ document.addEventListener('DOMContentLoaded', function() { ...@@ -39,8 +40,9 @@ document.addEventListener('DOMContentLoaded', function() {
}; };
room = parseInt(roomSelect.value); room = parseInt(roomSelect.value);
sendResolution = resSelect.value; sendResolution = resSelect.value;
console.log('sendResolution:', sendResolution); Janus.log('sendResolution:', sendResolution);
shareCamera(); shareCamera(pinInput.value);
pinInput.value = '';
}; };
startButton.removeAttribute('disabled'); startButton.removeAttribute('disabled');
}, },
...@@ -93,11 +95,12 @@ document.addEventListener('DOMContentLoaded', function() { ...@@ -93,11 +95,12 @@ document.addEventListener('DOMContentLoaded', function() {
}}); }});
}, false); }, false);
function shareCamera() { function shareCamera(pin) {
var register = { var register = {
request: 'join', request: 'join',
room, room,
ptype: 'publisher' ptype: 'publisher',
pin
}; };
videoroomHandle.send({ message: register }); videoroomHandle.send({ message: register });
} }
...@@ -123,7 +126,7 @@ function handleMessage(msg, jsep) { ...@@ -123,7 +126,7 @@ function handleMessage(msg, jsep) {
var event = msg['videoroom']; var event = msg['videoroom'];
if (event) { if (event) {
if (event === 'joined') { if (event === 'joined') {
console.log('Joined event:', msg); Janus.log('Joined event:', msg);
Janus.log('Successfully joined room ' + msg['room'] + ' with ID ' + msg['id']); Janus.log('Successfully joined room ' + msg['room'] + ' with ID ' + msg['id']);
if (msg['publishers'].length === 0) { if (msg['publishers'].length === 0) {
videoroomHandle.createOffer({ videoroomHandle.createOffer({
...@@ -152,7 +155,7 @@ function handleMessage(msg, jsep) { ...@@ -152,7 +155,7 @@ function handleMessage(msg, jsep) {
} }
} }
if (event === 'event' && msg['error']) { if (event === 'event' && msg['error']) {
alert(msg['error']); alert('Error message: ' + msg['error'] + '.\nError object: ' + JSON.stringify(msg, null, 2));
window.location.reload(); window.location.reload();
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment