-
Notifications
You must be signed in to change notification settings - Fork 270
Expand file tree
/
Copy patherrors.ts
More file actions
119 lines (97 loc) · 2.83 KB
/
Copy patherrors.ts
File metadata and controls
119 lines (97 loc) · 2.83 KB
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
import { DisconnectReason, RequestResponse_Reason } from '@livekit/protocol';
export class LivekitError extends Error {
code: number;
constructor(code: number, message?: string) {
super(message || 'an error has occured');
this.code = code;
}
}
export const enum ConnectionErrorReason {
NotAllowed,
ServerUnreachable,
InternalError,
Cancelled,
LeaveRequest,
}
export class ConnectionError extends LivekitError {
status?: number;
context?: unknown | DisconnectReason;
reason: ConnectionErrorReason;
constructor(
message: string,
reason: ConnectionErrorReason,
status?: number,
context?: unknown | DisconnectReason,
) {
super(1, message);
this.status = status;
this.reason = reason;
this.context = context;
}
}
export class DeviceUnsupportedError extends LivekitError {
constructor(message?: string) {
super(21, message ?? 'device is unsupported');
}
}
export class TrackInvalidError extends LivekitError {
constructor(message?: string) {
super(20, message ?? 'track is invalid');
}
}
export class UnsupportedServer extends LivekitError {
constructor(message?: string) {
super(10, message ?? 'unsupported server');
}
}
export class UnexpectedConnectionState extends LivekitError {
constructor(message?: string) {
super(12, message ?? 'unexpected connection state');
}
}
export class NegotiationError extends LivekitError {
constructor(message?: string) {
super(13, message ?? 'unable to negotiate');
}
}
export class PublishDataError extends LivekitError {
constructor(message?: string) {
super(13, message ?? 'unable to publish data');
}
}
export type RequestErrorReason =
| Exclude<RequestResponse_Reason, RequestResponse_Reason.OK>
| 'TimeoutError';
export class SignalRequestError extends LivekitError {
reason: RequestErrorReason;
constructor(message: string, reason: RequestErrorReason) {
super(15, message);
this.reason = reason;
}
}
export enum MediaDeviceFailure {
// user rejected permissions
PermissionDenied = 'PermissionDenied',
// device is not available
NotFound = 'NotFound',
// device is in use. On Windows, only a single tab may get access to a device at a time.
DeviceInUse = 'DeviceInUse',
Other = 'Other',
}
export namespace MediaDeviceFailure {
export function getFailure(error: any): MediaDeviceFailure | undefined {
if (!error || !('name' in error)) {
return undefined;
}
if (['NotFoundError', 'DevicesNotFoundError'].includes(error.name)) {
return MediaDeviceFailure.NotFound;
}
if (['NotAllowedError', 'PermissionDeniedError'].includes(error.name)) {
return MediaDeviceFailure.PermissionDenied;
}
if (['NotReadableError', 'TrackStartError'].includes(error.name)) {
return MediaDeviceFailure.DeviceInUse;
}
return MediaDeviceFailure.Other;
}
}