Commit 7151fad1 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Simplify the initial connection protocol.

The ServerConnection.connect method is no longer async,
we rely on the onconnected callback only.  The onconnected
callback is now only called after the initial handshake
completes.  There is a new onerror callback.
parent 58934a1a
......@@ -21,12 +21,12 @@ async function start(url) {
// connect to the server
if(token) {
await serverConnect(status, token);
serverConnect(status, token);
} else if(status.authPortal) {
window.location.href = groupStatus.authPortal
return;
} else {
await serverConnect(status, null);
serverConnect(status, null);
}
}
......@@ -46,7 +46,7 @@ function displayStatus(status) {
* @parm {Object} status
* @parm {string} token
*/
async function serverConnect(status, token) {
function serverConnect(status, token) {
// create the connection to the server
let conn = new ServerConnection();
conn.onconnected = async function() {
......@@ -66,7 +66,7 @@ async function serverConnect(status, token) {
conn.onjoined = onJoined;
// connect and wait for the onconnected callback
await conn.connect(status.endpoint);
conn.connect(status.endpoint);
}
/**
......
......@@ -420,6 +420,10 @@ function gotClose(code, reason) {
if(code != 1000) {
console.warn('Socket close', code, reason);
}
let form = document.getElementById('userform');
if(!(form instanceof HTMLFormElement))
throw new Error('Bad type for userform');
form.active = true;
}
/**
......@@ -433,7 +437,7 @@ function gotDownStream(c) {
};
c.onerror = function(e) {
console.error(e);
displayError(e);
displayError(e.toString());
};
c.ondowntrack = function(track, transceiver, stream) {
setMedia(c);
......@@ -3903,12 +3907,12 @@ function displayMessage(message) {
return displayError(message, "info");
}
let connecting = false;
document.getElementById('userform').onsubmit = async function(e) {
e.preventDefault();
if(connecting)
return;
let form = this;
if(!(form instanceof HTMLFormElement))
throw new Error('Bad type for userform');
setVisibility('passwordform', true);
......@@ -3921,12 +3925,8 @@ document.getElementById('userform').onsubmit = async function(e) {
getInputElement('presentoff').checked = true;
// Connect to the server, gotConnected will join.
connecting = true;
try {
await serverConnect();
} finally {
connecting = false;
}
form.active = false;
serverConnect();
};
document.getElementById('disconnectbutton').onclick = function(e) {
......@@ -3997,6 +3997,10 @@ async function serverConnect() {
serverConnection.close();
serverConnection = new ServerConnection();
serverConnection.onconnected = gotConnected;
serverConnection.onerror = function(e) {
console.error(e);
displayError(e.toString());
};
serverConnection.onpeerconnection = onPeerConnection;
serverConnection.onclose = gotClose;
serverConnection.ondownstream = gotDownStream;
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment