@whereby.com/browser-sdk 2.0.0-alpha1 → 2.0.0-alpha10

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/types.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  import React from 'react';
2
+ import RtcManager from '@whereby/jslib-media/src/webrtc/RtcManager';
3
+ import { ChatMessage as ChatMessage$1 } from '@whereby/jslib-media/src/utils/ServerSocket';
2
4
 
3
5
  interface WherebyEmbedAttributes {
4
6
  audio: string;
@@ -31,11 +33,88 @@ declare global {
31
33
  }
32
34
  }
33
35
 
34
- interface VideoElProps {
36
+ interface VideoViewSelfProps {
35
37
  stream: MediaStream;
36
38
  style?: React.CSSProperties;
37
39
  }
38
- declare const _default: ({ stream, style }: VideoElProps) => JSX.Element;
40
+ type VideoViewProps = VideoViewSelfProps & React.DetailedHTMLProps<React.VideoHTMLAttributes<HTMLVideoElement>, HTMLVideoElement>;
41
+ declare const _default: ({ muted, stream, ...rest }: VideoViewProps) => JSX.Element;
42
+
43
+ type CameraEnabledEvent = {
44
+ enabled: boolean;
45
+ };
46
+ type MicrophoneEnabledEvent = {
47
+ enabled: boolean;
48
+ };
49
+ type DeviceListUpdatedEvent = {
50
+ cameraDevices: MediaDeviceInfo[];
51
+ microphoneDevices: MediaDeviceInfo[];
52
+ speakerDevices: MediaDeviceInfo[];
53
+ };
54
+ type DeviceListUpdateErrorEvent = {
55
+ error: unknown;
56
+ };
57
+ type StreamUpdatedEvent = {
58
+ stream: MediaStream;
59
+ };
60
+ interface LocalMediaEventsMap {
61
+ camera_enabled: CustomEvent<CameraEnabledEvent>;
62
+ device_list_updated: CustomEvent<DeviceListUpdatedEvent>;
63
+ device_list_update_error: CustomEvent<DeviceListUpdateErrorEvent>;
64
+ microphone_enabled: CustomEvent<MicrophoneEnabledEvent>;
65
+ stream_updated: CustomEvent<StreamUpdatedEvent>;
66
+ }
67
+ interface LocalMediaEventTarget extends EventTarget {
68
+ addEventListener<K extends keyof LocalMediaEventsMap>(type: K, listener: (ev: LocalMediaEventsMap[K]) => void, options?: boolean | AddEventListenerOptions): void;
69
+ addEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: EventListenerOptions | boolean): void;
70
+ }
71
+ declare const TypedLocalMediaEventTarget: new () => LocalMediaEventTarget;
72
+ declare class LocalMedia extends TypedLocalMediaEventTarget {
73
+ private _constraints;
74
+ _rtcManagers: RtcManager[];
75
+ stream: MediaStream;
76
+ constructor(constraints: MediaStreamConstraints);
77
+ addRtcManager(rtcManager: RtcManager): void;
78
+ removeRtcManager(rtcManager: RtcManager): void;
79
+ getCameraDeviceId(): string | undefined;
80
+ getMicrophoneDeviceId(): string | undefined;
81
+ isCameraEnabled(): boolean;
82
+ isMicrophoneEnabled(): boolean;
83
+ toggleCameraEnabled(enabled?: boolean): void;
84
+ toggleMichrophoneEnabled(enabled?: boolean): void;
85
+ setCameraDevice(deviceId: string): Promise<void>;
86
+ setMicrophoneDevice(deviceId: string): Promise<void>;
87
+ private _updateDeviceList;
88
+ start(): Promise<MediaStream>;
89
+ stop(): void;
90
+ }
91
+
92
+ interface LocalMediaState {
93
+ currentCameraDeviceId?: string;
94
+ currentMicrophoneDeviceId?: string;
95
+ cameraDeviceError: unknown;
96
+ cameraDevices: MediaDeviceInfo[];
97
+ isSettingCameraDevice: boolean;
98
+ isSettingMicrophoneDevice: boolean;
99
+ isStarting: boolean;
100
+ localStream?: MediaStream;
101
+ microphoneDeviceError: unknown;
102
+ microphoneDevices: MediaDeviceInfo[];
103
+ speakerDevices: MediaDeviceInfo[];
104
+ startError: unknown;
105
+ }
106
+ interface LocalMediaActions {
107
+ setCameraDevice: InstanceType<typeof LocalMedia>["setCameraDevice"];
108
+ setMicrophoneDevice: InstanceType<typeof LocalMedia>["setMicrophoneDevice"];
109
+ toggleCameraEnabled: InstanceType<typeof LocalMedia>["toggleCameraEnabled"];
110
+ toggleMicrophoneEnabled: InstanceType<typeof LocalMedia>["toggleMichrophoneEnabled"];
111
+ }
112
+ type LocalMediaRef = {
113
+ state: LocalMediaState;
114
+ actions: LocalMediaActions;
115
+ _ref: LocalMedia;
116
+ };
117
+ declare function useLocalMedia(constraints?: MediaStreamConstraints): LocalMediaRef;
39
118
 
