@signalwire/js
Version:
225 lines • 8.93 kB
TypeScript
import { BaseComponent, BaseComponentOptions, BaseConnectionState, Rooms, EventEmitter, BaseConnectionContract, WebRTCMethod, UpdateMediaParams, UpdateMediaDirection } from '@signalwire/core';
import type { ReduxComponent } from '@signalwire/core';
import RTCPeer from './RTCPeer';
import { ConnectionOptions, UpdateMediaOptionsParams, BaseConnectionEvents, OnVertoByeParams } from './utils/interfaces';
export type BaseConnectionOptions = ConnectionOptions & BaseComponentOptions;
export declare class BaseConnection<EventTypes extends EventEmitter.ValidEventTypes = BaseConnectionEvents> extends BaseComponent<EventTypes> implements Rooms.BaseRoomInterface<EventTypes>, BaseConnectionContract<EventTypes> {
direction: 'inbound' | 'outbound';
options: BaseConnectionOptions;
/** @internal */
leaveReason: BaseConnectionContract<EventTypes>['leaveReason'];
/** @internal */
cause: string;
/** @internal */
causeCode: string;
/** @internal */
gotEarly: boolean;
private state;
private prevState;
private activeRTCPeerId;
private rtcPeerMap;
private sessionAuthTask;
protected resuming: boolean;
constructor(options: BaseConnectionOptions);
get id(): string;
get active(): boolean;
get trying(): boolean;
get memberId(): any;
get previewUrl(): any;
get roomId(): any;
get roomSessionId(): any;
get nodeId(): any;
get callId(): string;
get localStream(): MediaStream | undefined;
set localStream(stream: MediaStream | undefined);
get remoteStream(): MediaStream | undefined;
get iceServers(): RTCIceServer[];
get component(): ReduxComponent;
get cameraId(): string | null;
get cameraLabel(): string | null;
get microphoneId(): string | null;
get microphoneLabel(): string | null;
get withAudio(): boolean;
get withVideo(): boolean;
get localAudioTrack(): MediaStreamTrack | null;
get localVideoTrack(): MediaStreamTrack | null;
get peer(): RTCPeer<EventTypes> | undefined;
set peer(rtcPeer: RTCPeer<EventTypes> | undefined);
emit<E extends EventEmitter.EventNames<BaseConnectionEvents>>(event: E, ...args: EventEmitter.EventArgs<BaseConnectionEvents, E>): boolean;
emit<E extends EventEmitter.EventNames<EventTypes>>(event: E, ...args: EventEmitter.EventArgs<EventTypes, E>): boolean;
/** @internal */
dialogParams(rtcPeerId: string): {
dialogParams: {
id: string;
destinationNumber: string | undefined;
attach: boolean | undefined;
reattaching: boolean | undefined;
callerName: string | undefined;
callerNumber: string | undefined;
remoteCallerName: string | undefined;
remoteCallerNumber: string | undefined;
userVariables: {
[key: string]: any;
} | undefined;
screenShare: boolean | undefined;
additionalDevice: boolean | undefined;
pingSupported: boolean;
version: number;
};
};
getRTCPeerById(rtcPeerId: string): RTCPeer<EventTypes> | undefined;
appendRTCPeer(rtcPeer: RTCPeer<EventTypes>): Map<string, RTCPeer<EventTypes>>;
setActiveRTCPeer(rtcPeerId: string): void;
setLocalStream(stream: MediaStream): Promise<MediaStream>;
/**
* Verto messages have to be wrapped into an execute
* request and sent using the proper RPC WebRTCMethod.
*/
private vertoExecute;
/** @internal */
_getRPCMethod(): WebRTCMethod;
/** @internal */
_triggerNewRTCPeer(): Promise<void>;
updateCamera(constraints: MediaTrackConstraints): Promise<void>;
updateMicrophone(constraints: MediaTrackConstraints): Promise<void>;
/**
* Determines the appropriate {@link RTCRtpTransceiverDirection} based on current audio/video
* and negotiation options. The returned direction tells the peer connection
* whether to send, receive, both, or remain inactive for the given media kind.
*/
private _getTransceiverDirection;
/**
* Adjusts senders based on the given audio/video constraints. If a constraint is set to false,
* it stops the corresponding outbound track. Returns true if at least one sender is active,
* otherwise false.
*/
private manageSendersWithConstraints;
/**
* Attempts to obtain a new media stream that matches the given constraints, using a recursive
* strategy. If the new constraints fail, it tries to restore the old constraints.
* Returns a Promise that resolves to the new MediaStream or resolves without a stream if
* constraints were fully disabled. Rejects on unrecoverable errors.
*/
private updateConstraints;
/**
* Updates local tracks and transceivers from the given stream.
* For each new track, it adds/updates a transceiver and emits updated device events.
*/
private updateStream;
/**
* Finds or creates a transceiver for the new track. If an existing transceiver is found,
* replaces its track and updates its direction, if needed. If no transceiver is found,
* adds a new one. The method can trigger renegotiation.
*/
private handleTransceiverForTrack;
/**
* Replaces old tracks of the same kind in the local stream with the new track.
* Stops and removes the old track, then adds the new one. Also updates related
* device options and reattaches track listeners.
*/
private replaceOldTrack;
/**
* Emits device updated events for audio or video. Uses previously stored
* track references to indicate what changed between old and new devices.
*/
private emitDeviceUpdatedEvents;
/**
* Applies the given constraints by retrieving a new stream and then uses
* {@link updateStream} to synchronize local tracks with that new stream.
*/
private applyConstraintsAndRefreshStream;
runRTCPeerWorkers(rtcPeerId: string): void;
/** @internal */
invite<T>(): Promise<T>;
/** @internal */
answer<T>(): Promise<T>;
/** @internal */
onLocalSDPReady(rtcPeer: RTCPeer<EventTypes>): void | Promise<void>;
/** @internal */
_closeWSConnection(): void;
private _watchSessionAuth;
/** @internal */
resume(): Promise<void>;
/**
* Send the `verto.invite` only if the state is either `new` or `requesting`
* - new: the first time we send out the offer.
* - requesting: we received a redirectDestination so need to send it again
* specifying nodeId.
*
*/
private executeInvite;
/**
* Send the `verto.answer` only if the state is `new`
* - new: the first time we send out the answer.
*/
private executeAnswer;
/**
* Send the `verto.modify` when it's an offer and remote is already present
* It helps in renegotiation.
*/
private executeUpdateMedia;
hangup(id?: string): Promise<void>;
hangupAll(): Promise<void>;
sendDigits(dtmf: string): Promise<void>;
/** @internal */
doReinviteWithRelayOnly(): void;
/** @internal */
stopOutboundAudio(): void;
/** @internal */
restoreOutboundAudio(): void;
/** @internal */
stopOutboundVideo(): void;
/** @internal */
restoreOutboundVideo(): void;
/** @internal */
setState(state: BaseConnectionState): void;
/** @internal */
updateMediaOptions(options: UpdateMediaOptionsParams): void;
/** @internal */
onVertoBye: (params: OnVertoByeParams) => void;
/**
* Allow to define logic to munge the SDP
*
* @internal
* */
private _mungeSDP;
/**
* Always use VIDEO_CONSTRAINTS if video: true
* Always use AUDIO_CONSTRAINTS (or the SS one) if audio: true
*
* @internal
*/
private _checkDefaultMediaConstraints;
private _initPeer;
private _buildPeer;
/** @internal */
protected _finalize(): void;
/**
* Add or update the transceiver based on the media type and direction
*/
private _upsertTransceiverByKind;
/**
* Allow user to upgrade/downgrade media in a call.
* This performs RTC Peer renegotiation.
*
* @param params: {@link UpdateMediaParams}
*/
updateMedia(params: UpdateMediaParams): Promise<void>;
/**
* Allow user to set the audio direction on the RTC Peer.
* This performs RTC Peer renegotiation.
*
* @param direction {@link UpdateMediaDirection}
*/
setAudioDirection(direction: UpdateMediaDirection): Promise<void>;
/**
* Allow user to set the video direction on the RTC Peer.
* This performs RTC Peer renegotiation.
*
* @param direction {@link UpdateMediaDirection}
*/
setVideoDirection(direction: UpdateMediaDirection): Promise<void>;
hold(): Promise<void>;
unhold(): Promise<void>;
}
//# sourceMappingURL=BaseConnection.d.ts.map