@livedigital/client 3.48.0 → 3.49.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constants/encodings.d.ts +3 -3
- package/dist/constants/encodings.ts +3 -3
- package/dist/engine/handlers/ChannelAudioObserverEventHandler.d.ts +3 -1
- package/dist/engine/handlers/ChannelAudioObserverMissingProducerRestorer.d.ts +10 -0
- package/dist/engine/handlers/MediaEventHandler.d.ts +0 -1
- package/dist/engine/index.d.ts +7 -4
- package/dist/engine/network/DatachannelHeartbeater.d.ts +2 -2
- package/dist/engine/network/NetworkTransportPolicyManager.d.ts +22 -0
- package/dist/engine/network/index.d.ts +10 -8
- package/dist/index.d.ts +2 -0
- package/dist/index.es.js +2 -2
- package/dist/index.js +2 -2
- package/dist/inversify.tokens.d.ts +3 -1
- package/dist/types/network.d.ts +6 -6
- package/package.json +2 -3
- package/src/ClientMetaProvider.ts +0 -41
- package/src/EnhancedEventEmitter.ts +0 -75
- package/src/config/ConfigService.ts +0 -66
- package/src/constants/common.ts +0 -85
- package/src/constants/encodings.ts +0 -26
- package/src/constants/events.ts +0 -126
- package/src/constants/mutex.ts +0 -6
- package/src/constants/stats.ts +0 -1
- package/src/constants/videoConstrains.ts +0 -21
- package/src/engine/CallState.ts +0 -19
- package/src/engine/ChannelStateSynchronizer/ChannelStateSynchronizer.ts +0 -448
- package/src/engine/ChannelStateSynchronizer/types.ts +0 -22
- package/src/engine/EventsQueue.ts +0 -255
- package/src/engine/IntegrationsService.ts +0 -163
- package/src/engine/LocalMutex.ts +0 -45
- package/src/engine/Logger.ts +0 -234
- package/src/engine/MyPeer.ts +0 -25
- package/src/engine/Peer.ts +0 -602
- package/src/engine/PeerConsumer.ts +0 -276
- package/src/engine/PeerProducer.ts +0 -50
- package/src/engine/Peers.ts +0 -150
- package/src/engine/PeersStorage.ts +0 -45
- package/src/engine/RemotePeerTracks.ts +0 -73
- package/src/engine/WIDHandler.ts +0 -166
- package/src/engine/WebRTCStats/ConnectionStatsManager.ts +0 -31
- package/src/engine/WebRTCStats/InboundTrackStatsManager.ts +0 -51
- package/src/engine/WebRTCStats/OutboudTrackStatsManager.ts +0 -51
- package/src/engine/WebRTCStats/StatsHandler.ts +0 -80
- package/src/engine/WebRTCStats/TransportsStatsProvider.ts +0 -123
- package/src/engine/WebRTCStats/types.ts +0 -20
- package/src/engine/analyticsApiClient/LogApi.ts +0 -24
- package/src/engine/analyticsApiClient/MetricsApi.ts +0 -30
- package/src/engine/analyticsApiClient/helper.ts +0 -88
- package/src/engine/analyticsApiClient/index.ts +0 -42
- package/src/engine/analyticsApiClient/types.ts +0 -33
- package/src/engine/handlers/ChannelAudioObserverEventHandler.ts +0 -177
- package/src/engine/handlers/ChannelEventHandler.ts +0 -268
- package/src/engine/handlers/ChannelStateSyncEventHandler/ChannelStateConsistencyCheckResult.ts +0 -31
- package/src/engine/handlers/ChannelStateSyncEventHandler/ChannelStateConsistencyChecker.ts +0 -146
- package/src/engine/handlers/ChannelStateSyncEventHandler/consts.ts +0 -7
- package/src/engine/handlers/ChannelStateSyncEventHandler/index.ts +0 -342
- package/src/engine/handlers/ChannelStateSyncEventHandler/types.ts +0 -21
- package/src/engine/handlers/MediaEventHandler.ts +0 -273
- package/src/engine/index.ts +0 -793
- package/src/engine/media/index.ts +0 -574
- package/src/engine/media/producer/PendingClosureProducerStorage.ts +0 -37
- package/src/engine/media/producer/ProducerCloseManager.ts +0 -115
- package/src/engine/media/streamEffects/ProcessorsCache.ts +0 -41
- package/src/engine/media/streamEffects/audio/AudioTrackProcessor.ts +0 -7
- package/src/engine/media/streamEffects/audio/asdk/ASDKTrackProcessor.ts +0 -275
- package/src/engine/media/streamEffects/audio/asdk/atsrb.d.ts +0 -36
- package/src/engine/media/streamEffects/audio/asdk/errorBus.d.ts +0 -47
- package/src/engine/media/streamEffects/audio/noiseSuppression/NoiseSuppressionAudioWorkletNode.ts +0 -35
- package/src/engine/media/streamEffects/audio/noiseSuppression/NoiseSuppressionNodeProvider.ts +0 -44
- package/src/engine/media/streamEffects/audio/noiseSuppression/NoiseSuppressionScriptProcessorNode.ts +0 -69
- package/src/engine/media/streamEffects/audio/noiseSuppression/RNNoiseTrackProcessor.ts +0 -134
- package/src/engine/media/streamEffects/audio/noiseSuppression/WasmModuleCompiler.ts +0 -9
- package/src/engine/media/streamEffects/video/esdk/TrackProcessor.ts +0 -386
- package/src/engine/media/streamEffects/video/esdk/components/component.d.ts +0 -35
- package/src/engine/media/streamEffects/video/esdk/components/countdown/countdown.d.ts +0 -27
- package/src/engine/media/streamEffects/video/esdk/components/lower-third/collection/doubleSlideRect.d.ts +0 -33
- package/src/engine/media/streamEffects/video/esdk/components/lower-third/collection/horizontalMirror.d.ts +0 -29
- package/src/engine/media/streamEffects/video/esdk/components/lower-third/collection/leftTextbox.d.ts +0 -31
- package/src/engine/media/streamEffects/video/esdk/components/lower-third/collection/slideBold.d.ts +0 -41
- package/src/engine/media/streamEffects/video/esdk/components/lower-third/collection/twoSideRects/animatedBox.d.ts +0 -59
- package/src/engine/media/streamEffects/video/esdk/components/lower-third/collection/twoSideRects/twoSlideRects.d.ts +0 -27
- package/src/engine/media/streamEffects/video/esdk/components/lower-third/lowerThird.d.ts +0 -83
- package/src/engine/media/streamEffects/video/esdk/components/overlay-screen/overlayScreen.d.ts +0 -40
- package/src/engine/media/streamEffects/video/esdk/components/overlay-screen/overlaySprite.d.ts +0 -10
- package/src/engine/media/streamEffects/video/esdk/components/stickers/stickerSprite.d.ts +0 -51
- package/src/engine/media/streamEffects/video/esdk/components/stickers/stickers.d.ts +0 -54
- package/src/engine/media/streamEffects/video/esdk/components/utils/positionHelper.d.ts +0 -14
- package/src/engine/media/streamEffects/video/esdk/components/waterMark/waterMark.d.ts +0 -20
- package/src/engine/media/streamEffects/video/esdk/tsvb.d.ts +0 -187
- package/src/engine/media/streamEffects/video/esdk/utils/errorBus.d.ts +0 -42
- package/src/engine/media/tracks/DefaultAudioTrack.ts +0 -178
- package/src/engine/media/tracks/DefaultBaseTrack.ts +0 -592
- package/src/engine/media/tracks/DefaultVideoTrack.ts +0 -301
- package/src/engine/media/tracks/MediaStreamTrackManager.ts +0 -50
- package/src/engine/media/tracks/PeerTrack.ts +0 -558
- package/src/engine/network/DataChannelsManager.ts +0 -164
- package/src/engine/network/DatachannelHeartbeater.ts +0 -122
- package/src/engine/network/SignalingHeartbeater.ts +0 -55
- package/src/engine/network/index.ts +0 -961
- package/src/engine/signalingApiClient/SignalingApiClient.ts +0 -95
- package/src/engine/signalingApiClient/api.ts +0 -2289
- package/src/engine/system/index.ts +0 -221
- package/src/errors/AlreadyConnectedError.ts +0 -11
- package/src/errors/AlreadyCreatedError.ts +0 -11
- package/src/errors/ForbiddenError.ts +0 -11
- package/src/errors/InvalidPayloadError.ts +0 -11
- package/src/errors/InvalidRequestError.ts +0 -11
- package/src/errors/LivedigitalSDKError.ts +0 -15
- package/src/errors/NeedJoinFirstError.ts +0 -11
- package/src/errors/NotFoundError.ts +0 -11
- package/src/errors/OperationError.ts +0 -47
- package/src/errors/RequestError.ts +0 -11
- package/src/errors/TimeoutError.ts +0 -11
- package/src/errors/TooManyRequestsError.ts +0 -11
- package/src/errors/UnauthorizedError.ts +0 -11
- package/src/errors/UnsupportedError.ts +0 -15
- package/src/errors/signalingApiErrorMapper.ts +0 -143
- package/src/helpers/appDataValidator.ts +0 -21
- package/src/helpers/browser.ts +0 -37
- package/src/helpers/channelMessageConverter.ts +0 -124
- package/src/helpers/common.ts +0 -96
- package/src/helpers/datetime.ts +0 -11
- package/src/helpers/errors.ts +0 -25
- package/src/helpers/filterStatsCodecs.ts +0 -3
- package/src/helpers/loader.ts +0 -59
- package/src/helpers/media.ts +0 -57
- package/src/helpers/peer.ts +0 -19
- package/src/helpers/randomString.ts +0 -18
- package/src/helpers/retry.ts +0 -74
- package/src/index.ts +0 -171
- package/src/inversify.config.ts +0 -333
- package/src/inversify.factories.ts +0 -191
- package/src/inversify.tokens.ts +0 -42
- package/src/proto/.gitkeep +0 -0
- package/src/proto/generated/channel/channel_activity_confirmation_time.ts +0 -110
- package/src/proto/generated/channel/channel_management_event.ts +0 -213
- package/src/proto/generated/channel/channel_produce_permissions.ts +0 -171
- package/src/proto/generated/channel/channel_state.ts +0 -94
- package/src/proto/generated/channel/channel_state_short.ts +0 -282
- package/src/proto/generated/channel_message/channel_event.ts +0 -401
- package/src/proto/generated/channel_message/channel_message.ts +0 -139
- package/src/proto/generated/channel_message/media_event.ts +0 -290
- package/src/proto/generated/consumer/consumer.ts +0 -167
- package/src/proto/generated/google/protobuf/struct.ts +0 -588
- package/src/proto/generated/google/protobuf/timestamp.ts +0 -229
- package/src/proto/generated/peer/peer.ts +0 -430
- package/src/proto/generated/peer/peer_group.ts +0 -48
- package/src/proto/generated/peer/peer_role.ts +0 -48
- package/src/proto/generated/producer/producer.ts +0 -204
- package/src/proto/generated/producer/producer_kind.ts +0 -48
- package/src/proto/generated/producer/producer_label.ts +0 -78
- package/src/proto/generated/producer/producer_spatial_layer_request.ts +0 -116
- package/src/proto/generated/transport/transport_connection_timeout.ts +0 -156
- package/src/proto/generated/transport/transport_connection_timeout_reason.ts +0 -48
- package/src/proto/generated/transport/transport_direction.ts +0 -48
- package/src/types/channelAudioObserver.ts +0 -34
- package/src/types/channelStateSyncronizer.ts +0 -22
- package/src/types/client.ts +0 -27
- package/src/types/common.ts +0 -399
- package/src/types/container.ts +0 -31
- package/src/types/engine.ts +0 -97
- package/src/types/media.ts +0 -146
- package/src/types/mediasoup.ts +0 -10
- package/src/types/network.ts +0 -10
- package/src/types/streamEffects.ts +0 -23
|
@@ -1,221 +0,0 @@
|
|
|
1
|
-
import { inject, injectable } from 'inversify';
|
|
2
|
-
import { CLIENT_EVENTS } from '../../constants/events';
|
|
3
|
-
import EnhancedEventEmitter from '../../EnhancedEventEmitter';
|
|
4
|
-
import { TOKEN } from '../../inversify.tokens';
|
|
5
|
-
import { AvailableMediaDevices, DeviceErrors } from '../../types/common';
|
|
6
|
-
import Logger from '../Logger';
|
|
7
|
-
|
|
8
|
-
const isUnexpectedError = (errorMessage: string): boolean => {
|
|
9
|
-
const errors: string[] = [
|
|
10
|
-
DeviceErrors.NotFoundError,
|
|
11
|
-
DeviceErrors.NotAllowedError,
|
|
12
|
-
DeviceErrors.DeviceIsBusy,
|
|
13
|
-
];
|
|
14
|
-
|
|
15
|
-
return !errors.includes(errorMessage);
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const getDeviceErrorCode = (error: unknown): string | undefined => {
|
|
19
|
-
if (error instanceof Error) {
|
|
20
|
-
return error.message;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (typeof error === 'string') {
|
|
24
|
-
return error;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
if (error && typeof error === 'object' && 'message' in error) {
|
|
28
|
-
const maybeMessage = (error as { message?: unknown }).message;
|
|
29
|
-
|
|
30
|
-
return typeof maybeMessage === 'string' ? maybeMessage : undefined;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return undefined;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
@injectable()
|
|
37
|
-
class System {
|
|
38
|
-
public isEnableVideoDevicesLock = false;
|
|
39
|
-
|
|
40
|
-
public isEnableAudioDevicesLock = false;
|
|
41
|
-
|
|
42
|
-
public isDevicesDetected = false;
|
|
43
|
-
|
|
44
|
-
public availableVideoDevices: MediaDeviceInfo[] = [];
|
|
45
|
-
|
|
46
|
-
public availableAudioDevices: MediaDeviceInfo[] = [];
|
|
47
|
-
|
|
48
|
-
readonly #logger: Logger;
|
|
49
|
-
|
|
50
|
-
constructor(
|
|
51
|
-
@inject(TOKEN.ClientEventEmitter) private readonly clientEventEmitter: EnhancedEventEmitter,
|
|
52
|
-
@inject(TOKEN.LoggerFactory) loggerFactory: (namespace: string) => Logger,
|
|
53
|
-
) {
|
|
54
|
-
this.#logger = loggerFactory('System');
|
|
55
|
-
|
|
56
|
-
this.deviceChangeHandler = this.deviceChangeHandler.bind(this);
|
|
57
|
-
|
|
58
|
-
this.listenDevices();
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
setIsEnableVideoDevicesLock(value: boolean): void {
|
|
62
|
-
this.isEnableVideoDevicesLock = value;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
setIsEnableAudioDevicesLock(value: boolean): void {
|
|
66
|
-
this.isEnableAudioDevicesLock = value;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
setAvailableVideoDevices(availableVideoDevices: MediaDeviceInfo[]): void {
|
|
70
|
-
this.availableVideoDevices = availableVideoDevices;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
setAvailableAudioDevices(availableAudioDevices: MediaDeviceInfo[]): void {
|
|
74
|
-
this.availableAudioDevices = availableAudioDevices;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
async requestMediaDevicesAccess(
|
|
78
|
-
constraints: MediaStreamConstraints = { video: true, audio: true },
|
|
79
|
-
): Promise<MediaStreamTrack[]> {
|
|
80
|
-
try {
|
|
81
|
-
const stream = await navigator.mediaDevices.getUserMedia(constraints);
|
|
82
|
-
|
|
83
|
-
return stream.getTracks();
|
|
84
|
-
} catch (error) {
|
|
85
|
-
this.#logger.error('getUserMedia()', { error, constraints });
|
|
86
|
-
|
|
87
|
-
const errorName = error instanceof Error ? error.name : undefined;
|
|
88
|
-
|
|
89
|
-
if (errorName === 'NotAllowedError') {
|
|
90
|
-
throw new Error(DeviceErrors.NotAllowedError);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
if (errorName === 'NotReadableError') {
|
|
94
|
-
throw new Error(DeviceErrors.DeviceIsBusy);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (errorName === 'NotFoundError') {
|
|
98
|
-
throw new Error(DeviceErrors.NotFoundError);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
throw new Error(DeviceErrors.RequestDevicesUnknownError);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
async hasAvailableMediaDevicesList(): Promise<boolean> {
|
|
106
|
-
const devices = await navigator.mediaDevices.enumerateDevices();
|
|
107
|
-
|
|
108
|
-
if (devices.length === 0) {
|
|
109
|
-
return true;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/* this checks on browser level, will succeed if allowed in browser, but denied by OS */
|
|
113
|
-
const hasDevicesList = devices.every((device) => device.deviceId && device.label);
|
|
114
|
-
|
|
115
|
-
return hasDevicesList;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
async refreshAvailableMediaDevicesList(): Promise<MediaDeviceInfo[]> {
|
|
119
|
-
const devices = await navigator.mediaDevices.enumerateDevices();
|
|
120
|
-
const videoDevices = [] as MediaDeviceInfo[];
|
|
121
|
-
const audioDevices = [] as MediaDeviceInfo[];
|
|
122
|
-
devices.forEach((device) => {
|
|
123
|
-
if (device.deviceId === '') {
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
if (device.kind === 'videoinput') {
|
|
128
|
-
videoDevices.push(device);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
if (device.kind === 'audioinput') {
|
|
132
|
-
audioDevices.push(device);
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
this.setAvailableVideoDevices(videoDevices);
|
|
137
|
-
this.setAvailableAudioDevices(audioDevices);
|
|
138
|
-
|
|
139
|
-
const mapDeviceInfo = ({ label, kind }: MediaDeviceInfo): { label: string; kind: MediaDeviceKind } => ({
|
|
140
|
-
label,
|
|
141
|
-
kind,
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
this.#logger.debug('Devices list updated', {
|
|
145
|
-
videoDevices: videoDevices.map(mapDeviceInfo),
|
|
146
|
-
audioDevices: audioDevices.map(mapDeviceInfo),
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
return devices;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
async detectDevices(force?: boolean): Promise<void> {
|
|
153
|
-
if (this.isDevicesDetected && !force) {
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
const hasAvailableMediaDevicesList = await this.hasAvailableMediaDevicesList();
|
|
158
|
-
|
|
159
|
-
if (!hasAvailableMediaDevicesList) {
|
|
160
|
-
await this.tryToAccessDevices();
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
// at this moment an access to devices were granted or no devices exist
|
|
164
|
-
this.isDevicesDetected = true;
|
|
165
|
-
|
|
166
|
-
const rawDevices = await this.refreshAvailableMediaDevicesList();
|
|
167
|
-
const hasAudioInputDevices = rawDevices.some((x) => x.kind === 'audioinput');
|
|
168
|
-
const hasVideoInputDevices = rawDevices.some((x) => x.kind === 'videoinput');
|
|
169
|
-
|
|
170
|
-
if (!hasAudioInputDevices && !hasVideoInputDevices) {
|
|
171
|
-
throw new Error(DeviceErrors.NoDevices);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
async deviceChangeHandler(): Promise<void> {
|
|
176
|
-
if (!this.isDevicesDetected) {
|
|
177
|
-
return;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
await this.refreshAvailableMediaDevicesList();
|
|
181
|
-
|
|
182
|
-
const payload: AvailableMediaDevices = {
|
|
183
|
-
audio: this.availableAudioDevices,
|
|
184
|
-
video: this.availableVideoDevices,
|
|
185
|
-
};
|
|
186
|
-
this.clientEventEmitter.safeEmit(CLIENT_EVENTS.devicesListUpdated, payload);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
listenDevices(): void {
|
|
190
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
191
|
-
navigator.mediaDevices.addEventListener('devicechange', this.deviceChangeHandler);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
private async assertHasAccessToMediaDevices(
|
|
195
|
-
constraints: MediaStreamConstraints = { video: true, audio: true },
|
|
196
|
-
): Promise<void> {
|
|
197
|
-
const tracks = await this.requestMediaDevicesAccess(constraints);
|
|
198
|
-
tracks.forEach((track) => track.stop());
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
private async tryToAccessDevices(): Promise<void> {
|
|
202
|
-
try {
|
|
203
|
-
const tracks = await this.requestMediaDevicesAccess();
|
|
204
|
-
tracks.forEach((track) => track.stop());
|
|
205
|
-
} catch (error) {
|
|
206
|
-
const errorCode = getDeviceErrorCode(error);
|
|
207
|
-
|
|
208
|
-
if (!errorCode || isUnexpectedError(errorCode)) {
|
|
209
|
-
throw error;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/* if device is busy that means we have permissions */
|
|
213
|
-
if (errorCode !== DeviceErrors.DeviceIsBusy) {
|
|
214
|
-
await this.assertHasAccessToMediaDevices({ audio: true });
|
|
215
|
-
await this.assertHasAccessToMediaDevices({ video: true });
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
export default System;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import LivedigitalSDKError from './LivedigitalSDKError';
|
|
2
|
-
|
|
3
|
-
class AlreadyConnectedError extends LivedigitalSDKError {
|
|
4
|
-
static readonly DEFAULT_MESSAGE = 'Peer is already connected';
|
|
5
|
-
|
|
6
|
-
constructor(msg?: string, errorCode?: string, meta?: Record<string, unknown>) {
|
|
7
|
-
super(msg ?? AlreadyConnectedError.DEFAULT_MESSAGE, errorCode ?? 'already_connected', meta);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export default AlreadyConnectedError;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import LivedigitalSDKError from './LivedigitalSDKError';
|
|
2
|
-
|
|
3
|
-
class AlreadyCreatedError extends LivedigitalSDKError {
|
|
4
|
-
static readonly DEFAULT_MESSAGE = 'Resource has already been created';
|
|
5
|
-
|
|
6
|
-
constructor(msg?: string, errorCode?: string, meta?: Record<string, unknown>) {
|
|
7
|
-
super(msg ?? AlreadyCreatedError.DEFAULT_MESSAGE, errorCode ?? 'already_created', meta);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export default AlreadyCreatedError;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import LivedigitalSDKError from './LivedigitalSDKError';
|
|
2
|
-
|
|
3
|
-
class ForbiddenError extends LivedigitalSDKError {
|
|
4
|
-
static readonly DEFAULT_MESSAGE = 'Forbidden';
|
|
5
|
-
|
|
6
|
-
constructor(msg?: string, errorCode?: string, meta?: Record<string, unknown>) {
|
|
7
|
-
super(msg ?? ForbiddenError.DEFAULT_MESSAGE, errorCode ?? 'forbidden', meta);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export default ForbiddenError;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import LivedigitalSDKError from './LivedigitalSDKError';
|
|
2
|
-
|
|
3
|
-
class InvalidPayloadError extends LivedigitalSDKError {
|
|
4
|
-
static readonly DEFAULT_MESSAGE: string = 'Invalid payload';
|
|
5
|
-
|
|
6
|
-
constructor(msg?: string, errorCode?: string, meta?: Record<string, unknown>) {
|
|
7
|
-
super(msg ?? InvalidPayloadError.DEFAULT_MESSAGE, errorCode ?? 'invalid_payload', meta);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export default InvalidPayloadError;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import LivedigitalSDKError from './LivedigitalSDKError';
|
|
2
|
-
|
|
3
|
-
class InvalidRequestError extends LivedigitalSDKError {
|
|
4
|
-
static readonly DEFAULT_MESSAGE: string = 'Invalid request';
|
|
5
|
-
|
|
6
|
-
constructor(msg?: string, errorCode?: string, meta?: Record<string, unknown>) {
|
|
7
|
-
super(msg ?? InvalidRequestError.DEFAULT_MESSAGE, errorCode ?? 'invalid_request', meta);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export default InvalidRequestError;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
class LivedigitalSDKError extends Error {
|
|
2
|
-
readonly errorCode: string;
|
|
3
|
-
|
|
4
|
-
readonly meta?: Record<string, unknown>;
|
|
5
|
-
|
|
6
|
-
constructor(msg?: string, errorCode?: string, meta?: Record<string, unknown>) {
|
|
7
|
-
super(msg ?? 'Unexpected Livedigital SDK error');
|
|
8
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
9
|
-
this.name = new.target.name;
|
|
10
|
-
this.errorCode = errorCode ?? 'unknown_error';
|
|
11
|
-
this.meta = meta;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export default LivedigitalSDKError;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import LivedigitalSDKError from './LivedigitalSDKError';
|
|
2
|
-
|
|
3
|
-
class NeedJoinFirstError extends LivedigitalSDKError {
|
|
4
|
-
static readonly DEFAULT_MESSAGE = 'Peer must join the channel before performing this request';
|
|
5
|
-
|
|
6
|
-
constructor(msg?: string, errorCode?: string, meta?: Record<string, unknown>) {
|
|
7
|
-
super(msg ?? NeedJoinFirstError.DEFAULT_MESSAGE, errorCode ?? 'need_joined_to_channel', meta);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export default NeedJoinFirstError;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import LivedigitalSDKError from './LivedigitalSDKError';
|
|
2
|
-
|
|
3
|
-
class NotFoundError extends LivedigitalSDKError {
|
|
4
|
-
static readonly DEFAULT_MESSAGE = 'Requested resource was not found';
|
|
5
|
-
|
|
6
|
-
constructor(msg?: string, errorCode?: string, meta?: Record<string, unknown>) {
|
|
7
|
-
super(msg ?? NotFoundError.DEFAULT_MESSAGE, errorCode ?? 'not_found', meta);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export default NotFoundError;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { serializeError } from 'serialize-error';
|
|
2
|
-
|
|
3
|
-
const getMessageFromCause = (cause?: unknown): string | undefined => {
|
|
4
|
-
if (typeof cause === 'string') {
|
|
5
|
-
return cause;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
if (cause instanceof Error) {
|
|
9
|
-
return cause.message;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
if (cause && typeof cause === 'object' && 'message' in cause) {
|
|
13
|
-
const maybeMessage = (cause as { message?: unknown }).message;
|
|
14
|
-
|
|
15
|
-
return typeof maybeMessage === 'string' ? maybeMessage : undefined;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
return undefined;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
class OperationError extends Error {
|
|
22
|
-
readonly errorCode: string;
|
|
23
|
-
|
|
24
|
-
readonly cause: unknown;
|
|
25
|
-
|
|
26
|
-
constructor(errorCode: string, cause?: unknown) {
|
|
27
|
-
if (cause instanceof OperationError) {
|
|
28
|
-
super(cause.message);
|
|
29
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
30
|
-
this.name = new.target.name;
|
|
31
|
-
this.errorCode = cause.errorCode;
|
|
32
|
-
this.cause = cause.cause;
|
|
33
|
-
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const internalError = serializeError(cause);
|
|
38
|
-
const message = getMessageFromCause(internalError) ?? 'Operation failed';
|
|
39
|
-
super(message);
|
|
40
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
41
|
-
this.name = new.target.name;
|
|
42
|
-
this.errorCode = errorCode;
|
|
43
|
-
this.cause = serializeError(internalError);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export default OperationError;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import LivedigitalSDKError from './LivedigitalSDKError';
|
|
2
|
-
|
|
3
|
-
class RequestError extends LivedigitalSDKError {
|
|
4
|
-
static readonly DEFAULT_MESSAGE = 'Request failed';
|
|
5
|
-
|
|
6
|
-
constructor(msg?: string, errorCode?: string, meta?: Record<string, unknown>) {
|
|
7
|
-
super(msg ?? RequestError.DEFAULT_MESSAGE, errorCode ?? 'something_went_wrong', meta);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export default RequestError;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import LivedigitalSDKError from './LivedigitalSDKError';
|
|
2
|
-
|
|
3
|
-
class TimeoutError extends LivedigitalSDKError {
|
|
4
|
-
static readonly DEFAULT_MESSAGE = 'Request timed out';
|
|
5
|
-
|
|
6
|
-
constructor(msg?: string, errorCode?: string, meta?: Record<string, unknown>) {
|
|
7
|
-
super(msg ?? TimeoutError.DEFAULT_MESSAGE, errorCode ?? 'timeout', meta);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export default TimeoutError;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import LivedigitalSDKError from './LivedigitalSDKError';
|
|
2
|
-
|
|
3
|
-
class TooManyRequestsError extends LivedigitalSDKError {
|
|
4
|
-
static readonly DEFAULT_MESSAGE = 'Too many requests';
|
|
5
|
-
|
|
6
|
-
constructor(msg?: string, errorCode?: string, meta?: Record<string, unknown>) {
|
|
7
|
-
super(msg ?? TooManyRequestsError.DEFAULT_MESSAGE, errorCode ?? 'too_many_requests', meta);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export default TooManyRequestsError;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import LivedigitalSDKError from './LivedigitalSDKError';
|
|
2
|
-
|
|
3
|
-
class UnauthorizedError extends LivedigitalSDKError {
|
|
4
|
-
static readonly DEFAULT_MESSAGE = 'Unauthorized';
|
|
5
|
-
|
|
6
|
-
constructor(msg?: string, errorCode?: string, meta?: Record<string, unknown>) {
|
|
7
|
-
super(msg ?? UnauthorizedError.DEFAULT_MESSAGE, errorCode ?? 'unauthorized', meta);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export default UnauthorizedError;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import LivedigitalSDKError from './LivedigitalSDKError';
|
|
2
|
-
|
|
3
|
-
class UnsupportedError extends LivedigitalSDKError {
|
|
4
|
-
static readonly UNSUPPORTED_DEVICE_CODE = 'unsupported_device_error';
|
|
5
|
-
|
|
6
|
-
static readonly UNSUPPORTED_OPERATION_CODE = 'unsupported_operation_error';
|
|
7
|
-
|
|
8
|
-
static readonly DEFAULT_MESSAGE = 'Unsupported operation';
|
|
9
|
-
|
|
10
|
-
constructor(msg?: string, errorCode?: string, meta?: Record<string, unknown>) {
|
|
11
|
-
super(msg ?? UnsupportedError.DEFAULT_MESSAGE, errorCode ?? 'unsupported_error', meta);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export default UnsupportedError;
|
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
import type { AxiosError } from 'axios';
|
|
3
|
-
import AlreadyConnectedError from './AlreadyConnectedError';
|
|
4
|
-
import AlreadyCreatedError from './AlreadyCreatedError';
|
|
5
|
-
import ForbiddenError from './ForbiddenError';
|
|
6
|
-
import InvalidRequestError from './InvalidRequestError';
|
|
7
|
-
import type LivedigitalSDKError from './LivedigitalSDKError';
|
|
8
|
-
import NeedJoinFirstError from './NeedJoinFirstError';
|
|
9
|
-
import NotFoundError from './NotFoundError';
|
|
10
|
-
import RequestError from './RequestError';
|
|
11
|
-
import TimeoutError from './TimeoutError';
|
|
12
|
-
import TooManyRequestsError from './TooManyRequestsError';
|
|
13
|
-
import UnauthorizedError from './UnauthorizedError';
|
|
14
|
-
|
|
15
|
-
interface ErrorResponseBody {
|
|
16
|
-
error?: string;
|
|
17
|
-
errorCode?: string;
|
|
18
|
-
[key: string]: unknown;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
type ErrorFactory = (
|
|
22
|
-
message: string,
|
|
23
|
-
errorCode: string,
|
|
24
|
-
meta?: Record<string, unknown>,
|
|
25
|
-
) => LivedigitalSDKError;
|
|
26
|
-
|
|
27
|
-
type ErrorConstructor = new (
|
|
28
|
-
message?: string,
|
|
29
|
-
errorCode?: string,
|
|
30
|
-
meta?: Record<string, unknown>,
|
|
31
|
-
) => LivedigitalSDKError;
|
|
32
|
-
|
|
33
|
-
const createFactory = (Ctor: ErrorConstructor): ErrorFactory => (message, errorCode, meta) =>
|
|
34
|
-
new Ctor(message, errorCode, meta);
|
|
35
|
-
|
|
36
|
-
const ERROR_FACTORIES: Record<string, ErrorFactory> = {
|
|
37
|
-
check_access_fail: createFactory(ForbiddenError),
|
|
38
|
-
join_room_fail: createFactory(InvalidRequestError),
|
|
39
|
-
need_joined_to_channel: createFactory(NeedJoinFirstError),
|
|
40
|
-
forbidden: createFactory(ForbiddenError),
|
|
41
|
-
not_found: createFactory(NotFoundError),
|
|
42
|
-
invalid_request: createFactory(InvalidRequestError),
|
|
43
|
-
invalid_payload: createFactory(InvalidRequestError),
|
|
44
|
-
already_created: createFactory(AlreadyCreatedError),
|
|
45
|
-
too_many_requests: createFactory(TooManyRequestsError),
|
|
46
|
-
something_went_wrong: createFactory(RequestError),
|
|
47
|
-
di_error: createFactory(InvalidRequestError),
|
|
48
|
-
resources_lock_error: createFactory(InvalidRequestError),
|
|
49
|
-
already_connected: createFactory(AlreadyConnectedError),
|
|
50
|
-
timeout: createFactory(TimeoutError),
|
|
51
|
-
unauthorized: createFactory(UnauthorizedError),
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
const isRecord = (value: unknown): value is Record<string, unknown> =>
|
|
55
|
-
typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
56
|
-
|
|
57
|
-
const isErrorResponseBody = (value: unknown): value is ErrorResponseBody => {
|
|
58
|
-
if (!isRecord(value)) {
|
|
59
|
-
return false;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const { error, errorCode } = value;
|
|
63
|
-
|
|
64
|
-
return (error === undefined || typeof error === 'string')
|
|
65
|
-
&& (errorCode === undefined || typeof errorCode === 'string');
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
const buildMeta = (
|
|
69
|
-
error: AxiosError<ErrorResponseBody>,
|
|
70
|
-
payload?: ErrorResponseBody,
|
|
71
|
-
): Record<string, unknown> | undefined => {
|
|
72
|
-
const meta: Record<string, unknown> = {};
|
|
73
|
-
|
|
74
|
-
if (payload && Object.keys(payload).length > 0) {
|
|
75
|
-
meta.response = payload;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (typeof error.response?.status === 'number') {
|
|
79
|
-
meta.status = error.response.status;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (error.response?.statusText) {
|
|
83
|
-
meta.statusText = error.response.statusText;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
if (error.code) {
|
|
87
|
-
meta.axiosCode = error.code;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (error.config?.url) {
|
|
91
|
-
meta.url = error.config.url;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
if (error.config?.method) {
|
|
95
|
-
meta.method = error.config.method;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return Object.keys(meta).length > 0 ? meta : undefined;
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
export const mapSignalingApiError = (error: unknown): Error => {
|
|
102
|
-
if (!axios.isAxiosError(error)) {
|
|
103
|
-
return error instanceof Error ? error : new RequestError();
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
const axiosError = error as AxiosError<ErrorResponseBody>;
|
|
107
|
-
|
|
108
|
-
if (!axiosError.response) {
|
|
109
|
-
const meta = buildMeta(axiosError);
|
|
110
|
-
const message = axiosError.message || RequestError.DEFAULT_MESSAGE;
|
|
111
|
-
const errorCode = axiosError.code ?? 'network_error';
|
|
112
|
-
|
|
113
|
-
return new RequestError(message, errorCode, meta);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
const payload = isErrorResponseBody(axiosError.response.data) ? axiosError.response.data : undefined;
|
|
117
|
-
|
|
118
|
-
const errorCode = typeof payload?.errorCode === 'string' ? payload.errorCode : undefined;
|
|
119
|
-
|
|
120
|
-
const messageFromPayload = typeof payload?.error === 'string' ? payload.error : undefined;
|
|
121
|
-
const message =
|
|
122
|
-
(messageFromPayload && messageFromPayload.trim().length > 0
|
|
123
|
-
? messageFromPayload
|
|
124
|
-
: axiosError.message) || RequestError.DEFAULT_MESSAGE;
|
|
125
|
-
|
|
126
|
-
const meta = buildMeta(axiosError, payload);
|
|
127
|
-
|
|
128
|
-
if (errorCode) {
|
|
129
|
-
const factory = ERROR_FACTORIES[errorCode];
|
|
130
|
-
|
|
131
|
-
return factory ? factory(message, errorCode, meta) : new RequestError(message, errorCode, meta);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
const fallbackCode =
|
|
135
|
-
axiosError.code ??
|
|
136
|
-
(typeof axiosError.response.status === 'number'
|
|
137
|
-
? `http_${ axiosError.response.status }`
|
|
138
|
-
: 'something_went_wrong');
|
|
139
|
-
|
|
140
|
-
return new RequestError(message, fallbackCode, meta);
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
export default mapSignalingApiError;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { PEER_APP_DATA_MAX_SIZE_BYTES } from '../constants/common';
|
|
2
|
-
|
|
3
|
-
const validateAppData = (appData: Record<string, unknown>): void => {
|
|
4
|
-
let validStringifiesJsonAppData: string | undefined = undefined;
|
|
5
|
-
|
|
6
|
-
try {
|
|
7
|
-
validStringifiesJsonAppData = JSON.stringify(appData);
|
|
8
|
-
} catch {
|
|
9
|
-
throw new Error('Invalid appData');
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const size = new TextEncoder().encode(validStringifiesJsonAppData).length;
|
|
13
|
-
|
|
14
|
-
if (size <= PEER_APP_DATA_MAX_SIZE_BYTES) {
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
throw new Error('Maximum size appData reached');
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export default validateAppData;
|
package/src/helpers/browser.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import Bowser from 'bowser';
|
|
2
|
-
|
|
3
|
-
export interface BrowserEnvironment {
|
|
4
|
-
isMobile: boolean;
|
|
5
|
-
isChromiumBased: boolean;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export const detectBrowserEnvironment = (userAgent?: string): BrowserEnvironment => {
|
|
9
|
-
const ua = userAgent ?? (typeof navigator !== 'undefined' ? navigator.userAgent : undefined);
|
|
10
|
-
|
|
11
|
-
if (!ua) {
|
|
12
|
-
return { isMobile: false, isChromiumBased: false };
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const parser = Bowser.getParser(ua);
|
|
16
|
-
const platformType = parser.getPlatformType(true);
|
|
17
|
-
const isMobile = platformType === 'mobile' || platformType === 'tablet';
|
|
18
|
-
|
|
19
|
-
const engineName = parser.getEngineName().toLowerCase();
|
|
20
|
-
const isChromiumFamily = parser.satisfies({
|
|
21
|
-
chrome: '>=0',
|
|
22
|
-
chromium: '>=0',
|
|
23
|
-
'chromium webview': '>=0',
|
|
24
|
-
edge: '>=0',
|
|
25
|
-
opera: '>=0',
|
|
26
|
-
'opera coast': '>=0',
|
|
27
|
-
'samsung internet for android': '>=0',
|
|
28
|
-
'yandex browser': '>=0',
|
|
29
|
-
electron: '>=0',
|
|
30
|
-
}) ?? false;
|
|
31
|
-
|
|
32
|
-
const isChromiumBased = engineName === 'blink' || (isChromiumFamily && engineName !== 'webkit');
|
|
33
|
-
|
|
34
|
-
return { isMobile, isChromiumBased };
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export const isSafari = (): boolean => /apple/i.test(navigator.vendor);
|