mirror of
https://github.com/jech/galene.git
synced 2024-11-10 02:35:58 +01:00
Improve error handling in ServerConnection.connect.
This commit is contained in:
parent
b2f01a528e
commit
e824b93584
2 changed files with 14 additions and 11 deletions
|
@ -187,8 +187,9 @@ ServerConnection.prototype.getIceServers = async function() {
|
|||
*
|
||||
* @param {string} url - The URL to connect to.
|
||||
* @returns {Promise<ServerConnection>}
|
||||
* @function
|
||||
*/
|
||||
ServerConnection.prototype.connect = function(url) {
|
||||
ServerConnection.prototype.connect = async function(url) {
|
||||
let sc = this;
|
||||
if(sc.socket) {
|
||||
sc.socket.close(1000, 'Reconnecting');
|
||||
|
@ -197,19 +198,15 @@ ServerConnection.prototype.connect = function(url) {
|
|||
|
||||
if(!sc.iceServers) {
|
||||
try {
|
||||
sc.getIceServers();
|
||||
await sc.getIceServers();
|
||||
} catch(e) {
|
||||
console.error(e);
|
||||
console.warn(e);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
sc.socket = new WebSocket(url);
|
||||
} catch(e) {
|
||||
return Promise.reject(e);
|
||||
}
|
||||
sc.socket = new WebSocket(url);
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
return await new Promise((resolve, reject) => {
|
||||
this.socket.onerror = function(e) {
|
||||
reject(e);
|
||||
};
|
||||
|
|
|
@ -1296,7 +1296,7 @@ window.onclick = function(event) {
|
|||
}
|
||||
};
|
||||
|
||||
function serverConnect() {
|
||||
async function serverConnect() {
|
||||
serverConnection = new ServerConnection();
|
||||
serverConnection.onconnected = gotConnected;
|
||||
serverConnection.onclose = gotClose;
|
||||
|
@ -1311,7 +1311,13 @@ function serverConnect() {
|
|||
else
|
||||
displayWarning(`The server said: ${message}`);
|
||||
}
|
||||
return serverConnection.connect(`ws${location.protocol === 'https:' ? 's' : ''}://${location.host}/ws`);
|
||||
let url = `ws${location.protocol === 'https:' ? 's' : ''}://${location.host}/ws`;
|
||||
try {
|
||||
await serverConnection.connect(url);
|
||||
} catch(e) {
|
||||
console.error(e);
|
||||
displayError(e.message ? e.message : "Couldn't connect to " + url);
|
||||
}
|
||||
}
|
||||
|
||||
function start() {
|
||||
|
|
Loading…
Reference in a new issue