@inlivedev/inlive-js-sdk
Version:
InLive JavaScript SDK
1,590 lines (1,518 loc) • 48.1 kB
TypeScript
type ICEServers = {
/**
* - The server URL
*/
urls: string;
/**
* - The username that will be used to connect with the server
*/
username?: string | undefined;
/**
* - The credential that will be used to connect with the server
*/
credential?: string | undefined;
};
type WebRTC = {
/**
* - ICE servers used to allow connection with the peers
*/
iceServers?: ICEServers[] | undefined;
};
/**
* @typedef ICEServers
* @property {string} urls - The server URL
* @property {string} [username] - The username that will be used to connect with the server
* @property {string} [credential] - The credential that will be used to connect with the server
*/
/**
* @typedef WebRTC
* @property {Array<ICEServers>} [iceServers] - ICE servers used to allow connection with the peers
*/
/**
* @type {WebRTC} - The webrtc configuration
*/
declare const webrtc$1: WebRTC;
type API = {
/**
* - The inLive API base URL
*/
baseUrl?: string | undefined;
/**
* - The version of the API
*/
version?: string | undefined;
};
/**
* @typedef API
* @property {string} [baseUrl] - The inLive API base URL
* @property {string} [version] - The version of the API
*/
/**
* @type {API} - The API configuration
*/
declare const api$1: API;
/**
* A function to create object
*
* @param {typeof defaultConfig} config -- being passed from init module parameter
*/
declare function InitializationInstance(config: typeof defaultConfig): void;
declare class InitializationInstance {
/**
* A function to create object
*
* @param {typeof defaultConfig} config -- being passed from init module parameter
*/
constructor(config: typeof defaultConfig);
config: {
apiKey: string;
api: API;
webrtc: WebRTC;
};
}
type Config = {
/**
* - A string key for API authentication
*/
apiKey: string;
/**
* - config for API
*/
api?: API | undefined;
/**
* - config for WebRTC
*/
webrtc?: WebRTC | undefined;
};
declare namespace defaultConfig {
export let apiKey: string;
export { api$1 as api };
export { webrtc$1 as webrtc };
}
/**
* Initialize an initialization instance
*
* @function
* @param {Config} config - A set of key/value parameter configuration
* @returns {InitializationInstance} InitializationInstance that contains config object of apiKey
* @throws {Error}
*/
declare function init(config: Config): InitializationInstance;
declare const modules$1_init: typeof init;
declare namespace modules$1 {
export { modules$1_init as init };
}
declare const RoomEvent: Readonly<{
CHANNEL_OPENED: "channelOpened";
CHANNEL_CLOSED: "channelClosed";
PEER_OPENED: "peerOpened";
PEER_CLOSED: "peerClosed";
STREAM_AVAILABLE: "streamAvailable";
STREAM_REMOVED: "streamRemoved";
META_CHANGED: "metaChanged";
}>;
type StreamResponse$1 = {
/**
* - id of stream
*/
id: number;
/**
* - name of stream
*/
name: string;
/**
* - slug or URL friendly name
*/
slug: string;
/**
* - description for the stream
*/
description: string;
/**
* - HLS manifest URL
*/
hlsUrl: string;
/**
* - a Dash format URL
*/
dashUrl: string;
/**
* - a time string when the stream is created
*/
createdAt: string;
/**
* - a time string when the stream is updated
*/
updatedAt: string;
/**
* - a time string when the stream is prepared
*/
preparedAt: string;
/**
* - a time string when the stream is started
*/
startedAt: string;
/**
* - a time string when the stream is ended
*/
endedAt: string;
/**
* - the ID of the user who creates the stream
*/
createdBy: string;
/**
* - the ID of the user who updates the stream
*/
updatedBy: string | null;
/**
* - the quality of the stream
*/
quality: string;
};
/**
* a stream object that will hold all stream states
*
* @module Stream
*/
/**
* @typedef {import('../app/init/init.js').InitializationInstance} App
*/
/**
* @typedef {import('./fetch-stream/fetch-stream.js').StreamResponse} StreamResponse
*/
/**
* @typedef Manifests
* @property {string} hls - hls master playlist
* @property {string} dash - dash manifest
*/
declare class Stream {
static READY: string;
static STARTED: string;
static ENDED: string;
static ERROR: string;
static ICECANDIDATE: string;
static STATECHANGED: string;
static STATE_NEW: string;
static STATE_CONNECTING: string;
static STATE_CONNECTED: string;
static STATE_COMPLETED: string;
static STATE_DISCONNECTED: string;
static STATE_READY: string;
static STATE_LIVE: string;
static STATE_FAILED: string;
static STATE_ENDED: string;
/**
* Stream constructor.
*
* @param {App} app - The app instance with configurations.
* @param {StreamResponse} streamResponse - The stream response from the stream API endpoint.
*/
constructor(app: App, streamResponse: StreamResponse);
/**
* The app instance with configurations.
*
* @type {App}
* @public
*/
public app: App;
/**
* The stream ID.
*
* @type {number}
* @public
*/
public id: number;
/**
* The stream ID.
*
* @type {string}
* @public
*/
public state: string;
/**
* The stream name.
*
* @type {string}
* @public
*/
public name: string;
/**
* The stream data from the stream API endpoint.
*
* @public
* @type {StreamResponse}
*/
public data: StreamResponse;
/**
* The video and audio tracks for live streaming.
*
* @type {MediaStream|null}
* @public
*/
public mediaStream: MediaStream | null;
/**
* The RTCPeerConnection object for WebRTC connection
*
* @type {RTCPeerConnection|null}
* @public
*/
public peerConnection: RTCPeerConnection | null;
/**
* The eventHandler map object streaming event
*
* @type {Object<string, Function[]>}
* @public
*/
public eventHandlers: {
[x: string]: Function[];
};
/**
* The eventHandler map object streaming event
*
* @type {Manifests}
* @public
*/
public manifests: Manifests;
/**
* The pending ice candidates that can't be added because the remote SDP is not received yet
*
* @type {Array.<RTCIceCandidate>}
* @private
*/
private pandingIceCandidates;
/**
* Get the base URL of API endpoint
*
* @returns {string} baseURL - return string of API base URL with its version
*/
getAPIUrl(): string;
/**
* Subscribe to events
*/
subscribe(): Promise<void>;
/**
* Set event listeners and event dispatchers
*
* @param {EventSource} events - event source instance
*/
setEventHandlers(events: EventSource): Promise<void>;
/**
* Add ice candidate from remote peer connection
*
* @param {RTCIceCandidate} iceCandidate - ice candidate from remote peer connection
*/
addIceCandidate(iceCandidate: RTCIceCandidate): void;
/**
* Dispatch event to added event handlers
*
* @param {string} eventName - Name of event to dispatch
* @param {object }data - Data to pass into event handler
*/
dispatchEvent(eventName: string, data: object): void;
/**
* @callback eventHandler
* @param {any} data - Data to pass into event handler
*/
/**
* Add event handler to specific event
*
* @param {string} eventName - Name of event to listen
* @param {eventHandler} handlerFunction - function to handle the event
*/
on(eventName: string, handlerFunction: (data: any) => any): void;
/**
*
* @param {string} newState - new state of the stream
*/
changeState(newState: string): void;
/**
* listen to RTCPeerConnection event changes
*/
listenForWebRTCEvent(): void;
/**
* Adding pending ice candidates after set remote local description
*
* @private
*/
/**
*
*/
addPendingIceCandidates(): void;
/**
* Initiate the stream for live streaming
*
* @param {MediaStream} mediaStream - The video and audio stream tracks for going live
* @returns {Promise<boolean>} Promise object represent true value if initialization is complete
* @todo need to refactor because sometimes the ice event arrive before the answer is added. Maybe need to wait the answer first but make sure we're not lost all the ice candidates.
*/
init(mediaStream: MediaStream): Promise<boolean>;
/**
*
* @param {RTCIceCandidate} iceCandidate - ice candidate to send to remote RTCPeerConnection
*/
sendIceCandidate(iceCandidate: RTCIceCandidate): Promise<void>;
/**
* Subscribe to events and prepare the stream server for going live.
*/
prepare(): Promise<void>;
/**
* Start the live streaming
*/
live(): Promise<void>;
/**
* End the live streaming
*/
end(): Promise<void>;
}
type App = InitializationInstance;
type StreamResponse = StreamResponse$1;
type Manifests = {
/**
* - hls master playlist
*/
hls: string;
/**
* - dash manifest
*/
dash: string;
};
declare function createStream$1(initObject: InitializationInstance, parameters: Parameters$1): Promise<Stream>;
type Parameters$1 = {
/**
* -- name of stream
*/
name: string;
/**
* -- slug of stream
*/
slug?: string | undefined;
/**
* -- description of stream
*/
description?: string | undefined;
};
/**
* End and stop a stream
*
* @param {InitializationInstance} initInstance - The initialization instance received from the init() function
* @param {number} streamId - the stream ID to end
* @returns {Promise<boolean>} - return true if no error
*/
declare function endStream(initInstance: InitializationInstance, streamId: number): Promise<boolean>;
declare function getStreams(initInstance: InitializationInstance, parameters?: PaginationParameters | undefined): Promise<StreamListResponse>;
type StreamData = {
/**
* - id of stream
*/
id: number;
/**
* - name of stream
*/
name: string;
/**
* - slug or URL friendly name
*/
slug: string;
/**
* - description for the stream
*/
description: string;
/**
* - HLS manifest URL
*/
hlsUrl: string;
/**
* - a Dash format URL
*/
dashUrl: string;
/**
* - a time string when the stream is created
*/
createdAt: string;
/**
* - a time string when the stream is updated
*/
updatedAt: string;
/**
* - a time string when the stream is prepared
*/
preparedAt: string;
/**
* - a time string when the stream is started
*/
startedAt: string;
/**
* - a time string when the stream is ended
*/
endedAt: string;
/**
* - the ID of the user who creates the stream
*/
createdBy: string;
/**
* - the ID of the user who updates the stream
*/
updatedBy: string | null;
/**
* - the quality of the stream
*/
quality: string;
};
type MetaData = {
/**
* - current page
*/
page: number;
/**
* - page size limit in one page
*/
limit: number;
/**
* - total number of stream records
*/
totalRecords: number;
/**
* - total number of pages
*/
totalPages: number;
};
type StreamListResponse = {
/**
* -- A status code
*/
code: number;
/**
* -- A status message
*/
message: string;
/**
* -- list of streams data in array
*/
data: Array<StreamData>;
/**
* - A meta data
*/
meta: MetaData;
};
type PaginationParameters = {
/**
* - the page number will be displayed (default: 1)
*/
page?: number | undefined;
/**
* - the total number of streams displayed on one page (default: 10)
*/
pageSize?: number | undefined;
};
declare function getStream(initObject: InitializationInstance, streamId: number): Promise<Stream>;
declare namespace media$1 {
export { getUserMedia };
}
/**
* Capture the MediaStream and return Media instance
*
* @param {MediaStreamConstraints} mediaConstraints - The media stream constraints
* @returns {Promise<Media>} - Return a promise resolve to Media instance
*/
declare function getUserMedia(mediaConstraints?: MediaStreamConstraints): Promise<Media>;
declare class Media {
/**
*
* @param {MediaStream} localStream - a media stream from getUserMedia()
*/
constructor(localStream: MediaStream);
/**
* The media stream
*
* @type {MediaStream}
* @public
*/
public stream: MediaStream;
/**
* Attach media stream to video element
*
* @param {HTMLVideoElement} videoElement - a video element to attach the media stream
*/
attachTo(videoElement: HTMLVideoElement): void;
}
type Parameters = {
/**
* - The ID of the stream
*/
streamId: number;
/**
* - The werbtc local session description
*/
sessionDescription: RTCSessionDescription | null;
};
/**
* @typedef Parameters
* @property {number} streamId - The ID of the stream
* @property {RTCSessionDescription | null} sessionDescription - The werbtc local session description
*/
/**
* initialize a stream session
*
* @param {InitializationInstance} initInstance - The initialization instance received from the init() function
* @param {Parameters} parameters - Key / value configuration
*/
declare function initStream(initInstance: InitializationInstance, parameters: Parameters): Promise<{
status: {
code: any;
type: string;
message: string;
};
data: {
sdp: any;
type: any;
};
}>;
/**
* Prepare a stream session
*
* @param {InitializationInstance} initInstance - The initialization instance received from the init() function
* @param {number} streamID - the stream ID
* @returns {Promise<boolean>} status - Promise object that will resolve the stream
*/
declare function prepareStream(initInstance: InitializationInstance, streamID: number): Promise<boolean>;
/**
* Start a stream
*
* @param {InitializationInstance} initInstance - The initialization instance received from the init() function
* @param {number} streamID - the stream ID
* @returns {Promise<import('../stream.js').Manifests>} - return true if no error
*/
declare function startStream(initInstance: InitializationInstance, streamID: number): Promise<Manifests>;
declare namespace Stat {
let CLIENT_STAT: string;
let FFMPEG_STAT: string;
let WEBRTC_STAT: string;
}
declare function track(streamID: number, data: trackEvent, apiOptions?: API | undefined): Promise<void>;
declare function getStatsLogs(initInstance: InitializationInstance, streamID: number, options?: {
page: number;
pageSize: number;
}): Promise<FetchResponse>;
declare function getStatsRealtime(initInstance: InitializationInstance, streamID: number): Promise<EventSource>;
type FetchStatus = {
/**
* - status code
*/
code: number;
/**
* - status message
*/
message: string;
/**
* - status type
*/
type: string;
};
type FetchResponse = {
/**
* -- A status response
*/
status: FetchStatus;
/**
* -- A return data as per endpoint
*/
data: Array<any>;
};
type trackEvent = {
/**
* - unique identifier of the client, should be store in cookie or local storage to make it persistence
*/
clientID: string;
/**
* - elapsed time in seconds
*/
elapsedTimeInSeconds: number;
/**
* - unix epoch time
*/
clientTimeInUnixMillis: number;
/**
* - event name
*/
name: string;
/**
* - event object
*/
data: object;
};
declare const modules_endStream: typeof endStream;
declare const modules_getStatsLogs: typeof getStatsLogs;
declare const modules_getStatsRealtime: typeof getStatsRealtime;
declare const modules_getStream: typeof getStream;
declare const modules_getStreams: typeof getStreams;
declare const modules_initStream: typeof initStream;
declare const modules_prepareStream: typeof prepareStream;
declare const modules_startStream: typeof startStream;
declare const modules_track: typeof track;
declare namespace modules {
export { createStream$1 as createStream, modules_endStream as endStream, modules_getStatsLogs as getStatsLogs, modules_getStatsRealtime as getStatsRealtime, modules_getStream as getStream, modules_getStreams as getStreams, modules_initStream as initStream, media$1 as media, modules_prepareStream as prepareStream, modules_startStream as startStream, modules_track as track };
}
declare function createFetcher(): {
/**
* @param {string} baseUrl
*/
createInstance: (baseUrl: string) => {
getBaseUrl: () => string;
get: (endpoint: string, options?: RequestInit | undefined) => Promise<any>;
post: (endpoint: string, options?: RequestInit | undefined) => Promise<any>;
put: (endpoint: string, options?: RequestInit | undefined) => Promise<any>;
patch: (endpoint: string, options?: RequestInit | undefined) => Promise<any>;
delete: (endpoint: string, options?: RequestInit | undefined) => Promise<any>;
};
};
declare function createApi({ fetcher, config }: RoomAPIType.ApiDependencies): {
createInstance: () => {
createRoom: (name?: string | undefined, id?: string | undefined, options?: {
bitrates?: {
audioRed?: number | undefined;
audio?: number | undefined;
video?: number | undefined;
videoHigh?: number | undefined;
videoHighPixels?: number | undefined;
videoMid?: number | undefined;
videoMidPixels?: number | undefined;
videoLow?: number | undefined;
videoLowPixels?: number | undefined;
initialBandwidth?: number | undefined;
} | undefined;
codecs?: string[] | undefined;
emptyRoomTimeoutMS?: number | undefined;
pliIntervalMS?: number | undefined;
qualityPresets?: {
high?: {
sid?: number | undefined;
tid?: number | undefined;
} | undefined;
low?: {
sid?: number | undefined;
tid?: number | undefined;
} | undefined;
mid?: {
sid?: number | undefined;
tid?: number | undefined;
} | undefined;
} | undefined;
} | undefined) => Promise<RoomAPIType.RoomReturnBody>;
getRoom: (roomId: string) => Promise<RoomAPIType.RoomReturnBody>;
registerClient: (roomId: string, config?: {
clientId?: string | undefined;
clientName?: string | undefined;
enableVAD?: boolean | undefined;
} | undefined) => Promise<RoomAPIType.RegisterClientReturn>;
getClient: (roomId: string, clientId: string) => Promise<{
url: string;
headers: Headers;
code: number;
ok: boolean;
message: string;
data: {
clientId: string;
clientName: string;
connectionState: RTCPeerConnectionState;
iceConnectionState: RTCIceConnectionState;
events: {
[key: string]: {
name: string;
timestamp: number;
data: {
[key: string]: string | null;
};
};
};
};
}>;
setClientName: (roomId: string, clientId: string, clientName: string) => Promise<{
url: string;
headers: Headers;
code: number;
ok: boolean;
message: string;
data: {
clientId: string;
clientName: string;
bitrates: {
audio: number;
audioRed: number;
video: number;
videoHigh: number;
videoHighPixels: number;
videoMid: number;
videoMidPixels: number;
videoLow: number;
videoLowPixels: number;
initialBandwidth: number;
};
};
}>;
getMetadata: (roomId: string, key: string) => Promise<{
url: string;
headers: Headers;
code: number;
ok: boolean;
message: string;
data: any;
}>;
setMetadata: (roomId: string, metadata: {
[key: string]: any;
}) => Promise<{
url: string;
headers: Headers;
code: number;
ok: boolean;
message: string;
data: null;
}>;
deleteMetadata: (roomId: string, key: string) => Promise<{
url: string;
headers: Headers;
code: number;
ok: boolean;
message: string;
data: null;
}>;
sendIceCandidate: (roomId: string, clientId: string, candidate: RTCIceCandidate) => Promise<{
url: string;
headers: Headers;
code: number;
ok: boolean;
message: string;
data: null;
}>;
checkNegotiateAllowed: (roomId: string, clientId: string) => Promise<{
url: string;
headers: Headers;
code: number;
ok: boolean;
message: string;
data: null;
}>;
negotiateConnection: (roomId: string, clientId: string, localDescription: RTCSessionDescription) => Promise<{
url: string;
headers: Headers;
code: number;
ok: boolean;
message: string;
data: {
answer: RTCSessionDescription;
};
}>;
setTrackSources: (roomId: string, clientId: string, trackSources: RoomAPIType.TrackSourcesRequestBody[]) => Promise<{
url: string;
headers: Headers;
code: number;
ok: boolean;
message: string;
data: null;
}>;
subscribeTracks: (roomId: string, clientId: string, subscribeTracks: RoomAPIType.SubscribeTracksRequestBody[]) => Promise<{
url: string;
headers: Headers;
code: number;
ok: boolean;
message: string;
data: null;
}>;
leaveRoom: (roomId: string, clientId: string, useBeacon?: boolean) => Promise<{
code: number;
ok: boolean;
message: string;
data: null;
}>;
endRoom: (roomId: string) => Promise<RoomAPIType.BaseResponseReturn>;
createDataChannel: (roomId: string, name: string, ordered?: boolean) => Promise<{
url: string;
headers: Headers;
code: number;
ok: boolean;
message: string;
data: null;
}>;
setAuth: (auth: {
url: string;
data: {
expirySeconds: number;
accessToken: string;
refreshToken: string;
};
}) => {
baseUrl: string;
apiVersion: string;
accessToken: string;
refreshToken: string;
expirySeconds: number;
};
};
};
declare namespace SharedType {
type ObjectLiteral = {
[key: string]: any
}
type DeepPartial<Thing> = Thing extends any[]
? Thing
: { [Key in keyof Thing]?: DeepPartial<Thing[Key]> }
}
declare namespace api {
let baseUrl: string;
let version: string;
let apiKey: string;
}
declare namespace webrtc {
let iceServers: {
urls: string;
username: string;
credential: string;
}[];
}
declare namespace media {
namespace webcam {
let maxFramerate: number;
let videoCodecs: string[];
let simulcast: boolean;
let svc: boolean;
let scalabilityMode: string;
namespace bitrates {
let high: number;
let mid: number;
let low: number;
}
}
namespace screen {
let maxFramerate_1: number;
export { maxFramerate_1 as maxFramerate };
let videoCodecs_1: string[];
export { videoCodecs_1 as videoCodecs };
let simulcast_1: boolean;
export { simulcast_1 as simulcast };
let svc_1: boolean;
export { svc_1 as svc };
let scalabilityMode_1: string;
export { scalabilityMode_1 as scalabilityMode };
export namespace bitrates_1 {
let high_1: number;
export { high_1 as high };
let mid_1: number;
export { mid_1 as mid };
let low_1: number;
export { low_1 as low };
}
export { bitrates_1 as bitrates };
}
namespace microphone {
let audioCodecs: string[];
}
}
declare namespace RoomType {
type Config = {
api: typeof api
webrtc: typeof webrtc
media: typeof media
}
type UserConfig = {
api?: SharedType.DeepPartial<typeof api>
webrtc?: SharedType.DeepPartial<typeof webrtc>
media?: SharedType.DeepPartial<typeof media>
}
}
declare namespace RoomAPIType {
type CreateFetcher = typeof createFetcher
type CreateApi = typeof createApi
type InstanceFetcher = ReturnType<ReturnType<CreateFetcher>['createInstance']>
type InstanceApi = ReturnType<ReturnType<CreateApi>['createInstance']>
type ApiDependencies = {
fetcher: InstanceFetcher
config: RoomType.Config
}
type TrackSourcesRequestBody = {
track_id: string
source: string
}
type SubscribeTracksRequestBody = {
client_id: string
stream_id: string
track_id: string
}
type RegisterClientRequestBody = {
uid?: string
name?: string
enable_vad?: boolean
}
type BitratesCamelCase = {
audioRed: number
audio: number
video: number
videoHigh: number
videoHighPixels: number
videoMid: number
videoMidPixels: number
videoLow: number
videoLowPixels: number
initialBandwidth: number
}
type BitratesSnakeCase = {
audio: number
audio_red: number
video: number
video_high: number
video_high_pixels: number
video_mid: number
video_mid_pixels: number
video_low: number
video_low_pixels: number
initial_bandwidth: number
}
type QualityPreset = {
sid: number
tid: number
}
type QualityPresets = {
high: QualityPreset
low: QualityPreset
mid: QualityPreset
}
type RoomOptions = {
bitrates: BitratesCamelCase
codecs: string[]
emptyRoomTimeoutMS: number
pliIntervalMS: number
qualityPresets: QualityPresets
}
type RoomUserOptions = SharedType.DeepPartial<RoomOptions>
type RoomResponse = {
id: string
name: string
options: {
bitrates: BitratesSnakeCase
codecs: string[]
empty_room_timeout_ns: number
pli_interval_ns: number
quality_presets: QualityPresets
}
}
type BaseResponseBody = {
url: string
headers: Headers
code: number
ok: boolean
message: string
}
type BaseResponseReturn = BaseResponseBody & {
data: null
}
type RoomResponseBody = BaseResponseBody & {
data: RoomResponse
}
type Room = {
id: string
name: string
options: RoomOptions
}
type RoomReturnBody = BaseResponseBody & {
data: Room
}
type RegisterClientResponseBody = BaseResponseBody & {
data: {
client_id: string
name: string
bitrates: BitratesSnakeCase
}
}
type RegisterClientReturn = BaseResponseBody & {
data: {
clientId: string
clientName: string
bitrates: BitratesCamelCase
}
}
type GetClientResponseBody = BaseResponseBody & {
data: {
id: string
name: string
peer_connection_state: RTCPeerConnectionState
ice_peer_connection_state: RTCIceConnectionState
events: {
[key: string]: {
name: string
timestamp: number
data: { [key: string]: string | null }
}
}
}
}
type SetClientNameResponse = BaseResponseBody & {
data: {
client_id: string
name: string
bitrates: BitratesSnakeCase
}
}
type GetMetadataResponse = BaseResponseBody & {
data: any
}
type NegotiateConnectionResponseBody = BaseResponseBody & {
data: {
answer: RTCSessionDescription
}
}
type ApiAuth = {
baseUrl: string
apiVersion: string
expirySeconds: number
accessToken: string
refreshToken: string
}
}
declare function createEvent(): {
createInstance: () => {
emit: (eventName: string, value?: any) => void;
on: (eventName: string, callback: (data: any) => void) => void;
addEventListener: (eventName: string, callback: (data: any) => void) => void;
removeEventListener: (eventName: string, callback: (data: any) => void) => void;
};
};
declare namespace RoomEventType {
type CreateEvent = typeof createEvent
type InstanceEvent = ReturnType<ReturnType<CreateEvent>['createInstance']>
type EventHandlers = Set<(data: SharedType.ObjectLiteral) => void>
type EventItems = {
[key: string]: EventHandlers
}
}
declare function createStream(): {
/**
* @param {import('./stream-types.js').RoomStreamType.StreamParameters} data
*/
createInstance: (data: RoomStreamType.StreamParameters) => {
id: string;
clientId: string;
name: string;
origin: string;
source: string;
mediaStream: MediaStream;
audioLevel: number;
lastVoiceActivity: number;
/**
* @param {MediaStreamTrack} newTrack
*/
replaceTrack: (newTrack: MediaStreamTrack) => void;
/**
* @param {import('../peer/peer-types.d.ts').RoomPeerType.VoiceActivity} activity
* @returns {void}
*/
addVoiceActivity: (activity: RoomPeerType.VoiceActivity) => void;
/**
* @param audioLevel {number}
* @returns {void}
*/
"__#3@#triggerVoiceActivityEvent": (audioLevel: number) => void;
addEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: boolean | AddEventListenerOptions | undefined): void;
dispatchEvent(event: Event): boolean;
removeEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: boolean | EventListenerOptions | undefined): void;
};
};
declare function createStreams(): {
createInstance: () => {
addStream: (key: string, stream: RoomStreamType.InstanceStream) => RoomStreamType.InstanceStream;
removeStream: (key: string) => RoomStreamType.InstanceStream | null;
getAllStreams: () => {
id: string;
clientId: string;
name: string; /**
* To trigger the type safety
* @augments {Map<string, import('./stream-types.js').RoomStreamType.InstanceStream>}
*/
origin: string;
source: string;
mediaStream: MediaStream;
audioLevel: number;
lastVoiceActivity: number;
replaceTrack: (newTrack: MediaStreamTrack) => void;
addVoiceActivity: (activity: RoomPeerType.VoiceActivity) => void;
"__#3@#triggerVoiceActivityEvent": (audioLevel: number) => void;
addEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: boolean | AddEventListenerOptions | undefined): void;
dispatchEvent(event: Event): boolean;
removeEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: boolean | EventListenerOptions | undefined): void;
}[];
getStream: (key: string) => RoomStreamType.InstanceStream | null;
getStreamByTrackId: (trackId: string) => RoomStreamType.InstanceStream | null;
getTotalStreams: () => number;
hasStream: (key: string) => boolean;
addDraft: (key: string, value?: RoomStreamType.DraftStream) => void;
getDraft: (key: string) => RoomStreamType.DraftStream | null;
removeDraft: (key: string) => boolean;
validateKey: (key: string) => boolean;
validateStream: (data: RoomStreamType.DraftStream) => boolean;
};
};
declare namespace RoomStreamType {
export type CreateStream = typeof createStream
export type CreateStreams = typeof createStreams
export type InstanceStream = ReturnType<
ReturnType<CreateStream>['createInstance']
>
export type InstanceStreams = ReturnType<
ReturnType<CreateStreams>['createInstance']
>
export type StreamParameters = {
id: string
clientId: string
name: string
origin: 'local' | 'remote' | string
source: 'media' | 'screen' | string
mediaStream: MediaStream
}
export type AddStreamParameters = Omit<StreamParameters, 'id'>
export type DraftStream = {
clientId?: string
name?: string
origin?: 'local' | 'remote' | string
source?: 'media' | 'screen' | string
mediaStream?: MediaStream | undefined
}
}
declare function createPeer({ api, createStream, event, streams, config }: RoomPeerType.PeerDependencies): {
createInstance: () => {
connect: (roomId: string, clientId: string) => Promise<void>;
disconnect: () => void;
getClientId: () => string;
getRoom: () => Promise<RoomAPIType.RoomReturnBody>;
getRoomId: () => string;
getPeerConnection: () => Readonly<RTCPeerConnection | null>;
addStream: (key: string, data: RoomStreamType.AddStreamParameters) => void;
addIceCandidate: (candidate: RTCIceCandidate) => Promise<void>;
removeStream: (key: string) => RoomStreamType.InstanceStream | null;
getAllStreams: () => RoomStreamType.InstanceStream[];
getStream: (key: string) => RoomStreamType.InstanceStream | null;
getStreamByTrackId: (trackId: string) => RoomStreamType.InstanceStream | null;
getTotalStreams: () => number;
hasStream: (key: string) => boolean;
turnOnCamera: (newTrack?: MediaStreamTrack | undefined) => Promise<void>;
turnOnMic: (newTrack?: MediaStreamTrack | undefined) => Promise<void>;
turnOffCamera: (stop?: boolean | undefined) => void;
turnOffMic: (stop?: boolean | undefined) => void;
replaceTrack: (oldTrack: MediaStreamTrack, newTrack: MediaStreamTrack) => Promise<void>;
observeVideo: (videoElement: HTMLVideoElement) => void;
updateVideoSize: (trackId: string, width: number, height: number) => void;
unobserveVideo: (videoElement: HTMLVideoElement) => void;
negotiate: () => Promise<void>;
startViewOnly: () => Promise<void>;
pendingNegotiation: boolean;
};
};
declare namespace RoomPeerType {
type CreatePeer = typeof createPeer
type InstancePeer = {
connect: (roomId: string, clientId: string) => void
disconnect: () => void
getClientId: () => string
getRoomId: () => string
getPeerConnection: () => RTCPeerConnection | null
addStream: (key: string, value: RoomStreamType.AddStreamParameters) => void
addIceCandidate: (candidate: RTCIceCandidate) => void
removeStream: (key: string) => RoomStreamType.InstanceStream | null
getAllStreams: () => RoomStreamType.InstanceStream[]
getStream: (key: string) => RoomStreamType.InstanceStream | null
getStreamByTrackId: (
trackId: string
) => RoomStreamType.InstanceStream | null
getTotalStreams: () => number
hasStream: (key: string) => boolean
turnOnCamera: () => void
turnOnMic: () => void
turnOffCamera: () => void
turnOffMic: () => void
replaceTrack: (
oldTrack: MediaStreamTrack,
newTrack: MediaStreamTrack
) => Promise<void>
observeVideo: (video: HTMLVideoElement) => void
unobserveVideo: (video: HTMLVideoElement) => void
negotiate: () => Promise<void>
pendingNegotiation: boolean
}
type PeerDependencies = {
api: RoomAPIType.InstanceApi
createStream: RoomStreamType.CreateStream
event: RoomEventType.InstanceEvent
streams: RoomStreamType.InstanceStreams
config: RoomType.Config
}
type RTCRtpSVCEncodingParameters = RTCRtpEncodingParameters & {
scalabilityMode?: string
}
type RTCRtpSVCTransceiverInit = RTCRtpTransceiverInit & {
sendEncodings?: RTCRtpSVCEncodingParameters[]
}
type AudioLevel = {
sequenceNo: number
timestamp: number
audioLevel: number
}
type VoiceActivity = {
type: string
trackID: string
streamID: string
ssrc: number
clockRate: number
audioLevels?: AudioLevel[]
}
type VoiceActivityCallback = (voiceActivity: VoiceActivity) => void
}
declare function createAuth(userConfig?: {
baseUrl?: string | undefined;
apiVersion?: string | undefined;
apiKey?: string | undefined;
expirySeconds?: number | undefined;
} | undefined): Promise<{
url: string;
headers: Headers;
code: number;
ok: boolean;
message: string;
data: {
expirySeconds: number;
accessToken: string;
refreshToken: string;
};
}>;
declare namespace REASONS {
let PEER_CLOSED: string;
let NOT_FOUND: string;
let RECONNECT: string;
let TIMEOUT: string;
}
declare function Room(userConfig?: RoomType.UserConfig | undefined): {
createRoom: (name?: string | undefined, id?: string | undefined, options?: {
bitrates?: {
audioRed?: number | undefined;
audio?: number | undefined;
video?: number | undefined;
videoHigh?: number | undefined;
videoHighPixels?: number | undefined;
videoMid?: number | undefined;
videoMidPixels?: number | undefined;
videoLow?: number | undefined;
videoLowPixels?: number | undefined;
initialBandwidth?: number | undefined;
} | undefined;
codecs?: string[] | undefined;
emptyRoomTimeoutMS?: number | undefined;
pliIntervalMS?: number | undefined;
qualityPresets?: {
high?: {
sid?: number | undefined;
tid?: number | undefined;
} | undefined;
low?: {
sid?: number | undefined;
tid?: number | undefined;
} | undefined;
mid?: {
sid?: number | undefined;
tid?: number | undefined;
} | undefined;
} | undefined;
} | undefined) => Promise<RoomAPIType.RoomReturnBody>;
getRoom: (roomId: string) => Promise<RoomAPIType.RoomReturnBody>;
createClient: (roomId: string, config?: {
clientId?: string | undefined;
clientName?: string | undefined;
enableVAD?: boolean | undefined;
} | undefined) => Promise<RoomAPIType.RegisterClientReturn>;
getClient: (roomId: string, clientId: string) => Promise<{
url: string;
headers: Headers;
code: number;
ok: boolean;
message: string;
data: {
clientId: string;
clientName: string;
connectionState: RTCPeerConnectionState;
iceConnectionState: RTCIceConnectionState;
events: {
[key: string]: {
name: string;
timestamp: number;
data: {
[key: string]: string | null;
};
};
};
};
}>;
setClientName: (roomId: string, clientId: string, clientName: string) => Promise<{
url: string;
headers: Headers;
code: number;
ok: boolean;
message: string;
data: {
clientId: string;
clientName: string;
bitrates: {
audio: number;
audioRed: number;
video: number;
videoHigh: number;
videoHighPixels: number;
videoMid: number;
videoMidPixels: number;
videoLow: number;
videoLowPixels: number;
initialBandwidth: number;
};
};
}>;
getMetadata: (roomId: string, key: string) => Promise<{
url: string;
headers: Headers;
code: number;
ok: boolean;
message: string;
data: any;
}>;
setMetadata: (roomId: string, metadata: {
[key: string]: any;
}) => Promise<{
url: string;
headers: Headers;
code: number;
ok: boolean;
message: string;
data: null;
}>;
deleteMetadata: (roomId: string, key: string) => Promise<{
url: string;
headers: Headers;
code: number;
ok: boolean;
message: string;
data: null;
}>;
createPeer: (roomId: string, clientId: string) => Promise<{
connect: (roomId: string, clientId: string) => Promise<void>;
disconnect: () => void;
getClientId: () => string;
getRoom: () => Promise<RoomAPIType.RoomReturnBody>;
getRoomId: () => string;
getPeerConnection: () => Readonly<RTCPeerConnection | null>;
addStream: (key: string, data: RoomStreamType.AddStreamParameters) => void;
addIceCandidate: (candidate: RTCIceCandidate) => Promise<void>;
removeStream: (key: string) => {
id: string;
clientId: string;
name: string;
origin: string;
source: string;
mediaStream: MediaStream;
audioLevel: number;
lastVoiceActivity: number;
replaceTrack: (newTrack: MediaStreamTrack) => void;
addVoiceActivity: (activity: RoomPeerType.VoiceActivity) => void;
"__#3@#triggerVoiceActivityEvent": (audioLevel: number) => void;
addEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: boolean | AddEventListenerOptions | undefined): void;
dispatchEvent(event: Event): boolean;
removeEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: boolean | EventListenerOptions | undefined): void;
} | null;
getAllStreams: () => {
id: string;
clientId: string;
name: string;
origin: string;
source: string;
mediaStream: MediaStream;
audioLevel: number;
lastVoiceActivity: number;
replaceTrack: (newTrack: MediaStreamTrack) => void;
addVoiceActivity: (activity: RoomPeerType.VoiceActivity) => void;
"__#3@#triggerVoiceActivityEvent": (audioLevel: number) => void;
addEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: boolean | AddEventListenerOptions | undefined): void;
dispatchEvent(event: Event): boolean;
removeEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: boolean | EventListenerOptions | undefined): void;
}[];
getStream: (key: string) => {
id: string;
clientId: string;
name: string;
origin: string;
source: string;
mediaStream: MediaStream;
audioLevel: number;
lastVoiceActivity: number;
replaceTrack: (newTrack: MediaStreamTrack) => void;
addVoiceActivity: (activity: RoomPeerType.VoiceActivity) => void;
"__#3@#triggerVoiceActivityEvent": (audioLevel: number) => void;
addEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: boolean | AddEventListenerOptions | undefined): void;
dispatchEvent(event: Event): boolean;
removeEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: boolean | EventListenerOptions | undefined): void;
} | null;
getStreamByTrackId: (trackId: string) => {
id: string;
clientId: string;
name: string;
origin: string;
source: string;
mediaStream: MediaStream;
audioLevel: number;
lastVoiceActivity: number;
replaceTrack: (newTrack: MediaStreamTrack) => void;
addVoiceActivity: (activity: RoomPeerType.VoiceActivity) => void;
"__#3@#triggerVoiceActivityEvent": (audioLevel: number) => void;
addEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: boolean | AddEventListenerOptions | undefined): void;
dispatchEvent(event: Event): boolean;
removeEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: boolean | EventListenerOptions | undefined): void;
} | null;
getTotalStreams: () => number;
hasStream: (key: string) => boolean;
turnOnCamera: (newTrack?: MediaStreamTrack | undefined) => Promise<void>;
turnOnMic: (newTrack?: MediaStreamTrack | undefined) => Promise<void>;
turnOffCamera: (stop?: boolean | undefined) => void;
turnOffMic: (stop?: boolean | undefined) => void;
replaceTrack: (oldTrack: MediaStreamTrack, newTrack: MediaStreamTrack) => Promise<void>;
observeVideo: (videoElement: HTMLVideoElement) => void;
updateVideoSize: (trackId: string, width: number, height: number) => void;
unobserveVideo: (videoElement: HTMLVideoElement) => void;
negotiate: () => Promise<void>;
startViewOnly: () => Promise<void>;
pendingNegotiation: boolean;
}>;
createDataChannel: (roomId: string, name: string, ordered?: boolean) => Promise<{
url: string;
headers: Headers;
code: number;
ok: boolean;
message: string;
data: null;
}>;
setAuth: (auth: {
url: string;
data: {
expirySeconds: number;
accessToken: string;
refreshToken: string;
};
}) => {
baseUrl: string;
apiVersion: string;
accessToken: string;
refreshToken: string;
expirySeconds: number;
};
on: (eventName: string, callback: (data: any) => void) => void;
addEventListener: (eventName: string, callback: (data: any) => void) => void;
removeEventListener: (eventName: string, callback: (data: any) => void) => void;
leaveRoom: (roomId: string, clientId: string, useBeacon?: boolean) => Promise<{
code: number;
ok: boolean;
message: string;
data: null;
}>;
endRoom: (roomId: string) => Promise<RoomAPIType.BaseResponseReturn>;
};
export { REASONS as ChannelClosureReasons, modules$1 as InliveApp, modules as InliveStream, Room, RoomEvent, Stat, Stream, createAuth };
//# sourceMappingURL=inlive-js-sdk.d.ts.map