Skip to content

Commit c482f0c

Browse files
authored
Merge pull request #107 from saltyrtc/close-code-3008
Add close code 3008
2 parents 9598d78 + 5ed80a9 commit c482f0c

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

src/closecode.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,17 @@
77

88
export const enum CloseCode {
99
ClosingNormal = 1000,
10-
GoingAway,
11-
NoSharedSubprotocol,
10+
GoingAway = 1001,
11+
NoSharedSubprotocol = 1002,
1212
PathFull = 3000,
13-
ProtocolError,
14-
InternalError,
15-
Handover,
16-
DroppedByInitiator,
17-
InitiatorCouldNotDecrypt,
18-
NoSharedTask,
19-
InvalidKey,
13+
ProtocolError = 3001,
14+
InternalError = 3002,
15+
Handover = 3003,
16+
DroppedByInitiator = 3004,
17+
InitiatorCouldNotDecrypt = 3005,
18+
NoSharedTask = 3006,
19+
InvalidKey = 3007,
20+
Timeout = 3008,
2021
}
2122

2223
export function explainCloseCode(code: CloseCode): string {
@@ -43,6 +44,8 @@ export function explainCloseCode(code: CloseCode): string {
4344
return 'No shared task was found';
4445
case CloseCode.InvalidKey:
4546
return 'Invalid key';
47+
case CloseCode.Timeout:
48+
return 'Timeout';
4649
default:
4750
return 'Unknown';
4851
}

src/signaling/common.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -242,31 +242,32 @@ export abstract class Signaling implements saltyrtc.Signaling {
242242
if (ev.code === CloseCode.Handover) {
243243
console.info(this.logTag, 'Closed WebSocket connection due to handover');
244244
} else {
245-
console.info(this.logTag, 'Closed WebSocket connection');
245+
console.info(this.logTag, 'Closed WebSocket connection with close code ' + ev.code +
246+
' (' + explainCloseCode(ev.code) + ')');
246247
this.setState('closed');
247248
this.client.emit({type: 'connection-closed', data: ev.code});
248-
const log = (reason: string) => console.error(this.logTag, 'Websocket close reason:', reason);
249+
const logError = (reason: string) => console.error(this.logTag, 'Websocket close reason:', reason);
249250
switch (ev.code) {
250251
case CloseCode.GoingAway:
251-
log('Server is being shut down');
252+
logError('Server is being shut down');
252253
break;
253254
case CloseCode.NoSharedSubprotocol:
254-
log('No shared sub-protocol could be found');
255+
logError('No shared sub-protocol could be found');
255256
break;
256257
case CloseCode.PathFull:
257-
log('Path full (no free responder byte)');
258+
logError('Path full (no free responder byte)');
258259
break;
259260
case CloseCode.ProtocolError:
260-
log('Protocol error');
261+
logError('Protocol error');
261262
break;
262263
case CloseCode.InternalError:
263-
log('Internal error');
264+
logError('Internal error');
264265
break;
265266
case CloseCode.DroppedByInitiator:
266-
log('Dropped by initiator');
267+
logError('Dropped by initiator');
267268
break;
268269
case CloseCode.InvalidKey:
269-
log('Invalid server key');
270+
logError('Invalid server key');
270271
break;
271272
}
272273
}

0 commit comments

Comments
 (0)