mirror of
https://github.com/jech/galene.git
synced 2024-11-22 16:45:58 +01:00
Detect sends on closed websocket explicitly.
It turns out that send on a closed websocket doesn't throw, so handle this case explicitly. Thanks to Giuseppe Castagna for noticing.
This commit is contained in:
parent
191624130a
commit
f70ff2424e
1 changed files with 39 additions and 21 deletions
|
@ -67,10 +67,13 @@ Connection.prototype.close = function(sendit) {
|
||||||
this.pc.close();
|
this.pc.close();
|
||||||
|
|
||||||
if(sendit) {
|
if(sendit) {
|
||||||
|
try {
|
||||||
send({
|
send({
|
||||||
type: 'close',
|
type: 'close',
|
||||||
id: this.id,
|
id: this.id,
|
||||||
});
|
});
|
||||||
|
} catch(e) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -526,7 +529,6 @@ function serverConnect() {
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
socket.onerror = function(e) {
|
socket.onerror = function(e) {
|
||||||
console.error(e);
|
|
||||||
reject(e.error ? e.error : e);
|
reject(e.error ? e.error : e);
|
||||||
};
|
};
|
||||||
socket.onopen = function(e) {
|
socket.onopen = function(e) {
|
||||||
|
@ -534,14 +536,21 @@ function serverConnect() {
|
||||||
resetChat();
|
resetChat();
|
||||||
setConnected(true);
|
setConnected(true);
|
||||||
let up = getUserPass();
|
let up = getUserPass();
|
||||||
|
try {
|
||||||
send({
|
send({
|
||||||
type: 'handshake',
|
type: 'handshake',
|
||||||
id: myid,
|
id: myid,
|
||||||
group: group,
|
group: group,
|
||||||
username: up.username,
|
username: up.username,
|
||||||
password: up.password,
|
password: up.password,
|
||||||
});
|
})
|
||||||
sendRequest(document.getElementById('requestselect').value);
|
sendRequest(document.getElementById('requestselect').value);
|
||||||
|
} catch(e) {
|
||||||
|
console.error(e);
|
||||||
|
displayError(e);
|
||||||
|
reject(e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
resolve();
|
resolve();
|
||||||
};
|
};
|
||||||
socket.onclose = function(e) {
|
socket.onclose = function(e) {
|
||||||
|
@ -730,6 +739,10 @@ async function addIceCandidates(conn) {
|
||||||
function send(m) {
|
function send(m) {
|
||||||
if(!m)
|
if(!m)
|
||||||
throw(new Error('Sending null message'));
|
throw(new Error('Sending null message'));
|
||||||
|
if(socket.readyState !== socket.OPEN) {
|
||||||
|
// send on a closed connection doesn't throw
|
||||||
|
throw(new Error('Connection is not open'));
|
||||||
|
}
|
||||||
return socket.send(JSON.stringify(m));
|
return socket.send(JSON.stringify(m));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -993,14 +1006,19 @@ function handleInput() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
addToChatbox(myid, username, message, me);
|
try {
|
||||||
send({
|
let a = send({
|
||||||
type: 'chat',
|
type: 'chat',
|
||||||
id: myid,
|
id: myid,
|
||||||
username: username,
|
username: username,
|
||||||
value: message,
|
value: message,
|
||||||
me: me,
|
me: me,
|
||||||
});
|
});
|
||||||
|
addToChatbox(myid, username, message, me);
|
||||||
|
} catch(e) {
|
||||||
|
console.error(e);
|
||||||
|
displayError(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
document.getElementById('inputform').onsubmit = function(e) {
|
document.getElementById('inputform').onsubmit = function(e) {
|
||||||
|
|
Loading…
Reference in a new issue