-
Notifications
You must be signed in to change notification settings - Fork 472
/
MeetingSessionStatus.ts
208 lines (198 loc) · 9.59 KB
/
MeetingSessionStatus.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { SdkSignalFrame } from '../signalingprotocol/SignalingProtocol.js';
import MeetingSessionStatusCode from './MeetingSessionStatusCode';
/**
* [[MeetingSessionStatus]] indicates a status received regarding the session.
*/
export default class MeetingSessionStatus {
constructor(private _statusCode: MeetingSessionStatusCode) {}
statusCode(): MeetingSessionStatusCode {
return this._statusCode;
}
isFailure(): boolean {
switch (this._statusCode) {
case MeetingSessionStatusCode.AudioAuthenticationRejected:
case MeetingSessionStatusCode.AudioCallAtCapacity:
case MeetingSessionStatusCode.AudioInternalServerError:
case MeetingSessionStatusCode.AudioServiceUnavailable:
case MeetingSessionStatusCode.AudioDisconnected:
case MeetingSessionStatusCode.VideoCallAtSourceCapacity:
case MeetingSessionStatusCode.SignalingBadRequest:
case MeetingSessionStatusCode.SignalingInternalServerError:
case MeetingSessionStatusCode.SignalingRequestFailed:
case MeetingSessionStatusCode.ICEGatheringTimeoutWorkaround:
case MeetingSessionStatusCode.ConnectionHealthReconnect:
case MeetingSessionStatusCode.RealtimeApiFailed:
case MeetingSessionStatusCode.TaskFailed:
case MeetingSessionStatusCode.NoAttendeePresent:
return true;
default:
return false;
}
}
isTerminal(): boolean {
switch (this._statusCode) {
case MeetingSessionStatusCode.Left:
case MeetingSessionStatusCode.AudioJoinedFromAnotherDevice:
case MeetingSessionStatusCode.AudioAuthenticationRejected:
case MeetingSessionStatusCode.AudioCallAtCapacity:
case MeetingSessionStatusCode.MeetingEnded:
case MeetingSessionStatusCode.AudioDisconnected:
case MeetingSessionStatusCode.TURNCredentialsForbidden:
case MeetingSessionStatusCode.SignalingBadRequest:
case MeetingSessionStatusCode.SignalingRequestFailed:
case MeetingSessionStatusCode.VideoCallAtSourceCapacity:
case MeetingSessionStatusCode.RealtimeApiFailed:
case MeetingSessionStatusCode.AudioAttendeeRemoved:
return true;
default:
return false;
}
}
isAudioConnectionFailure(): boolean {
switch (this._statusCode) {
case MeetingSessionStatusCode.AudioAuthenticationRejected:
case MeetingSessionStatusCode.AudioInternalServerError:
case MeetingSessionStatusCode.AudioServiceUnavailable:
case MeetingSessionStatusCode.ICEGatheringTimeoutWorkaround:
case MeetingSessionStatusCode.SignalingBadRequest:
case MeetingSessionStatusCode.SignalingInternalServerError:
case MeetingSessionStatusCode.SignalingRequestFailed:
case MeetingSessionStatusCode.RealtimeApiFailed:
case MeetingSessionStatusCode.NoAttendeePresent:
return true;
default:
return false;
}
}
toString?(): string {
switch (this._statusCode) {
case MeetingSessionStatusCode.OK:
return 'Everything is OK so far.';
case MeetingSessionStatusCode.Left:
return 'The attendee left the meeting.';
case MeetingSessionStatusCode.AudioJoinedFromAnotherDevice:
return 'The attendee joined from another device.';
case MeetingSessionStatusCode.AudioAuthenticationRejected:
return 'The meeting rejected the attendee.';
case MeetingSessionStatusCode.AudioCallAtCapacity:
return "The attendee couldn't join because the meeting was at capacity.";
case MeetingSessionStatusCode.MeetingEnded:
return 'The meeting ended.';
case MeetingSessionStatusCode.AudioInternalServerError:
case MeetingSessionStatusCode.AudioServiceUnavailable:
case MeetingSessionStatusCode.AudioDisconnected:
return 'The audio connection failed.';
case MeetingSessionStatusCode.VideoCallSwitchToViewOnly:
return "The attendee couldn't start the local video because the maximum video capacity was reached.";
case MeetingSessionStatusCode.VideoCallAtSourceCapacity:
return 'The connection failed due to an internal server error.';
case MeetingSessionStatusCode.SignalingBadRequest:
case MeetingSessionStatusCode.SignalingInternalServerError:
case MeetingSessionStatusCode.SignalingRequestFailed:
return 'The signaling connection failed.';
case MeetingSessionStatusCode.ICEGatheringTimeoutWorkaround:
return 'Gathering ICE candidates timed out. In Chrome, this might indicate that the browser is in a bad state after reconnecting to VPN.';
case MeetingSessionStatusCode.ConnectionHealthReconnect:
return 'The meeting was reconnected.';
case MeetingSessionStatusCode.RealtimeApiFailed:
return 'The real-time API failed. This status code might indicate that the callback you passed to the real-time API threw an exception.';
case MeetingSessionStatusCode.TaskFailed:
return 'The connection failed. See the error message for more details.';
case MeetingSessionStatusCode.IncompatibleSDP:
return 'The connection failed due to incompatible SDP.';
case MeetingSessionStatusCode.TURNCredentialsForbidden:
return 'The meeting ended, or the attendee was removed.';
case MeetingSessionStatusCode.NoAttendeePresent:
return 'The attendee was not present.';
case MeetingSessionStatusCode.AudioAttendeeRemoved:
return 'The meeting ended because attendee removed.';
case MeetingSessionStatusCode.AudioVideoWasRemovedFromPrimaryMeeting:
return 'The Primary meeting credentials provided are no longer valid. chime::DeleteAttendee may have been called on them.';
case MeetingSessionStatusCode.AudioVideoDisconnectedWhilePromoted:
return 'The client disconnected while promoted, which will automatically demote. The attendee must promote again to participate.';
case MeetingSessionStatusCode.AudioDisconnectAudio:
return 'The audio connection failed.';
/* istanbul ignore next */
default: {
// You get a compile-time error if you do not handle any status code.
const exhaustiveCheck: never = this._statusCode;
throw new Error(`Unhandled case: ${exhaustiveCheck}`);
}
}
}
static fromSignalFrame(frame: SdkSignalFrame): MeetingSessionStatus {
if (frame.error && frame.error.status) {
return this.fromSignalingStatus(frame.error.status);
} else if (frame.type === SdkSignalFrame.Type.AUDIO_STATUS) {
if (frame.audioStatus) {
return this.fromAudioStatus(frame.audioStatus.audioStatus);
}
return new MeetingSessionStatus(MeetingSessionStatusCode.SignalingRequestFailed);
} else if (frame.type === SdkSignalFrame.Type.PRIMARY_MEETING_LEAVE) {
return new MeetingSessionStatus(
MeetingSessionStatusCode.AudioVideoWasRemovedFromPrimaryMeeting
);
}
return new MeetingSessionStatus(MeetingSessionStatusCode.OK);
}
private static fromAudioStatus(status: number): MeetingSessionStatus {
// TODO: Add these numbers to proto definition and reference them here.
switch (status) {
case 200:
return new MeetingSessionStatus(MeetingSessionStatusCode.OK);
case 301:
return new MeetingSessionStatus(MeetingSessionStatusCode.AudioJoinedFromAnotherDevice);
case 302:
return new MeetingSessionStatus(MeetingSessionStatusCode.AudioDisconnectAudio);
case 403:
return new MeetingSessionStatus(MeetingSessionStatusCode.AudioAuthenticationRejected);
case 409:
return new MeetingSessionStatus(MeetingSessionStatusCode.AudioCallAtCapacity);
case 410:
return new MeetingSessionStatus(MeetingSessionStatusCode.MeetingEnded);
case 411:
return new MeetingSessionStatus(MeetingSessionStatusCode.AudioAttendeeRemoved);
case 500:
return new MeetingSessionStatus(MeetingSessionStatusCode.AudioInternalServerError);
case 503:
return new MeetingSessionStatus(MeetingSessionStatusCode.AudioServiceUnavailable);
default:
switch (Math.floor(status / 100)) {
case 2:
return new MeetingSessionStatus(MeetingSessionStatusCode.OK);
default:
return new MeetingSessionStatus(MeetingSessionStatusCode.AudioDisconnected);
}
}
}
private static fromSignalingStatus(status: number): MeetingSessionStatus {
// TODO: Add these numbers to proto definition and reference them here.
//
// We don't bother adding additional codes with different prefixes, and we probably
// shouldn't be prefixing all these errors (e.g. `AuthenticationRejected`) with the media type
// since that doesn't make sense.
switch (status) {
case 206:
return new MeetingSessionStatus(MeetingSessionStatusCode.VideoCallSwitchToViewOnly);
case 509:
return new MeetingSessionStatus(MeetingSessionStatusCode.VideoCallAtSourceCapacity);
case 403:
return new MeetingSessionStatus(MeetingSessionStatusCode.AudioAuthenticationRejected);
case 409:
return new MeetingSessionStatus(MeetingSessionStatusCode.AudioCallAtCapacity);
default:
switch (Math.floor(status / 100)) {
case 2:
return new MeetingSessionStatus(MeetingSessionStatusCode.OK);
case 4:
return new MeetingSessionStatus(MeetingSessionStatusCode.SignalingBadRequest);
case 5:
return new MeetingSessionStatus(MeetingSessionStatusCode.SignalingInternalServerError);
default:
return new MeetingSessionStatus(MeetingSessionStatusCode.SignalingRequestFailed);
}
}
}
}