|
1 |
| -/** 1.5.3 */ |
2 |
| - |
3 |
| -// eslint-disable-next-line no-undef |
| 1 | +/** 1.6.0-beta */ |
| 2 | +// eslint-disable-next-line no-undef,max-classes-per-file |
4 | 3 | export as namespace SendBirdCall;
|
5 | 4 |
|
6 | 5 | export function init(appId: string): void;
|
@@ -37,6 +36,9 @@ export function handleWebhookData(data: WebhookData): void;
|
37 | 36 | export function addDirectCallSound(type: SoundType, url: string): Promise<boolean>;
|
38 | 37 | export function removeDirectCallSound(type: SoundType): boolean;
|
39 | 38 | export function getCall(callId: string): DirectCall;
|
| 39 | +export function createRoom(): Promise<Room>; |
| 40 | +export function getCachedRoomById(roomId: string): Room; |
| 41 | +export function fetchRoomById(roomId: string): Promise<Room>; |
40 | 42 | export const sdkVersion: string;
|
41 | 43 | export const appId: string;
|
42 | 44 | export const currentUser: User;
|
@@ -146,6 +148,64 @@ export interface SendBirdCallRecordingListener {
|
146 | 148 | onRecordingFailed: ((callId: string, recordingId: string, error) => void) | null;
|
147 | 149 | }
|
148 | 150 |
|
| 151 | +/** |
| 152 | + * Event Target |
| 153 | + */ |
| 154 | + |
| 155 | +interface Event { |
| 156 | + readonly args?: any[]; |
| 157 | +} |
| 158 | + |
| 159 | +declare type nullish = null | undefined; |
| 160 | + |
| 161 | +declare type ArgsType<T extends Event> = T['args'] extends nullish ? [] : T['args']; |
| 162 | + |
| 163 | +interface EventListener<T extends Event> { |
| 164 | + (...args: ArgsType<T>): void; |
| 165 | +} |
| 166 | + |
| 167 | +declare type EventMap = Record<string, Event>; |
| 168 | + |
| 169 | +declare type EventKey<T extends EventMap> = keyof T; |
| 170 | + |
| 171 | +declare class EventTarget<T extends EventMap> { |
| 172 | + |
| 173 | + /** |
| 174 | + * Adds a listener to receive events. |
| 175 | + */ |
| 176 | + addEventListener<K extends EventKey<T>>(type: K, callback: EventListener<T[K]>): void; |
| 177 | + |
| 178 | + /** |
| 179 | + * Alias for addEventListener |
| 180 | + */ |
| 181 | + on: <K extends keyof T>(type: K, callback: EventListener<T[K]>) => void; |
| 182 | + |
| 183 | + /** |
| 184 | + * Adds listener to receive events once. |
| 185 | + */ |
| 186 | + once<K extends EventKey<T>>(type: K, givenCb: EventListener<T[K]>): void; |
| 187 | + |
| 188 | + /** |
| 189 | + * Removes an added listener. |
| 190 | + */ |
| 191 | + removeEventListener<K extends EventKey<T>>(type: K, callback: EventListener<T[K]>): void; |
| 192 | + |
| 193 | + /** |
| 194 | + * Alias for removeEventListener |
| 195 | + */ |
| 196 | + off: <K extends keyof T>(type: K, callback: EventListener<T[K]>) => void; |
| 197 | + |
| 198 | + /** |
| 199 | + * Removes all added listeners. |
| 200 | + */ |
| 201 | + removeAllEventListeners(): void; |
| 202 | + |
| 203 | +} |
| 204 | + |
| 205 | +/** |
| 206 | + * DirectCall |
| 207 | + */ |
| 208 | + |
149 | 209 | export interface DirectCall {
|
150 | 210 | onEstablished: ((call: DirectCall) => void) | null;
|
151 | 211 | onConnected: ((call: DirectCall) => void) | null;
|
@@ -338,3 +398,150 @@ export interface WebhookData {
|
338 | 398 | [key: string]: any;
|
339 | 399 | }
|
340 | 400 | /* eslint-enable babel/camelcase */
|
| 401 | + |
| 402 | + |
| 403 | +/** |
| 404 | + * Room |
| 405 | + */ |
| 406 | + |
| 407 | +declare type RoomEventMap = { |
| 408 | + remoteParticipantEntered: { args: [RemoteParticipant]; }; |
| 409 | + remoteParticipantExited: { args: [RemoteParticipant]; }; |
| 410 | + remoteParticipantStreamStarted: { args: [RemoteParticipant]; }; |
| 411 | + remoteAudioSettingsChanged: { args: [RemoteParticipant]; }; |
| 412 | + remoteVideoSettingsChanged: { args: [RemoteParticipant]; }; |
| 413 | + error: { args: [Error, Particpant?] }; |
| 414 | +}; |
| 415 | + |
| 416 | +/** |
| 417 | + * Called when remote participant has been entered |
| 418 | + */ |
| 419 | +export type RemoteParticipantEnteredEventListener = (participant: RemoteParticipant) => void; |
| 420 | +/** |
| 421 | + * Called when remote participant has been exited |
| 422 | + */ |
| 423 | +export type RemoteParticipantExitedEventListener = (participant: RemoteParticipant) => void; |
| 424 | +/** |
| 425 | + * Called when it's able to receive media stream from remote participant. |
| 426 | + */ |
| 427 | +export type RemoteParticipantStreamStartedEventListener = (participant: RemoteParticipant) => void; |
| 428 | +/** |
| 429 | + * Called when audio settings of remote participant has been changed |
| 430 | + */ |
| 431 | +export type RemoteAudioSettingsChangedEventListener = (participant: RemoteParticipant) => void; |
| 432 | +/** |
| 433 | + * Called when video settings of remote participant has been changed. |
| 434 | + */ |
| 435 | +export type RemoteVideoSettingsChangedEventListener = (participant: RemoteParticipant) => void; |
| 436 | + |
| 437 | +export declare class Room extends EventTarget<RoomEventMap> { |
| 438 | + |
| 439 | + /** |
| 440 | + * The ID of room |
| 441 | + */ |
| 442 | + readonly roomId: string; |
| 443 | + |
| 444 | + /** |
| 445 | + * Long value of the date when the room created at. |
| 446 | + */ |
| 447 | + readonly createdAt: number; |
| 448 | + |
| 449 | + /** |
| 450 | + * The ID of user who created the room |
| 451 | + */ |
| 452 | + readonly createdBy: string; |
| 453 | + |
| 454 | + /** |
| 455 | + * The list of all participants including local participant. |
| 456 | + */ |
| 457 | + readonly participants: Participant[]; |
| 458 | + |
| 459 | + /** |
| 460 | + * The local participant. |
| 461 | + */ |
| 462 | + readonly localParticipant: LocalParticipant; |
| 463 | + |
| 464 | + /** |
| 465 | + * The list of remote participants. |
| 466 | + */ |
| 467 | + readonly remoteParticipants: RemoteParticipant[]; |
| 468 | + |
| 469 | + /** |
| 470 | + * Enters a room |
| 471 | + */ |
| 472 | + enter(params: EnterParams): Promise<void>; |
| 473 | + |
| 474 | + /** |
| 475 | + * Exits a room |
| 476 | + */ |
| 477 | + exit(): Promise<void>; |
| 478 | + |
| 479 | +} |
| 480 | + |
| 481 | +export interface EnterParams { |
| 482 | + audioEnabled: boolean; |
| 483 | + videoEnabled: boolean; |
| 484 | +} |
| 485 | + |
| 486 | +export enum ParticipantState { |
| 487 | + /** |
| 488 | + * The state when the participant has entered room |
| 489 | + */ |
| 490 | + ENTERED = 'entered', |
| 491 | + /** |
| 492 | + * The state when the participant has been connected. |
| 493 | + */ |
| 494 | + CONNECTED = 'connected', |
| 495 | + /** |
| 496 | + * The state when the participant has exit room |
| 497 | + */ |
| 498 | + EXITED = 'exited', |
| 499 | +} |
| 500 | + |
| 501 | +export interface Participant { |
| 502 | + participantId: string; |
| 503 | + enteredAt: number; |
| 504 | + updatedAt: number; |
| 505 | + exitedAt?: number; |
| 506 | + duration?: number; |
| 507 | + isLocalParticipant: boolean; |
| 508 | + state: ParticipantState; |
| 509 | + user: User; |
| 510 | + isAudioEnabled: boolean; |
| 511 | + isVideoEnabled: boolean; |
| 512 | + |
| 513 | + setMediaView(mediaView: HTMLMediaElement): Promise<void>; |
| 514 | +} |
| 515 | + |
| 516 | +export interface LocalParticipant extends Participant { |
| 517 | + isLocalParticipant: true; |
| 518 | + |
| 519 | + /** |
| 520 | + * Alias for setMediaView |
| 521 | + */ |
| 522 | + setLocalMediaView(mediaView: HTMLMediaElement): Promise<void>; |
| 523 | + |
| 524 | + /** |
| 525 | + * Stop the local audio. |
| 526 | + */ |
| 527 | + muteMicrophone(): void; |
| 528 | + /** |
| 529 | + * Start the local audio. |
| 530 | + */ |
| 531 | + unmuteMicrophone(): void; |
| 532 | + |
| 533 | + /** |
| 534 | + * Start the local video. |
| 535 | + */ |
| 536 | + stopVideo(): void; |
| 537 | + |
| 538 | + /** |
| 539 | + * Stop the local video. |
| 540 | + */ |
| 541 | + startVideo(): void; |
| 542 | + |
| 543 | +} |
| 544 | + |
| 545 | +export interface RemoteParticipant extends Participant { |
| 546 | + isLocalParticipant: false; |
| 547 | +} |
0 commit comments