40
119
  interface RoomParticipantData {
41
120
  displayName: string;
@@ -71,34 +150,159 @@ declare class RemoteParticipant extends RoomParticipant {
71
150
  declare class LocalParticipant extends RoomParticipant {
72
151
  readonly isLocalParticipant = true;
73
152
  constructor({ displayName, id, stream, isAudioEnabled, isVideoEnabled }: RoomParticipantData);
153
+ }
154
+ interface WaitingParticipant {
155
+ id: string;
156
+ displayName: string | null;
74
157
  }
75
158
 
76
159
  type Logger = Pick<Console, "debug" | "error" | "log" | "warn">;
77
160
  interface RoomConnectionOptions {
78
161
  displayName?: string;
79
- localStream?: MediaStream;
80
162
  localMediaConstraints?: MediaStreamConstraints;
81
163
  roomKey?: string;
82
164
  logger?: Logger;
165
+ localMedia?: LocalMedia;
166
+ }
167
+ type ChatMessage = Pick<ChatMessage$1, "senderId" | "timestamp" | "text">;
168
+ type RoomConnectionStatus = "" | "connecting" | "connected" | "room_locked" | "knocking" | "disconnected" | "accepted" | "rejected";
169
+ type RoomJoinedEvent = {
170
+ localParticipant: LocalParticipant;
171
+ remoteParticipants: RemoteParticipant[];
172
+ waitingParticipants: WaitingParticipant[];
173
+ };
174
+ type RoomConnectionStatusChangedEvent = {
175
+ roomConnectionStatus: RoomConnectionStatus;
176
+ };
177
+ type ParticipantJoinedEvent = {
178
+ remoteParticipant: RemoteParticipant;
179
+ };
180
+ type ParticipantLeftEvent = {
181
+ participantId: string;
182
+ };
183
+ type ParticipantStreamAddedEvent = {
184
+ participantId: string;
185
+ stream: MediaStream;
186
+ };
187
+ type ParticipantAudioEnabledEvent = {
188
+ participantId: string;
189
+ isAudioEnabled: boolean;
190
+ };
191
+ type ParticipantVideoEnabledEvent = {
192
+ participantId: string;
193
+ isVideoEnabled: boolean;
194
+ };
195
+ type ParticipantMetadataChangedEvent = {
196
+ participantId: string;
197
+ displayName: string;
198
+ };
199
+ type WaitingParticipantJoinedEvent = {
200
+ participantId: string;
201
+ displayName: string | null;
202
+ };
203
+ type WaitingParticipantLeftEvent = {
204
+ participantId: string;
205
+ };
206
+ interface RoomEventsMap {
207
+ chat_message: CustomEvent<ChatMessage>;
208
+ participant_audio_enabled: CustomEvent<ParticipantAudioEnabledEvent>;
209
+ participant_joined: CustomEvent<ParticipantJoinedEvent>;
210
+ participant_left: CustomEvent<ParticipantLeftEvent>;
211
+ participant_metadata_changed: CustomEvent<ParticipantMetadataChangedEvent>;
212
+ participant_stream_added: CustomEvent<ParticipantStreamAddedEvent>;
213
+ participant_video_enabled: CustomEvent<ParticipantVideoEnabledEvent>;
214
+ room_connection_status_changed: CustomEvent<RoomConnectionStatusChangedEvent>;
215
+ room_joined: CustomEvent<RoomJoinedEvent>;
216
+ waiting_participant_joined: CustomEvent<WaitingParticipantJoinedEvent>;
217
+ waiting_participant_left: CustomEvent<WaitingParticipantLeftEvent>;
218
+ }
219
+ interface RoomEventTarget extends EventTarget {
220
+ addEventListener<K extends keyof RoomEventsMap>(type: K, listener: (ev: RoomEventsMap[K]) => void, options?: boolean | AddEventListenerOptions): void;
221
+ addEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: EventListenerOptions | boolean): void;
222
+ }
223
+ declare const TypedEventTarget: new () => RoomEventTarget;
224
+ declare class RoomConnection extends TypedEventTarget {
225
+ localMedia: LocalMedia;
226
+ localParticipant: LocalParticipant | null;
227
+ roomUrl: URL;
228
+ remoteParticipants: RemoteParticipant[];
229
+ readonly localMediaConstraints?: MediaStreamConstraints;
230
+ readonly roomName: string;
231
+ private organizationId;
232
+ private credentialsService;
233
+ private apiClient;
234
+ private organizationService;
235
+ private organizationServiceCache;
236
+ private organizationApiClient;
237
+ private roomService;
238
+ private signalSocket;
239
+ private rtcManagerDispatcher?;
240
+ private rtcManager?;
241
+ private roomConnectionStatus;
242
+ private logger;
243
+ private _ownsLocalMedia;
244
+ private displayName?;
245
+ private _roomKey;
246
+ constructor(roomUrl: string, { displayName, localMedia, localMediaConstraints, logger, roomKey }: RoomConnectionOptions);
247
+ get roomKey(): string | null;
248
+ private _handleNewChatMessage;
249
+ private _handleNewClient;
250
+ private _handleClientLeft;
251
+ private _handleClientAudioEnabled;
252
+ private _handleClientVideoEnabled;
253
+ private _handleClientMetadataReceived;
254
+ private _handleKnockHandled;
255
+ private _handleKnockerLeft;
256
+ private _handleRoomJoined;
257
+ private _handleRoomKnocked;
258
+ private _handleRtcEvent;
259
+ private _handleRtcManagerCreated;
260
+ private _handleAcceptStreams;
261
+ private _handleStreamAdded;
262
+ private _joinRoom;
263
+ join(): Promise<void>;
264
+ knock(): void;
265
+ leave(): Promise<void>;
266
+ sendChatMessage(text: string): void;
267
+ setDisplayName(displayName: string): void;
268
+ acceptWaitingParticipant(participantId: string): void;
269
+ rejectWaitingParticipant(participantId: string): void;
83
270
  }
84
271
 
85
272
  type RemoteParticipantState = Omit<RemoteParticipant, "updateStreamState">;
86
- interface RoomState {
273
+ interface RoomConnectionState {
274
+ chatMessages: ChatMessage[];
275
+ isJoining: boolean;
276
+ joinError: unknown;
87
277
  localParticipant?: LocalParticipant;
88
- roomConnectionStatus?: "connecting" | "connected" | "disconnected";
278
+ mostRecentChatMessage: ChatMessage | null;
279
+ roomConnectionStatus: RoomConnectionStatus;
89
280
  remoteParticipants: RemoteParticipantState[];
90
- }
91
-
281
+ waitingParticipants: WaitingParticipant[];
282
+ }
283
+ interface UseRoomConnectionOptions extends Omit<RoomConnectionOptions, "localMedia"> {
284
+ localMedia?: LocalMediaRef;
285
+ }
92
286
  interface RoomConnectionActions {
287
+ sendChatMessage(text: string): void;
288
+ knock(): void;
289
+ setDisplayName(displayName: string): void;
93
290
  toggleCamera(enabled?: boolean): void;
94
291
  toggleMicrophone(enabled?: boolean): void;
95
- setDisplayName(displayName: string): void;
292
+ acceptWaitingParticipant(participantId: string): void;
293
+ rejectWaitingParticipant(participantId: string): void;
96
294
  }
97
295
  interface RoomConnectionComponents {
98
296
  VideoView: typeof _default;
99
297
  }
100
- declare function useRoomConnection(roomUrl: string, roomConnectionOptions: RoomConnectionOptions): [state: RoomState, actions: RoomConnectionActions, components: RoomConnectionComponents];
298
+ type RoomConnectionRef = {
299
+ state: RoomConnectionState;
300
+ actions: RoomConnectionActions;
301
+ components: RoomConnectionComponents;
302
+ _ref: RoomConnection;
303
+ };
304
+ declare function useRoomConnection(roomUrl: string, roomConnectionOptions: UseRoomConnectionOptions): RoomConnectionRef;
101
305
 
102
- declare const sdkVersion = "2.0.0-alpha1";
306
+ declare const sdkVersion = "2.0.0-alpha10";
103
307
 
104
- export { sdkVersion, useRoomConnection };
308
+ export { _default as VideoView, sdkVersion, useLocalMedia, useRoomConnection };