sip-connector 14.1.2-0 → 14.1.2-1
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/SipConnector-CZwqeStw.cjs +1 -0
- package/dist/SipConnector-DfaRIKWv.js +1345 -0
- package/dist/SipConnector.d.ts +315 -0
- package/dist/{src/SipConnectorFacade → SipConnectorFacade}/SipConnectorFacade.d.ts +1 -1
- package/dist/doMock.cjs +1 -1
- package/dist/doMock.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +2 -2
- package/dist/utils/utils.d.ts +4 -0
- package/package.json +1 -1
- package/dist/SipConnector-BHvTGgmw.js +0 -1352
- package/dist/SipConnector-ChW25Tx9.cjs +0 -1
- package/dist/src/SipConnector.d.ts +0 -235
- /package/dist/{src/SipConnectorFacade → SipConnectorFacade}/index.d.ts +0 -0
- /package/dist/{src/__fixtures__ → __fixtures__}/BaseSession.mock.d.ts +0 -0
- /package/dist/{src/__fixtures__ → __fixtures__}/RTCPeerConnectionMock.d.ts +0 -0
- /package/dist/{src/__fixtures__ → __fixtures__}/RTCRtpSenderMock.d.ts +0 -0
- /package/dist/{src/__fixtures__ → __fixtures__}/RTCSessionMock.d.ts +0 -0
- /package/dist/{src/__fixtures__ → __fixtures__}/Registrator.mock.d.ts +0 -0
- /package/dist/{src/__fixtures__ → __fixtures__}/Request.mock.d.ts +0 -0
- /package/dist/{src/__fixtures__ → __fixtures__}/UA.mock.d.ts +0 -0
- /package/dist/{src/__fixtures__ → __fixtures__}/WebSocketInterface.mock.d.ts +0 -0
- /package/dist/{src/__fixtures__ → __fixtures__}/accountNotify.d.ts +0 -0
- /package/dist/{src/__fixtures__ → __fixtures__}/channels.d.ts +0 -0
- /package/dist/{src/__fixtures__ → __fixtures__}/channelsNotify.d.ts +0 -0
- /package/dist/{src/__fixtures__ → __fixtures__}/conferenceParticipantTokenIssuedNotify.d.ts +0 -0
- /package/dist/{src/__fixtures__ → __fixtures__}/delayPromise.d.ts +0 -0
- /package/dist/{src/__fixtures__ → __fixtures__}/enterRoom.d.ts +0 -0
- /package/dist/{src/__fixtures__ → __fixtures__}/index.d.ts +0 -0
- /package/dist/{src/__fixtures__ → __fixtures__}/jssip.mock.d.ts +0 -0
- /package/dist/{src/__fixtures__ → __fixtures__}/mediaState.d.ts +0 -0
- /package/dist/{src/__fixtures__ → __fixtures__}/participantMoveRequests.d.ts +0 -0
- /package/dist/{src/__fixtures__ → __fixtures__}/participantNotify.d.ts +0 -0
- /package/dist/{src/__fixtures__ → __fixtures__}/remoteCallerData.d.ts +0 -0
- /package/dist/{src/__fixtures__ → __fixtures__}/utils.d.ts +0 -0
- /package/dist/{src/__fixtures__ → __fixtures__}/webcastNotify.d.ts +0 -0
- /package/dist/{src/causes.d.ts → causes.d.ts} +0 -0
- /package/dist/{src/constants.d.ts → constants.d.ts} +0 -0
- /package/dist/{src/doMock.d.ts → doMock.d.ts} +0 -0
- /package/dist/{src/eventNames.d.ts → eventNames.d.ts} +0 -0
- /package/dist/{src/getExtraHeadersRemoteAddress.d.ts → getExtraHeadersRemoteAddress.d.ts} +0 -0
- /package/dist/{src/headers.d.ts → headers.d.ts} +0 -0
- /package/dist/{src/index.d.ts → index.d.ts} +0 -0
- /package/dist/{src/logger.d.ts → logger.d.ts} +0 -0
- /package/dist/{src/setParametersToSender → setParametersToSender}/configureDegradationPreference.d.ts +0 -0
- /package/dist/{src/setParametersToSender → setParametersToSender}/configureEmptyEncodings.d.ts +0 -0
- /package/dist/{src/setParametersToSender → setParametersToSender}/configureEncodings.d.ts +0 -0
- /package/dist/{src/setParametersToSender → setParametersToSender}/configureMaxBitrate.d.ts +0 -0
- /package/dist/{src/setParametersToSender → setParametersToSender}/configureScaleResolutionDownBy.d.ts +0 -0
- /package/dist/{src/setParametersToSender → setParametersToSender}/hasChangedRTCRtpSendParameters.d.ts +0 -0
- /package/dist/{src/setParametersToSender → setParametersToSender}/index.d.ts +0 -0
- /package/dist/{src/setParametersToSender → setParametersToSender}/resolveHasNeedToUpdateItemEncoding.d.ts +0 -0
- /package/dist/{src/setParametersToSender → setParametersToSender}/setParametersToSender.d.ts +0 -0
- /package/dist/{src/tools → tools}/__fixtures__/call.d.ts +0 -0
- /package/dist/{src/tools → tools}/__fixtures__/connectToServer.d.ts +0 -0
- /package/dist/{src/tools → tools}/__fixtures__/hasValidUri.d.ts +0 -0
- /package/dist/{src/tools → tools}/__fixtures__/permissions.d.ts +0 -0
- /package/dist/{src/tools → tools}/__fixtures__/processRequest.d.ts +0 -0
- /package/dist/{src/tools → tools}/__tests-utils__/parseObject.d.ts +0 -0
- /package/dist/{src/tools → tools}/__tests-utils__/resolveParseArray.d.ts +0 -0
- /package/dist/{src/tools → tools}/error/getLinkError.d.ts +0 -0
- /package/dist/{src/tools → tools}/error/getTypeFromError.d.ts +0 -0
- /package/dist/{src/tools → tools}/error/getValuesFromError.d.ts +0 -0
- /package/dist/{src/tools → tools}/error/index.d.ts +0 -0
- /package/dist/{src/tools → tools}/error/stringifyMessage.d.ts +0 -0
- /package/dist/{src/tools → tools}/generateSimulcastEncodings.d.ts +0 -0
- /package/dist/{src/tools → tools}/getExtraHeaders.d.ts +0 -0
- /package/dist/{src/tools → tools}/getUserAgent.d.ts +0 -0
- /package/dist/{src/tools → tools}/hasPurgatory.d.ts +0 -0
- /package/dist/{src/tools → tools}/index.d.ts +0 -0
- /package/dist/{src/tools → tools}/prepareMediaStream.d.ts +0 -0
- /package/dist/{src/tools → tools}/resolveUpdateTransceiver.d.ts +0 -0
- /package/dist/{src/tools → tools}/sendDTMFAccumulated.d.ts +0 -0
- /package/dist/{src/tools → tools}/setVideoTrackContentHints.d.ts +0 -0
- /package/dist/{src/tools → tools}/syncMediaState/index.d.ts +0 -0
- /package/dist/{src/tools → tools}/syncMediaState/resolveOnStartMainCam.d.ts +0 -0
- /package/dist/{src/tools → tools}/syncMediaState/resolveOnStartMic.d.ts +0 -0
- /package/dist/{src/tools → tools}/syncMediaState/resolveOnStopMainCam.d.ts +0 -0
- /package/dist/{src/tools → tools}/syncMediaState/resolveOnStopMic.d.ts +0 -0
- /package/dist/{src/types.d.ts → types.d.ts} +0 -0
- /package/dist/{src/utils → utils}/errors.d.ts +0 -0
- /package/dist/{src/utils → utils}/findSenderByStream.d.ts +0 -0
- /package/dist/{src/utils → utils}/findVideoSender.d.ts +0 -0
- /package/dist/{src/utils → utils}/findVideoTrack.d.ts +0 -0
- /package/dist/{src/utils → utils}/getCodecFromSender.d.ts +0 -0
- /package/dist/{src/utils → utils}/replaceForbiddenSymbolsWithUnderscore.d.ts +0 -0
- /package/dist/{src/videoSendingBalancer → videoSendingBalancer}/balance.d.ts +0 -0
- /package/dist/{src/videoSendingBalancer → videoSendingBalancer}/getMaxBitrateByWidth.d.ts +0 -0
- /package/dist/{src/videoSendingBalancer → videoSendingBalancer}/getMaxBitrateByWidthAndCodec.d.ts +0 -0
- /package/dist/{src/videoSendingBalancer → videoSendingBalancer}/hasAv1Codec.d.ts +0 -0
- /package/dist/{src/videoSendingBalancer → videoSendingBalancer}/hasIncludesString.d.ts +0 -0
- /package/dist/{src/videoSendingBalancer → videoSendingBalancer}/index.d.ts +0 -0
- /package/dist/{src/videoSendingBalancer → videoSendingBalancer}/processSender.d.ts +0 -0
- /package/dist/{src/videoSendingBalancer → videoSendingBalancer}/scaleBitrate.d.ts +0 -0
- /package/dist/{src/videoSendingBalancer → videoSendingBalancer}/scaleBitrateByCodec.d.ts +0 -0
- /package/dist/{src/videoSendingBalancer → videoSendingBalancer}/scaleResolutionAndBitrate.d.ts +0 -0
- /package/dist/{src/videoSendingBalancer → videoSendingBalancer}/setEncodingsToSender.d.ts +0 -0
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
import { IncomingInfoEvent, IncomingRTCSessionEvent, IncomingRequest, OutgoingInfoEvent, RTCSession, RegisteredEvent, UA, UAConfigurationParams, URI, UnRegisteredEvent, WebSocketInterface } from '@krivega/jssip';
|
|
2
|
+
import { TEventSession, TEventUA } from './eventNames';
|
|
3
|
+
import { TContentHint, TCustomError, TJsSIP, TOnAddedTransceiver } from './types';
|
|
4
|
+
export declare const hasCanceledCallError: (error: unknown) => boolean;
|
|
5
|
+
export declare const hasCanceledStartPresentationError: (error: unknown) => error is import('node_modules/repeated-calls/dist/utils').TCanceledError<unknown>;
|
|
6
|
+
type TChannels = {
|
|
7
|
+
inputChannels: string;
|
|
8
|
+
outputChannels: string;
|
|
9
|
+
};
|
|
10
|
+
type TMediaState = {
|
|
11
|
+
cam: boolean;
|
|
12
|
+
mic: boolean;
|
|
13
|
+
};
|
|
14
|
+
type TOptionsInfoMediaState = {
|
|
15
|
+
noTerminateWhenError?: boolean;
|
|
16
|
+
};
|
|
17
|
+
declare const CMD_CHANNELS = "channels";
|
|
18
|
+
declare const CMD_WEBCAST_STARTED = "WebcastStarted";
|
|
19
|
+
declare const CMD_ADDED_TO_LIST_MODERATORS = "addedToListModerators";
|
|
20
|
+
declare const CMD_REMOVED_FROM_LIST_MODERATORS = "removedFromListModerators";
|
|
21
|
+
declare const CMD_ACCEPTING_WORD_REQUEST = "ParticipationRequestAccepted";
|
|
22
|
+
declare const CMD_CANCELLING_WORD_REQUEST = "ParticipationRequestRejected";
|
|
23
|
+
declare const CMD_MOVE_REQUEST_TO_STREAM = "ParticipantMovedToWebcast";
|
|
24
|
+
declare const CMD_CONFERENCE_PARTICIPANT_TOKEN_ISSUED = "ConferenceParticipantTokenIssued";
|
|
25
|
+
type TAddedToListModeratorsInfoNotify = {
|
|
26
|
+
cmd: typeof CMD_ADDED_TO_LIST_MODERATORS;
|
|
27
|
+
conference: string;
|
|
28
|
+
};
|
|
29
|
+
type TRemovedFromListModeratorsInfoNotify = {
|
|
30
|
+
cmd: typeof CMD_REMOVED_FROM_LIST_MODERATORS;
|
|
31
|
+
conference: string;
|
|
32
|
+
};
|
|
33
|
+
type TAcceptingWordRequestInfoNotify = {
|
|
34
|
+
cmd: typeof CMD_ACCEPTING_WORD_REQUEST;
|
|
35
|
+
body: {
|
|
36
|
+
conference: string;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
type TCancellingWordRequestInfoNotify = {
|
|
40
|
+
cmd: typeof CMD_CANCELLING_WORD_REQUEST;
|
|
41
|
+
body: {
|
|
42
|
+
conference: string;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
type TMoveRequestToStreamInfoNotify = {
|
|
46
|
+
cmd: typeof CMD_MOVE_REQUEST_TO_STREAM;
|
|
47
|
+
body: {
|
|
48
|
+
conference: string;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
type TConferenceParticipantTokenIssued = {
|
|
52
|
+
cmd: typeof CMD_CONFERENCE_PARTICIPANT_TOKEN_ISSUED;
|
|
53
|
+
body: {
|
|
54
|
+
conference: string;
|
|
55
|
+
participant: string;
|
|
56
|
+
jwt: string;
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
type TWebcastInfoNotify = {
|
|
60
|
+
cmd: typeof CMD_WEBCAST_STARTED;
|
|
61
|
+
body: {
|
|
62
|
+
conference: string;
|
|
63
|
+
type: string;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
type TChannelsInfoNotify = {
|
|
67
|
+
cmd: typeof CMD_CHANNELS;
|
|
68
|
+
input: string;
|
|
69
|
+
output: string;
|
|
70
|
+
};
|
|
71
|
+
type TInfoNotify = Omit<TAddedToListModeratorsInfoNotify | TChannelsInfoNotify | TRemovedFromListModeratorsInfoNotify, 'cmd'> & {
|
|
72
|
+
cmd: string;
|
|
73
|
+
};
|
|
74
|
+
type TOptionsExtraHeaders = {
|
|
75
|
+
extraHeaders?: string[];
|
|
76
|
+
};
|
|
77
|
+
type TOntrack = (track: RTCTrackEvent) => void;
|
|
78
|
+
type TParametersConnection = TOptionsExtraHeaders & {
|
|
79
|
+
displayName?: string;
|
|
80
|
+
user?: string;
|
|
81
|
+
password?: string;
|
|
82
|
+
register?: boolean;
|
|
83
|
+
sipServerUrl: string;
|
|
84
|
+
sipWebSocketServerURL: string;
|
|
85
|
+
remoteAddress?: string;
|
|
86
|
+
sessionTimers?: boolean;
|
|
87
|
+
registerExpires?: number;
|
|
88
|
+
connectionRecoveryMinInterval?: number;
|
|
89
|
+
connectionRecoveryMaxInterval?: number;
|
|
90
|
+
userAgent?: string;
|
|
91
|
+
};
|
|
92
|
+
type TParametersCheckTelephony = {
|
|
93
|
+
displayName: string;
|
|
94
|
+
sipServerUrl: string;
|
|
95
|
+
sipWebSocketServerURL: string;
|
|
96
|
+
userAgent?: string;
|
|
97
|
+
remoteAddress?: string;
|
|
98
|
+
extraHeaders?: string[];
|
|
99
|
+
};
|
|
100
|
+
type TParametersCreateUa = UAConfigurationParams & {
|
|
101
|
+
remoteAddress?: string;
|
|
102
|
+
extraHeaders?: string[];
|
|
103
|
+
};
|
|
104
|
+
type TConnect = (parameters: TParametersConnection, options?: {
|
|
105
|
+
callLimit?: number;
|
|
106
|
+
}) => Promise<UA>;
|
|
107
|
+
type TInitUa = (parameters: TParametersConnection) => Promise<UA>;
|
|
108
|
+
type TCreateUa = (parameters: TParametersCreateUa) => UA;
|
|
109
|
+
type TStart = () => Promise<UA>;
|
|
110
|
+
type TSet = ({ displayName, password, }: {
|
|
111
|
+
displayName?: string;
|
|
112
|
+
password?: string;
|
|
113
|
+
}) => Promise<boolean>;
|
|
114
|
+
type TParametersAnswerToIncomingCall = {
|
|
115
|
+
mediaStream: MediaStream;
|
|
116
|
+
extraHeaders?: TOptionsExtraHeaders['extraHeaders'];
|
|
117
|
+
ontrack?: TOntrack;
|
|
118
|
+
iceServers?: RTCIceServer[];
|
|
119
|
+
directionVideo?: RTCRtpTransceiverDirection;
|
|
120
|
+
directionAudio?: RTCRtpTransceiverDirection;
|
|
121
|
+
contentHint?: TContentHint;
|
|
122
|
+
sendEncodings?: RTCRtpEncodingParameters[];
|
|
123
|
+
offerToReceiveAudio?: boolean;
|
|
124
|
+
offerToReceiveVideo?: boolean;
|
|
125
|
+
onAddedTransceiver?: TOnAddedTransceiver;
|
|
126
|
+
};
|
|
127
|
+
type TParametersCall = TParametersAnswerToIncomingCall & {
|
|
128
|
+
number: string;
|
|
129
|
+
};
|
|
130
|
+
type TCall = (parameters: TParametersCall) => Promise<RTCPeerConnection>;
|
|
131
|
+
type TDisconnect = () => Promise<void>;
|
|
132
|
+
type TAnswerToIncomingCall = (parameters: TParametersAnswerToIncomingCall) => Promise<RTCPeerConnection>;
|
|
133
|
+
type TSendDTMF = (tone: number | string) => Promise<void>;
|
|
134
|
+
type THangUp = () => Promise<void>;
|
|
135
|
+
export default class SipConnector {
|
|
136
|
+
private _isRegisterConfig;
|
|
137
|
+
private _connectionConfiguration;
|
|
138
|
+
private _remoteStreams;
|
|
139
|
+
private readonly JsSIP;
|
|
140
|
+
private readonly _sessionEvents;
|
|
141
|
+
private readonly _uaEvents;
|
|
142
|
+
private readonly _cancelableConnect;
|
|
143
|
+
private _cancelableConnectWithRepeatedCalls;
|
|
144
|
+
private _cancelableSendPresentationWithRepeatedCalls;
|
|
145
|
+
private readonly _cancelableInitUa;
|
|
146
|
+
private readonly _cancelableDisconnect;
|
|
147
|
+
private readonly _cancelableSet;
|
|
148
|
+
private readonly _cancelableCall;
|
|
149
|
+
private readonly _cancelableAnswer;
|
|
150
|
+
private readonly _cancelableSendDTMF;
|
|
151
|
+
private getSipServerUrl;
|
|
152
|
+
promisePendingStartPresentation?: Promise<MediaStream>;
|
|
153
|
+
promisePendingStopPresentation?: Promise<MediaStream | void>;
|
|
154
|
+
ua?: UA;
|
|
155
|
+
rtcSession?: RTCSession;
|
|
156
|
+
incomingRTCSession?: RTCSession;
|
|
157
|
+
_streamPresentationCurrent?: MediaStream;
|
|
158
|
+
socket?: WebSocketInterface;
|
|
159
|
+
constructor({ JsSIP }: {
|
|
160
|
+
JsSIP: TJsSIP;
|
|
161
|
+
});
|
|
162
|
+
connect: TConnect;
|
|
163
|
+
initUa: TInitUa;
|
|
164
|
+
set: TSet;
|
|
165
|
+
call: TCall;
|
|
166
|
+
disconnect: TDisconnect;
|
|
167
|
+
answerToIncomingCall: TAnswerToIncomingCall;
|
|
168
|
+
sendDTMF: TSendDTMF;
|
|
169
|
+
hangUp: THangUp;
|
|
170
|
+
register(): Promise<RegisteredEvent>;
|
|
171
|
+
unregister(): Promise<UnRegisteredEvent>;
|
|
172
|
+
tryRegister: () => Promise<RegisteredEvent>;
|
|
173
|
+
sendOptions(target: URI | string, body?: string, extraHeaders?: string[]): Promise<void>;
|
|
174
|
+
ping(body?: string, extraHeaders?: string[]): Promise<void>;
|
|
175
|
+
checkTelephony({ userAgent, displayName, sipServerUrl, sipWebSocketServerURL, remoteAddress, extraHeaders, }: TParametersCheckTelephony): Promise<void>;
|
|
176
|
+
replaceMediaStream(mediaStream: MediaStream, options?: {
|
|
177
|
+
deleteExisting?: boolean;
|
|
178
|
+
addMissing?: boolean;
|
|
179
|
+
forceRenegotiation?: boolean;
|
|
180
|
+
contentHint?: TContentHint;
|
|
181
|
+
sendEncodings?: RTCRtpEncodingParameters[];
|
|
182
|
+
onAddedTransceiver?: TOnAddedTransceiver;
|
|
183
|
+
}): Promise<void>;
|
|
184
|
+
declineToIncomingCall: ({ statusCode }?: {
|
|
185
|
+
statusCode?: number | undefined;
|
|
186
|
+
}) => Promise<unknown>;
|
|
187
|
+
busyIncomingCall: () => Promise<unknown>;
|
|
188
|
+
removeIncomingSession: () => void;
|
|
189
|
+
askPermissionToEnableCam(options?: TOptionsInfoMediaState): Promise<void>;
|
|
190
|
+
get isPendingPresentation(): boolean;
|
|
191
|
+
private readonly _connectWithDuplicatedCalls;
|
|
192
|
+
private _sendPresentationWithDuplicatedCalls;
|
|
193
|
+
private hasEqualConnectionConfiguration;
|
|
194
|
+
private createUaConfiguration;
|
|
195
|
+
private _sendPresentation;
|
|
196
|
+
startPresentation(stream: MediaStream, { isNeedReinvite, isP2P, maxBitrate, contentHint, sendEncodings, onAddedTransceiver, }?: {
|
|
197
|
+
isNeedReinvite?: boolean;
|
|
198
|
+
isP2P?: boolean;
|
|
199
|
+
maxBitrate?: number;
|
|
200
|
+
contentHint?: TContentHint;
|
|
201
|
+
sendEncodings?: RTCRtpEncodingParameters[];
|
|
202
|
+
onAddedTransceiver?: TOnAddedTransceiver;
|
|
203
|
+
}, options?: {
|
|
204
|
+
callLimit: number;
|
|
205
|
+
}): Promise<MediaStream>;
|
|
206
|
+
private sendMustStopPresentation;
|
|
207
|
+
stopPresentation({ isP2P, }?: {
|
|
208
|
+
isP2P?: boolean;
|
|
209
|
+
}): Promise<MediaStream | void>;
|
|
210
|
+
updatePresentation(stream: MediaStream, { isP2P, maxBitrate, contentHint, sendEncodings, onAddedTransceiver, }?: {
|
|
211
|
+
isP2P?: boolean;
|
|
212
|
+
maxBitrate?: number;
|
|
213
|
+
contentHint?: TContentHint;
|
|
214
|
+
sendEncodings?: RTCRtpEncodingParameters[];
|
|
215
|
+
onAddedTransceiver?: TOnAddedTransceiver;
|
|
216
|
+
}): Promise<MediaStream | void>;
|
|
217
|
+
_removeStreamPresentationCurrent(): void;
|
|
218
|
+
_resetPresentation(): void;
|
|
219
|
+
_cancelRequestsAndResetPresentation(): void;
|
|
220
|
+
handleNewRTCSession: ({ originator, session: rtcSession }: IncomingRTCSessionEvent) => void;
|
|
221
|
+
on<T = void>(eventName: TEventUA, handler: (data: T) => void): () => void;
|
|
222
|
+
once<T>(eventName: TEventUA, handler: (data: T) => void): () => void;
|
|
223
|
+
onceRace<T>(eventNames: TEventUA[], handler: (data: T, eventName: string) => void): () => void;
|
|
224
|
+
wait<T>(eventName: TEventUA): Promise<T>;
|
|
225
|
+
off<T>(eventName: TEventUA, handler: (data: T) => void): void;
|
|
226
|
+
onSession<T>(eventName: TEventSession, handler: (data: T) => void): () => void;
|
|
227
|
+
onceSession<T>(eventName: TEventSession, handler: (data: T) => void): () => void;
|
|
228
|
+
onceRaceSession<T>(eventNames: TEventSession[], handler: (data: T, eventName: string) => void): () => void;
|
|
229
|
+
waitSession<T>(eventName: TEventSession): Promise<T>;
|
|
230
|
+
offSession<T>(eventName: TEventSession, handler: (data: T) => void): void;
|
|
231
|
+
isConfigured(): boolean;
|
|
232
|
+
getConnectionConfiguration(): {
|
|
233
|
+
sipServerUrl?: string;
|
|
234
|
+
displayName?: string;
|
|
235
|
+
register?: boolean;
|
|
236
|
+
user?: string;
|
|
237
|
+
password?: string;
|
|
238
|
+
number?: string;
|
|
239
|
+
answer?: boolean;
|
|
240
|
+
};
|
|
241
|
+
getRemoteStreams(): MediaStream[] | undefined;
|
|
242
|
+
get connection(): RTCPeerConnection | undefined;
|
|
243
|
+
get remoteCallerData(): {
|
|
244
|
+
displayName: string | undefined;
|
|
245
|
+
host: string | undefined;
|
|
246
|
+
incomingNumber: string | undefined;
|
|
247
|
+
rtcSession: RTCSession | undefined;
|
|
248
|
+
};
|
|
249
|
+
get requested(): boolean;
|
|
250
|
+
get establishedRTCSession(): RTCSession | undefined;
|
|
251
|
+
get isRegistered(): boolean;
|
|
252
|
+
get isRegisterConfig(): boolean;
|
|
253
|
+
get isCallActive(): boolean;
|
|
254
|
+
get isAvailableIncomingCall(): boolean;
|
|
255
|
+
_connect: TConnect;
|
|
256
|
+
_initUa: TInitUa;
|
|
257
|
+
_createUa: TCreateUa;
|
|
258
|
+
_start: TStart;
|
|
259
|
+
_set: TSet;
|
|
260
|
+
_disconnectWithoutCancelRequests: TDisconnect;
|
|
261
|
+
_disconnect: () => Promise<void>;
|
|
262
|
+
_call: TCall;
|
|
263
|
+
_answer: TAnswerToIncomingCall;
|
|
264
|
+
_handleCall: ({ ontrack }: {
|
|
265
|
+
ontrack?: TOntrack;
|
|
266
|
+
}) => Promise<RTCPeerConnection>;
|
|
267
|
+
_restoreSession: () => void;
|
|
268
|
+
_sendDTMF: TSendDTMF;
|
|
269
|
+
_generateStream(videoTrack: MediaStreamTrack, audioTrack?: MediaStreamTrack): MediaStream;
|
|
270
|
+
_generateAudioStream(audioTrack: MediaStreamTrack): MediaStream;
|
|
271
|
+
_generateStreams(remoteTracks: MediaStreamTrack[]): MediaStream[];
|
|
272
|
+
_generateAudioStreams(remoteTracks: MediaStreamTrack[]): MediaStream[];
|
|
273
|
+
_hangUpWithoutCancelRequests: THangUp;
|
|
274
|
+
_cancelRequests(): void;
|
|
275
|
+
_cancelConnectWithRepeatedCalls(): void;
|
|
276
|
+
_cancelSendPresentationWithRepeatedCalls(): void;
|
|
277
|
+
_cancelCallRequests(): void;
|
|
278
|
+
_cancelActionsRequests(): void;
|
|
279
|
+
_handleShareState: (eventName: string) => void;
|
|
280
|
+
_maybeTriggerChannels: (request: IncomingRequest) => void;
|
|
281
|
+
_handleNotify: (header: TInfoNotify) => void;
|
|
282
|
+
_triggerRemovedFromListModeratorsNotify: ({ conference, }: TRemovedFromListModeratorsInfoNotify) => void;
|
|
283
|
+
_triggerAddedToListModeratorsNotify: ({ conference }: TAddedToListModeratorsInfoNotify) => void;
|
|
284
|
+
_triggerWebcastStartedNotify: ({ body: { conference, type } }: TWebcastInfoNotify) => void;
|
|
285
|
+
_triggerWebcastStoppedNotify: ({ body: { conference, type } }: TWebcastInfoNotify) => void;
|
|
286
|
+
_triggerAccountChangedNotify: () => void;
|
|
287
|
+
_triggerAccountDeletedNotify: () => void;
|
|
288
|
+
_triggerConferenceParticipantTokenIssued: ({ body: { conference, participant, jwt }, }: TConferenceParticipantTokenIssued) => void;
|
|
289
|
+
_triggerChannelsNotify: (channelsInfo: TChannelsInfoNotify) => void;
|
|
290
|
+
_triggerParticipationAcceptingWordRequest: ({ body: { conference }, }: TAcceptingWordRequestInfoNotify) => void;
|
|
291
|
+
_triggerParticipationCancellingWordRequest: ({ body: { conference }, }: TCancellingWordRequestInfoNotify) => void;
|
|
292
|
+
_triggerParticipantMoveRequestToStream: ({ body: { conference }, }: TMoveRequestToStreamInfoNotify) => void;
|
|
293
|
+
_triggerEnterRoom: (request: IncomingRequest) => void;
|
|
294
|
+
_triggerShareState: (request: IncomingRequest) => void;
|
|
295
|
+
_maybeTriggerParticipantMoveRequest: (request: IncomingRequest) => void;
|
|
296
|
+
_triggerMainCamControl: (request: IncomingRequest) => void;
|
|
297
|
+
_triggerMicControl: (request: IncomingRequest) => void;
|
|
298
|
+
_triggerUseLicense: (request: IncomingRequest) => void;
|
|
299
|
+
_handleNewInfo: (info: IncomingInfoEvent | OutgoingInfoEvent) => void;
|
|
300
|
+
_handleSipEvent: ({ request }: {
|
|
301
|
+
request: IncomingRequest;
|
|
302
|
+
}) => void;
|
|
303
|
+
_maybeHandleNotify: (request: IncomingRequest) => void;
|
|
304
|
+
waitChannels(): Promise<TChannels>;
|
|
305
|
+
waitSyncMediaState(): Promise<{
|
|
306
|
+
isSyncForced: boolean;
|
|
307
|
+
}>;
|
|
308
|
+
sendChannels({ inputChannels, outputChannels }: TChannels): Promise<void>;
|
|
309
|
+
sendMediaState({ cam, mic }: TMediaState, options?: TOptionsInfoMediaState): Promise<void>;
|
|
310
|
+
_sendRefusalToTurnOn(type: 'cam' | 'mic', options?: TOptionsInfoMediaState): Promise<void>;
|
|
311
|
+
sendRefusalToTurnOnMic(options?: TOptionsInfoMediaState): Promise<void>;
|
|
312
|
+
sendRefusalToTurnOnCam(options?: TOptionsInfoMediaState): Promise<void>;
|
|
313
|
+
_handleEnded: (error: TCustomError) => void;
|
|
314
|
+
}
|
|
315
|
+
export {};
|
|
@@ -145,7 +145,7 @@ declare class SipConnectorFacade implements IProxyMethods {
|
|
|
145
145
|
}) => Promise<MediaStream | undefined>;
|
|
146
146
|
stopShareSipConnector: ({ isP2P }?: {
|
|
147
147
|
isP2P?: boolean;
|
|
148
|
-
}) => Promise<void | MediaStream
|
|
148
|
+
}) => Promise<void | MediaStream>;
|
|
149
149
|
sendRefusalToTurnOnMic: () => Promise<void>;
|
|
150
150
|
sendRefusalToTurnOnCam: () => Promise<void>;
|
|
151
151
|
sendMediaState: ({ isEnabledCam, isEnabledMic, }: {
|
package/dist/doMock.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var F=Object.defineProperty;var L=(o,e,t)=>e in o?F(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t;var r=(o,e,t)=>L(o,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("./SipConnector-ChW25Tx9.cjs"),V=require("@krivega/jssip/lib/NameAddrHeader"),U=require("@krivega/jssip/lib/URI"),z=require("node:events"),x=require("@krivega/jssip/lib/SIPMessage"),y=require("webrtc-mock"),A=require("events-constructor"),u=require("@krivega/jssip");class v extends x.IncomingRequest{constructor(t){super();r(this,"headers");this.headers=new Headers(t)}getHeader(t){return this.headers.get(t)??""}}class q{constructor({originator:e="local",eventHandlers:t}){r(this,"originator");r(this,"connection");r(this,"events");r(this,"remote_identity");r(this,"mutedOptions",{audio:!1,video:!1});this.originator=e,this.events=new A(p.SESSION_EVENT_NAMES),this.initEvents(t)}get contact(){throw new Error("Method not implemented.")}get direction(){throw new Error("Method not implemented.")}get local_identity(){throw new Error("Method not implemented.")}get start_time(){throw new Error("Method not implemented.")}get end_time(){throw new Error("Method not implemented.")}get status(){throw new Error("Method not implemented.")}get C(){throw new Error("Method not implemented.")}get causes(){throw new Error("Method not implemented.")}get id(){throw new Error("Method not implemented.")}get data(){throw new Error("Method not implemented.")}set data(e){throw new Error("Method not implemented.")}isInProgress(){throw new Error("Method not implemented.")}isEnded(){throw new Error("Method not implemented.")}isReadyToReOffer(){throw new Error("Method not implemented.")}answer(e){throw new Error("Method not implemented.")}terminate(e){throw new Error("Method not implemented.")}async sendInfo(e,t,n){throw new Error("Method not implemented.")}hold(e,t){throw new Error("Method not implemented.")}unhold(e,t){throw new Error("Method not implemented.")}async renegotiate(e,t){throw new Error("Method not implemented.")}isOnHold(){throw new Error("Method not implemented.")}mute(e){throw new Error("Method not implemented.")}unmute(e){throw new Error("Method not implemented.")}isMuted(){throw new Error("Method not implemented.")}refer(e,t){throw new Error("Method not implemented.")}resetLocalMedia(){throw new Error("Method not implemented.")}async replaceMediaStream(e,t){throw new Error("Method not implemented.")}addListener(e,t){throw new Error("Method not implemented.")}once(e,t){throw new Error("Method not implemented.")}removeListener(e,t){throw new Error("Method not implemented.")}off(e,t){throw new Error("Method not implemented.")}removeAllListeners(e){throw new Error("Method not implemented.")}setMaxListeners(e){throw new Error("Method not implemented.")}getMaxListeners(){throw new Error("Method not implemented.")}listeners(e){throw new Error("Method not implemented.")}rawListeners(e){throw new Error("Method not implemented.")}emit(e,...t){throw new Error("Method not implemented.")}listenerCount(e){throw new Error("Method not implemented.")}prependListener(e,t){throw new Error("Method not implemented.")}prependOnceListener(e,t){throw new Error("Method not implemented.")}eventNames(){throw new Error("Method not implemented.")}initEvents(e){Object.entries(e).forEach(([t,n])=>this.on(t,n))}on(e,t){return this.events.on(e,t),this}trigger(e,t){this.events.trigger(e,t)}sendDTMF(){this.trigger("newDTMF",{originator:this.originator})}async startPresentation(e){return e}async updatePresentation(e){return e}async stopPresentation(e){return e}isEstablished(){return!0}}class H{constructor({track:e}={}){r(this,"dtmf",null);r(this,"track",null);r(this,"transport",null);r(this,"transform",null);r(this,"parameters",{encodings:[{}],transactionId:"0",codecs:[],headerExtensions:[],rtcp:{}});r(this,"parametersGets");this.track=e??null}async getStats(){throw new Error("Method not implemented.")}async replaceTrack(e){this.track=e??null}async setParameters(e){if(e!==this.parametersGets)throw new Error("Failed to execute 'setParameters' on 'RTCRtpSender': Read-only field modified in setParameters().");const{transactionId:t}=this.parameters;this.parameters={...this.parameters,...e,transactionId:`${Number(t)+1}`}}getParameters(){return this.parametersGets={...this.parameters},this.parametersGets}setStreams(){throw new Error("Method not implemented.")}}class Y{constructor(e,t){r(this,"senders",[]);r(this,"receivers",[]);r(this,"canTrickleIceCandidates");r(this,"connectionState");r(this,"currentLocalDescription");r(this,"currentRemoteDescription");r(this,"iceConnectionState");r(this,"iceGatheringState");r(this,"idpErrorInfo");r(this,"idpLoginUrl");r(this,"localDescription");r(this,"onconnectionstatechange");r(this,"ondatachannel");r(this,"onicecandidate");r(this,"onicecandidateerror",null);r(this,"oniceconnectionstatechange");r(this,"onicegatheringstatechange");r(this,"onnegotiationneeded");r(this,"onsignalingstatechange");r(this,"ontrack");r(this,"peerIdentity");r(this,"pendingLocalDescription");r(this,"pendingRemoteDescription");r(this,"remoteDescription");r(this,"sctp",null);r(this,"signalingState");r(this,"getReceivers",()=>this.receivers);r(this,"getSenders",()=>this.senders);r(this,"addTrack",e=>{const t=new H({track:e});return this.senders.push(t),t});this.receivers=t.map(n=>({track:n}))}getRemoteStreams(){throw new Error("Method not implemented.")}async addIceCandidate(e){throw new Error("Method not implemented.")}addTransceiver(e,t){throw new Error("Method not implemented.")}close(){throw new Error("Method not implemented.")}restartIce(){throw new Error("Method not implemented.")}async createAnswer(e,t){throw new Error("Method not implemented.")}createDataChannel(e,t){throw new Error("Method not implemented.")}async createOffer(e,t,n){throw new Error("Method not implemented.")}getConfiguration(){throw new Error("Method not implemented.")}async getIdentityAssertion(){throw new Error("Method not implemented.")}async getStats(e){throw new Error("Method not implemented.")}getTransceivers(){throw new Error("Method not implemented.")}removeTrack(e){throw new Error("Method not implemented.")}setConfiguration(e){throw new Error("Method not implemented.")}async setLocalDescription(e){throw new Error("Method not implemented.")}async setRemoteDescription(e){throw new Error("Method not implemented.")}addEventListener(e,t,n){throw new Error("Method not implemented.")}removeEventListener(e,t,n){throw new Error("Method not implemented.")}dispatchEvent(e){throw new Error("Method not implemented.")}}function j(o){const e=o.match(/(purgatory)|[\d.]+/g);if(!e)throw new Error("wrong sip url");return e[0]}const S=400,O="777",B=o=>o.getVideoTracks().length>0,a=class a extends q{constructor({url:t="",mediaStream:n,eventHandlers:i,originator:d}){super({originator:d,eventHandlers:i});r(this,"url");r(this,"status_code");r(this,"answer",jest.fn(({mediaStream:t})=>{if(this.originator!=="remote")throw new Error("answer available only for remote sessions");this.initPeerconnection(t),setTimeout(()=>{this.trigger("connecting"),setTimeout(()=>{this.trigger("accepted")},100),setTimeout(()=>{this.trigger("confirmed")},200)},S)}));r(this,"isEndedInner",!1);this.url=t,this.initPeerconnection(n)}static setStartPresentationError(t,{count:n=Number.POSITIVE_INFINITY}={}){this.startPresentationError=t,this.countStartPresentationError=n}static resetStartPresentationError(){this.startPresentationError=void 0,this.countStartPresentationError=Number.POSITIVE_INFINITY,this.countStartsPresentation=0}async startPresentation(t){if(a.countStartsPresentation+=1,a.startPresentationError&&a.countStartsPresentation<a.countStartPresentationError)throw a.startPresentationError;return super.startPresentation(t)}initPeerconnection(t){return t?(this.createPeerconnection(t),!0):!1}createPeerconnection(t){const n=y.createAudioMediaStreamTrackMock();n.id="mainaudio1";const i=[n];if(B(t)){const c=y.createVideoMediaStreamTrackMock();c.id="mainvideo1",i.push(c)}this.connection=new Y(void 0,i),this.addStream(t),setTimeout(()=>{this.trigger("peerconnection",{peerconnection:this.connection})},S)}connect(t){const n=j(t);setTimeout(()=>{this.url.includes(O)?this.trigger("failed",{originator:"remote",message:"IncomingResponse",cause:p.REJECTED}):(this.trigger("connecting"),setTimeout(()=>{this.trigger("enterRoom",{room:n})},100),setTimeout(()=>{this.trigger("accepted")},200),setTimeout(()=>{this.trigger("confirmed")},300))},S)}terminate({status_code:t,cause:n}={}){return this.status_code=t,this.trigger("ended",{status_code:t,cause:n,originator:"local"}),this.isEndedInner=!1,this}async terminateAsync({status_code:t,cause:n}={}){this.terminate({status_code:t,cause:n})}terminateRemote({status_code:t}={}){return this.status_code=t,this.trigger("ended",{status_code:t,originator:"remote"}),this}addStream(t,n="getTracks"){t[n]().forEach(i=>this.connection.addTrack(i))}forEachSenders(t){const n=this.connection.getSenders();for(const i of n)t(i);return n}toggleMuteAudio(t){this.forEachSenders(({track:n})=>{n&&n.kind==="audio"&&(n.enabled=!t)})}toggleMuteVideo(t){this.forEachSenders(({track:n})=>{n&&n.kind==="video"&&(n.enabled=!t)})}mute(t){t.audio&&(this.mutedOptions.audio=!0,this.toggleMuteAudio(this.mutedOptions.audio)),t.video&&(this.mutedOptions.video=!0,this.toggleMuteVideo(this.mutedOptions.video)),this.onmute(t)}unmute(t){t.audio&&(this.mutedOptions.audio=!1),t.video&&(this.mutedOptions.video=!1),this.trigger("unmuted",t)}isMuted(){return this.mutedOptions}async replaceMediaStream(t){}onmute({audio:t,video:n}){this.trigger("muted",{audio:t,video:n})}async sendInfo(){}isEnded(){return this.isEndedInner}newInfo(t){this.trigger("newInfo",t)}};r(a,"startPresentationError"),r(a,"countStartPresentationError",Number.POSITIVE_INFINITY),r(a,"countStartsPresentation",0);let g=a;class G{constructor(){r(this,"extraHeaders",[])}setExtraHeaders(e){this.extraHeaders=e}setExtraContactParams(){}}const h="PASSWORD_CORRECT",I="PASSWORD_CORRECT_2",k="NAME_INCORRECT",l=400,f={url:"wss://sipServerUrl/webrtc/wss/",sip_uri:"sip:sipServerUrl;transport=ws",via_transport:"WSS"},N={status_code:200,reason_phrase:"OK"},P={status_code:401,reason_phrase:"Unauthorized"},s=class s{constructor(e){r(this,"events");r(this,"registratorInner");r(this,"call",jest.fn((e,t)=>{const{mediaStream:n,eventHandlers:i}=t;return this.session=new g({url:e,mediaStream:n,eventHandlers:i,originator:"local"}),this.session.connect(e),this.session}));r(this,"startedTimeout");r(this,"stopedTimeout");r(this,"session");r(this,"isRegisteredInner");r(this,"isConnectedInner");r(this,"configuration");this.events=new A(p.UA_JSSIP_EVENT_NAMES);const[t,n]=e.uri.split(":"),[i,d]=n.split("@"),c={...e,uri:new u.URI(t,i,d)};this.configuration=c,this.registratorInner=new G}static setStartError(e,{count:t=Number.POSITIVE_INFINITY}={}){this.startError=e,this.countStartError=t}static resetStartError(){this.startError=void 0,this.countStartError=Number.POSITIVE_INFINITY,this.countStarts=0}static setAvailableTelephony(){this.isAvailableTelephony=!0}static setNotAvailableTelephony(){this.isAvailableTelephony=!1}start(){if(s.countStarts+=1,s.startError&&s.countStarts<s.countStartError){this.trigger("disconnected",s.startError);return}this.register()}stop(){this.startedTimeout&&clearTimeout(this.startedTimeout),this.stopedTimeout&&clearTimeout(this.stopedTimeout),this.unregister(),this.isStarted()?this.stopedTimeout=setTimeout(()=>{this.trigger("disconnected",{error:!0,socket:f})},l):this.trigger("disconnected",{error:!0,socket:f})}on(e,t){return this.events.on(e,t),this}once(e,t){return this.events.once(e,t),this}off(e,t){return this.events.off(e,t),this}removeAllListeners(){return this.events.removeEventHandlers(),this}trigger(e,t){this.events.trigger(e,t)}terminateSessions(){var e;(e=this.session)==null||e.terminate()}set(e,t){return this.configuration[e]=t,!0}register(){this.startedTimeout&&clearTimeout(this.startedTimeout);const{password:e,register:t,uri:n}=this.configuration;t===!0&&n.user.includes(k)?(this.isRegisteredInner=!1,this.isConnectedInner=!1,this.startedTimeout=setTimeout(()=>{this.trigger("registrationFailed",{response:P,cause:u.C.causes.REJECTED})},l)):!this.isRegistered()&&t===!0&&(e===h||e===I)?(this.isRegisteredInner=!0,this.startedTimeout=setTimeout(()=>{this.trigger("registered",{response:N})},l)):t===!0&&e!==h&&e!==I&&(this.isRegisteredInner=!1,this.isConnectedInner=!1,this.startedTimeout=setTimeout(()=>{this.trigger("registrationFailed",{response:P,cause:u.C.causes.REJECTED})},l)),s.isAvailableTelephony?(this.trigger("connected",{socket:f}),this.isConnectedInner=!0):this.stop()}unregister(){this.isRegisteredInner=!1,this.isConnectedInner=!1,this.trigger("unregistered",{response:N})}isRegistered(){return this.isRegisteredInner===!0}isConnected(){return this.isConnectedInner===!0}isStarted(){return this.configuration.register===!0&&this.isRegisteredInner===!0||this.configuration.register!==!0&&this.isConnectedInner===!0}newSipEvent(e){this.trigger("sipEvent",e)}registrator(){return this.registratorInner}};r(s,"isAvailableTelephony",!0),r(s,"startError"),r(s,"countStartError",Number.POSITIVE_INFINITY),r(s,"countStarts",0);let M=s;class J{constructor(e){r(this,"url");this.url=e}}class K extends z.EventEmitter{constructor(t,n){super();r(this,"contentType");r(this,"body");this.contentType=t,this.body=n}}const T="remote",$=(o,e)=>{const t=new v(e),n={originator:T,request:t,info:new K("","")};o.newInfo(n)},X=(o,e)=>{const n={event:"sipEvent",request:new v(e)};o.newSipEvent(n)},Q=(o,{incomingNumber:e="1234",displayName:t,host:n})=>{const i=new g({originator:T,eventHandlers:{}}),d=new U("sip",e,n);i.remote_identity=new V(d,t);const c=new v([]);o.trigger("newRTCSession",{originator:T,session:i,request:c})},Z=(o,e)=>{e?o.trigger("failed",e):o.trigger("failed",o)},W={triggerNewInfo:$,triggerNewSipEvent:X,triggerIncomingSession:Q,triggerFailIncomingSession:Z,WebSocketInterface:J,UA:M,C:{INVITE:"INVITE"}},E="user",m="displayName",w="SIP_SERVER_URL",R="SIP_WEB_SOCKET_SERVER_URL",ee=new W.WebSocketInterface(R),C={userAgent:"Chrome",sipServerUrl:w,sipWebSocketServerURL:R},te={...C},b={...C,user:E,password:h,register:!0},re={...b,displayName:m},ne={...C,displayName:m,register:!1},_={session_timers:!1,sockets:[ee],user_agent:"Chrome",sdp_semantics:"unified-plan",register_expires:300,connection_recovery_max_interval:6,connection_recovery_min_interval:2},oe={..._,password:h,uri:new u.URI("sip",E,w),display_name:"",register:!0},ie={..._,password:h,uri:new u.URI("sip",E,w),display_name:m,register:!0},se={..._,display_name:m,register:!1},ae={..._,display_name:"",register:!1},D="10.10.10.10",de=[`X-Vinteo-Remote: ${D}`],ce=()=>new p.SipConnector({JsSIP:W});exports.FAILED_CONFERENCE_NUMBER=O;exports.NAME_INCORRECT=k;exports.PASSWORD_CORRECT=h;exports.PASSWORD_CORRECT_2=I;exports.SIP_SERVER_URL=w;exports.SIP_WEB_SOCKET_SERVER_URL=R;exports.dataForConnectionWithAuthorization=b;exports.dataForConnectionWithAuthorizationWithDisplayName=re;exports.dataForConnectionWithoutAuthorization=ne;exports.dataForConnectionWithoutAuthorizationWithoutDisplayName=te;exports.displayName=m;exports.doMockSipConnector=ce;exports.extraHeadersRemoteAddress=de;exports.remoteAddress=D;exports.uaConfigurationWithAuthorization=oe;exports.uaConfigurationWithAuthorizationWithDisplayName=ie;exports.uaConfigurationWithoutAuthorization=se;exports.uaConfigurationWithoutAuthorizationWithoutDisplayName=ae;exports.user=E;
|
|
1
|
+
"use strict";var F=Object.defineProperty;var L=(o,e,t)=>e in o?F(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t;var r=(o,e,t)=>L(o,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("./SipConnector-CZwqeStw.cjs"),V=require("@krivega/jssip/lib/NameAddrHeader"),U=require("@krivega/jssip/lib/URI"),z=require("node:events"),x=require("@krivega/jssip/lib/SIPMessage"),y=require("webrtc-mock"),A=require("events-constructor"),u=require("@krivega/jssip");class v extends x.IncomingRequest{constructor(t){super();r(this,"headers");this.headers=new Headers(t)}getHeader(t){return this.headers.get(t)??""}}class q{constructor({originator:e="local",eventHandlers:t}){r(this,"originator");r(this,"connection");r(this,"events");r(this,"remote_identity");r(this,"mutedOptions",{audio:!1,video:!1});this.originator=e,this.events=new A(p.SESSION_EVENT_NAMES),this.initEvents(t)}get contact(){throw new Error("Method not implemented.")}get direction(){throw new Error("Method not implemented.")}get local_identity(){throw new Error("Method not implemented.")}get start_time(){throw new Error("Method not implemented.")}get end_time(){throw new Error("Method not implemented.")}get status(){throw new Error("Method not implemented.")}get C(){throw new Error("Method not implemented.")}get causes(){throw new Error("Method not implemented.")}get id(){throw new Error("Method not implemented.")}get data(){throw new Error("Method not implemented.")}set data(e){throw new Error("Method not implemented.")}isInProgress(){throw new Error("Method not implemented.")}isEnded(){throw new Error("Method not implemented.")}isReadyToReOffer(){throw new Error("Method not implemented.")}answer(e){throw new Error("Method not implemented.")}terminate(e){throw new Error("Method not implemented.")}async sendInfo(e,t,n){throw new Error("Method not implemented.")}hold(e,t){throw new Error("Method not implemented.")}unhold(e,t){throw new Error("Method not implemented.")}async renegotiate(e,t){throw new Error("Method not implemented.")}isOnHold(){throw new Error("Method not implemented.")}mute(e){throw new Error("Method not implemented.")}unmute(e){throw new Error("Method not implemented.")}isMuted(){throw new Error("Method not implemented.")}refer(e,t){throw new Error("Method not implemented.")}resetLocalMedia(){throw new Error("Method not implemented.")}async replaceMediaStream(e,t){throw new Error("Method not implemented.")}addListener(e,t){throw new Error("Method not implemented.")}once(e,t){throw new Error("Method not implemented.")}removeListener(e,t){throw new Error("Method not implemented.")}off(e,t){throw new Error("Method not implemented.")}removeAllListeners(e){throw new Error("Method not implemented.")}setMaxListeners(e){throw new Error("Method not implemented.")}getMaxListeners(){throw new Error("Method not implemented.")}listeners(e){throw new Error("Method not implemented.")}rawListeners(e){throw new Error("Method not implemented.")}emit(e,...t){throw new Error("Method not implemented.")}listenerCount(e){throw new Error("Method not implemented.")}prependListener(e,t){throw new Error("Method not implemented.")}prependOnceListener(e,t){throw new Error("Method not implemented.")}eventNames(){throw new Error("Method not implemented.")}initEvents(e){Object.entries(e).forEach(([t,n])=>this.on(t,n))}on(e,t){return this.events.on(e,t),this}trigger(e,t){this.events.trigger(e,t)}sendDTMF(){this.trigger("newDTMF",{originator:this.originator})}async startPresentation(e){return e}async updatePresentation(e){return e}async stopPresentation(e){return e}isEstablished(){return!0}}class H{constructor({track:e}={}){r(this,"dtmf",null);r(this,"track",null);r(this,"transport",null);r(this,"transform",null);r(this,"parameters",{encodings:[{}],transactionId:"0",codecs:[],headerExtensions:[],rtcp:{}});r(this,"parametersGets");this.track=e??null}async getStats(){throw new Error("Method not implemented.")}async replaceTrack(e){this.track=e??null}async setParameters(e){if(e!==this.parametersGets)throw new Error("Failed to execute 'setParameters' on 'RTCRtpSender': Read-only field modified in setParameters().");const{transactionId:t}=this.parameters;this.parameters={...this.parameters,...e,transactionId:`${Number(t)+1}`}}getParameters(){return this.parametersGets={...this.parameters},this.parametersGets}setStreams(){throw new Error("Method not implemented.")}}class Y{constructor(e,t){r(this,"senders",[]);r(this,"receivers",[]);r(this,"canTrickleIceCandidates");r(this,"connectionState");r(this,"currentLocalDescription");r(this,"currentRemoteDescription");r(this,"iceConnectionState");r(this,"iceGatheringState");r(this,"idpErrorInfo");r(this,"idpLoginUrl");r(this,"localDescription");r(this,"onconnectionstatechange");r(this,"ondatachannel");r(this,"onicecandidate");r(this,"onicecandidateerror",null);r(this,"oniceconnectionstatechange");r(this,"onicegatheringstatechange");r(this,"onnegotiationneeded");r(this,"onsignalingstatechange");r(this,"ontrack");r(this,"peerIdentity");r(this,"pendingLocalDescription");r(this,"pendingRemoteDescription");r(this,"remoteDescription");r(this,"sctp",null);r(this,"signalingState");r(this,"getReceivers",()=>this.receivers);r(this,"getSenders",()=>this.senders);r(this,"addTrack",e=>{const t=new H({track:e});return this.senders.push(t),t});this.receivers=t.map(n=>({track:n}))}getRemoteStreams(){throw new Error("Method not implemented.")}async addIceCandidate(e){throw new Error("Method not implemented.")}addTransceiver(e,t){throw new Error("Method not implemented.")}close(){throw new Error("Method not implemented.")}restartIce(){throw new Error("Method not implemented.")}async createAnswer(e,t){throw new Error("Method not implemented.")}createDataChannel(e,t){throw new Error("Method not implemented.")}async createOffer(e,t,n){throw new Error("Method not implemented.")}getConfiguration(){throw new Error("Method not implemented.")}async getIdentityAssertion(){throw new Error("Method not implemented.")}async getStats(e){throw new Error("Method not implemented.")}getTransceivers(){throw new Error("Method not implemented.")}removeTrack(e){throw new Error("Method not implemented.")}setConfiguration(e){throw new Error("Method not implemented.")}async setLocalDescription(e){throw new Error("Method not implemented.")}async setRemoteDescription(e){throw new Error("Method not implemented.")}addEventListener(e,t,n){throw new Error("Method not implemented.")}removeEventListener(e,t,n){throw new Error("Method not implemented.")}dispatchEvent(e){throw new Error("Method not implemented.")}}function j(o){const e=o.match(/(purgatory)|[\d.]+/g);if(!e)throw new Error("wrong sip url");return e[0]}const S=400,O="777",B=o=>o.getVideoTracks().length>0,a=class a extends q{constructor({url:t="",mediaStream:n,eventHandlers:i,originator:d}){super({originator:d,eventHandlers:i});r(this,"url");r(this,"status_code");r(this,"answer",jest.fn(({mediaStream:t})=>{if(this.originator!=="remote")throw new Error("answer available only for remote sessions");this.initPeerconnection(t),setTimeout(()=>{this.trigger("connecting"),setTimeout(()=>{this.trigger("accepted")},100),setTimeout(()=>{this.trigger("confirmed")},200)},S)}));r(this,"isEndedInner",!1);this.url=t,this.initPeerconnection(n)}static setStartPresentationError(t,{count:n=Number.POSITIVE_INFINITY}={}){this.startPresentationError=t,this.countStartPresentationError=n}static resetStartPresentationError(){this.startPresentationError=void 0,this.countStartPresentationError=Number.POSITIVE_INFINITY,this.countStartsPresentation=0}async startPresentation(t){if(a.countStartsPresentation+=1,a.startPresentationError&&a.countStartsPresentation<a.countStartPresentationError)throw a.startPresentationError;return super.startPresentation(t)}initPeerconnection(t){return t?(this.createPeerconnection(t),!0):!1}createPeerconnection(t){const n=y.createAudioMediaStreamTrackMock();n.id="mainaudio1";const i=[n];if(B(t)){const c=y.createVideoMediaStreamTrackMock();c.id="mainvideo1",i.push(c)}this.connection=new Y(void 0,i),this.addStream(t),setTimeout(()=>{this.trigger("peerconnection",{peerconnection:this.connection})},S)}connect(t){const n=j(t);setTimeout(()=>{this.url.includes(O)?this.trigger("failed",{originator:"remote",message:"IncomingResponse",cause:p.REJECTED}):(this.trigger("connecting"),setTimeout(()=>{this.trigger("enterRoom",{room:n})},100),setTimeout(()=>{this.trigger("accepted")},200),setTimeout(()=>{this.trigger("confirmed")},300))},S)}terminate({status_code:t,cause:n}={}){return this.status_code=t,this.trigger("ended",{status_code:t,cause:n,originator:"local"}),this.isEndedInner=!1,this}async terminateAsync({status_code:t,cause:n}={}){this.terminate({status_code:t,cause:n})}terminateRemote({status_code:t}={}){return this.status_code=t,this.trigger("ended",{status_code:t,originator:"remote"}),this}addStream(t,n="getTracks"){t[n]().forEach(i=>this.connection.addTrack(i))}forEachSenders(t){const n=this.connection.getSenders();for(const i of n)t(i);return n}toggleMuteAudio(t){this.forEachSenders(({track:n})=>{n&&n.kind==="audio"&&(n.enabled=!t)})}toggleMuteVideo(t){this.forEachSenders(({track:n})=>{n&&n.kind==="video"&&(n.enabled=!t)})}mute(t){t.audio&&(this.mutedOptions.audio=!0,this.toggleMuteAudio(this.mutedOptions.audio)),t.video&&(this.mutedOptions.video=!0,this.toggleMuteVideo(this.mutedOptions.video)),this.onmute(t)}unmute(t){t.audio&&(this.mutedOptions.audio=!1),t.video&&(this.mutedOptions.video=!1),this.trigger("unmuted",t)}isMuted(){return this.mutedOptions}async replaceMediaStream(t){}onmute({audio:t,video:n}){this.trigger("muted",{audio:t,video:n})}async sendInfo(){}isEnded(){return this.isEndedInner}newInfo(t){this.trigger("newInfo",t)}};r(a,"startPresentationError"),r(a,"countStartPresentationError",Number.POSITIVE_INFINITY),r(a,"countStartsPresentation",0);let g=a;class G{constructor(){r(this,"extraHeaders",[])}setExtraHeaders(e){this.extraHeaders=e}setExtraContactParams(){}}const h="PASSWORD_CORRECT",I="PASSWORD_CORRECT_2",k="NAME_INCORRECT",l=400,f={url:"wss://sipServerUrl/webrtc/wss/",sip_uri:"sip:sipServerUrl;transport=ws",via_transport:"WSS"},N={status_code:200,reason_phrase:"OK"},P={status_code:401,reason_phrase:"Unauthorized"},s=class s{constructor(e){r(this,"events");r(this,"registratorInner");r(this,"call",jest.fn((e,t)=>{const{mediaStream:n,eventHandlers:i}=t;return this.session=new g({url:e,mediaStream:n,eventHandlers:i,originator:"local"}),this.session.connect(e),this.session}));r(this,"startedTimeout");r(this,"stopedTimeout");r(this,"session");r(this,"isRegisteredInner");r(this,"isConnectedInner");r(this,"configuration");this.events=new A(p.UA_JSSIP_EVENT_NAMES);const[t,n]=e.uri.split(":"),[i,d]=n.split("@"),c={...e,uri:new u.URI(t,i,d)};this.configuration=c,this.registratorInner=new G}static setStartError(e,{count:t=Number.POSITIVE_INFINITY}={}){this.startError=e,this.countStartError=t}static resetStartError(){this.startError=void 0,this.countStartError=Number.POSITIVE_INFINITY,this.countStarts=0}static setAvailableTelephony(){this.isAvailableTelephony=!0}static setNotAvailableTelephony(){this.isAvailableTelephony=!1}start(){if(s.countStarts+=1,s.startError&&s.countStarts<s.countStartError){this.trigger("disconnected",s.startError);return}this.register()}stop(){this.startedTimeout&&clearTimeout(this.startedTimeout),this.stopedTimeout&&clearTimeout(this.stopedTimeout),this.unregister(),this.isStarted()?this.stopedTimeout=setTimeout(()=>{this.trigger("disconnected",{error:!0,socket:f})},l):this.trigger("disconnected",{error:!0,socket:f})}on(e,t){return this.events.on(e,t),this}once(e,t){return this.events.once(e,t),this}off(e,t){return this.events.off(e,t),this}removeAllListeners(){return this.events.removeEventHandlers(),this}trigger(e,t){this.events.trigger(e,t)}terminateSessions(){var e;(e=this.session)==null||e.terminate()}set(e,t){return this.configuration[e]=t,!0}register(){this.startedTimeout&&clearTimeout(this.startedTimeout);const{password:e,register:t,uri:n}=this.configuration;t===!0&&n.user.includes(k)?(this.isRegisteredInner=!1,this.isConnectedInner=!1,this.startedTimeout=setTimeout(()=>{this.trigger("registrationFailed",{response:P,cause:u.C.causes.REJECTED})},l)):!this.isRegistered()&&t===!0&&(e===h||e===I)?(this.isRegisteredInner=!0,this.startedTimeout=setTimeout(()=>{this.trigger("registered",{response:N})},l)):t===!0&&e!==h&&e!==I&&(this.isRegisteredInner=!1,this.isConnectedInner=!1,this.startedTimeout=setTimeout(()=>{this.trigger("registrationFailed",{response:P,cause:u.C.causes.REJECTED})},l)),s.isAvailableTelephony?(this.trigger("connected",{socket:f}),this.isConnectedInner=!0):this.stop()}unregister(){this.isRegisteredInner=!1,this.isConnectedInner=!1,this.trigger("unregistered",{response:N})}isRegistered(){return this.isRegisteredInner===!0}isConnected(){return this.isConnectedInner===!0}isStarted(){return this.configuration.register===!0&&this.isRegisteredInner===!0||this.configuration.register!==!0&&this.isConnectedInner===!0}newSipEvent(e){this.trigger("sipEvent",e)}registrator(){return this.registratorInner}};r(s,"isAvailableTelephony",!0),r(s,"startError"),r(s,"countStartError",Number.POSITIVE_INFINITY),r(s,"countStarts",0);let M=s;class J{constructor(e){r(this,"url");this.url=e}}class K extends z.EventEmitter{constructor(t,n){super();r(this,"contentType");r(this,"body");this.contentType=t,this.body=n}}const T="remote",$=(o,e)=>{const t=new v(e),n={originator:T,request:t,info:new K("","")};o.newInfo(n)},X=(o,e)=>{const n={event:"sipEvent",request:new v(e)};o.newSipEvent(n)},Q=(o,{incomingNumber:e="1234",displayName:t,host:n})=>{const i=new g({originator:T,eventHandlers:{}}),d=new U("sip",e,n);i.remote_identity=new V(d,t);const c=new v([]);o.trigger("newRTCSession",{originator:T,session:i,request:c})},Z=(o,e)=>{e?o.trigger("failed",e):o.trigger("failed",o)},W={triggerNewInfo:$,triggerNewSipEvent:X,triggerIncomingSession:Q,triggerFailIncomingSession:Z,WebSocketInterface:J,UA:M,C:{INVITE:"INVITE"}},E="user",m="displayName",w="SIP_SERVER_URL",R="SIP_WEB_SOCKET_SERVER_URL",ee=new W.WebSocketInterface(R),C={userAgent:"Chrome",sipServerUrl:w,sipWebSocketServerURL:R},te={...C},b={...C,user:E,password:h,register:!0},re={...b,displayName:m},ne={...C,displayName:m,register:!1},_={session_timers:!1,sockets:[ee],user_agent:"Chrome",sdp_semantics:"unified-plan",register_expires:300,connection_recovery_max_interval:6,connection_recovery_min_interval:2},oe={..._,password:h,uri:new u.URI("sip",E,w),display_name:"",register:!0},ie={..._,password:h,uri:new u.URI("sip",E,w),display_name:m,register:!0},se={..._,display_name:m,register:!1},ae={..._,display_name:"",register:!1},D="10.10.10.10",de=[`X-Vinteo-Remote: ${D}`],ce=()=>new p.SipConnector({JsSIP:W});exports.FAILED_CONFERENCE_NUMBER=O;exports.NAME_INCORRECT=k;exports.PASSWORD_CORRECT=h;exports.PASSWORD_CORRECT_2=I;exports.SIP_SERVER_URL=w;exports.SIP_WEB_SOCKET_SERVER_URL=R;exports.dataForConnectionWithAuthorization=b;exports.dataForConnectionWithAuthorizationWithDisplayName=re;exports.dataForConnectionWithoutAuthorization=ne;exports.dataForConnectionWithoutAuthorizationWithoutDisplayName=te;exports.displayName=m;exports.doMockSipConnector=ce;exports.extraHeadersRemoteAddress=de;exports.remoteAddress=D;exports.uaConfigurationWithAuthorization=oe;exports.uaConfigurationWithAuthorizationWithDisplayName=ie;exports.uaConfigurationWithoutAuthorization=se;exports.uaConfigurationWithoutAuthorizationWithoutDisplayName=ae;exports.user=E;
|
package/dist/doMock.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var k = Object.defineProperty;
|
|
2
2
|
var A = (o, e, t) => e in o ? k(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
|
|
3
3
|
var r = (o, e, t) => A(o, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
-
import { o as b, R as D, U as L, S as W } from "./SipConnector-
|
|
4
|
+
import { o as b, R as D, U as L, S as W } from "./SipConnector-DfaRIKWv.js";
|
|
5
5
|
import V from "@krivega/jssip/lib/NameAddrHeader";
|
|
6
6
|
import F from "@krivega/jssip/lib/URI";
|
|
7
7
|
import { EventEmitter as x } from "node:events";
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var se=Object.defineProperty;var oe=(n,e,t)=>e in n?se(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var a=(n,e,t)=>oe(n,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./SipConnector-ChW25Tx9.cjs"),re=require("sequent-promises"),ie=require("stack-promises"),_=require("debug"),ce=require("@krivega/cancelable-promise"),ae=require("repeated-calls"),le=require("ts-debounce"),U=n=>{const{url:e,cause:t}=n;let s=e;return(t===o.BAD_MEDIA_DESCRIPTION||t===o.NOT_FOUND)&&(s=`${n.message.to.uri.user}@${n.message.to.uri.host}`),s};var G=(n=>(n.CONNECT_SERVER_FAILED="CONNECT_SERVER_FAILED",n.WRONG_USER_OR_PASSWORD="WRONG_USER_OR_PASSWORD",n.BAD_MEDIA_ERROR="BAD_MEDIA_ERROR",n.NOT_FOUND_ERROR="NOT_FOUND_ERROR",n.WS_CONNECTION_FAILED="WS_CONNECTION_FAILED",n.CONNECT_SERVER_FAILED_BY_LINK="CONNECT_SERVER_FAILED_BY_LINK",n))(G||{});const ue=new Error("Unknown error"),de=(n=ue)=>{var r;const{cause:e,socket:t}=n;let s="CONNECT_SERVER_FAILED";switch(e){case"Forbidden":{s="WRONG_USER_OR_PASSWORD";break}case o.BAD_MEDIA_DESCRIPTION:{s="BAD_MEDIA_ERROR";break}case o.NOT_FOUND:{s="NOT_FOUND_ERROR";break}default:t!==void 0&&((r=t._ws)==null?void 0:r.readyState)===3?s="WS_CONNECTION_FAILED":U(n)!==void 0&&U(n)!==""&&(s="CONNECT_SERVER_FAILED_BY_LINK")}return s},ge=n=>{let e="";try{e=JSON.stringify(n)}catch(t){o.logger("failed to stringify message",t)}return e},Ce=new Error("Unknown error"),Se=(n=Ce)=>{const{code:e,cause:t,message:s}=n,r=U(n),i={code:"",cause:"",message:""};return typeof s=="object"&&s!==null?i.message=ge(s):s&&(i.message=String(s)),r!==void 0&&r!==""&&(i.link=r),e!==void 0&&e!==""&&(i.code=e),t!==void 0&&t!==""&&(i.cause=t),i},fe=Object.freeze(Object.defineProperty({__proto__:null,EErrorTypes:G,getLinkError:U,getTypeFromError:de,getValuesFromError:Se},Symbol.toStringTag,{value:"Module"})),me=({sessionId:n,remoteAddress:e,isMutedAudio:t,isMutedVideo:s,isRegistered:r,isPresentationCall:i})=>{const c=[],l=t?"0":"1",u=s?"0":"1";return c.push(`X-Vinteo-Mic-State: ${l}`,`X-Vinteo-MainCam-State: ${u}`),(r===!1||r===void 0)&&c.push("X-Vinteo-Purgatory-Call: yes"),n!==void 0&&n!==""&&c.push(`X-Vinteo-Session: ${n}`),i===!0&&c.push("X-Vinteo-Presentation-Call: yes"),e!==void 0&&e!==""&&c.push(`X-Vinteo-Remote: ${e}`),c},he="[@*!|]",Re="_",pe=n=>{let e=n;return e=e.replaceAll(new RegExp(he,"g"),Re),e},Ee=({appName:n,appVersion:e,browserName:t,browserVersion:s})=>{const i=`${pe(n)} ${e}`;return`ChromeNew - ${t===void 0?i:`${t} ${s}, ${i}`}`},ye=({isUnifiedSdpSemantic:n,appVersion:e,browserName:t,browserVersion:s,appName:r})=>n?Ee({appVersion:e,browserName:t,browserVersion:s,appName:r}):"Chrome",K="purgatory",I=n=>n===K,Te=n=>e=>[...e].map(s=>async()=>n(s)),Me=async({accumulatedKeys:n,sendKey:e,canRunTask:t})=>{const r=Te(e)(n);return re.sequentPromises(r,t)},be=n=>t=>(o.logger("onStartMainCam"),n.onSession("admin-start-main-cam",t)),ve=n=>t=>(o.logger("onStartMic"),n.onSession("admin-start-mic",t)),Ae=n=>t=>(o.logger("onStopMainCam"),n.onSession("admin-stop-main-cam",t)),_e=n=>t=>(o.logger("onStopMic"),n.onSession("admin-stop-mic",t)),Oe=({sipConnector:n})=>{const e=(f,p)=>({isSyncForced:m=!1})=>{if(m){f();return}p()},t=be(n),s=Ae(n),r=ve(n),i=_e(n);let c=()=>{},l=()=>{},u=()=>{},g=()=>{};const S=({onStartMainCamForced:f,onStartMainCamNotForced:p,onStopMainCamForced:m,onStopMainCamNotForced:h,onStartMicForced:E,onStartMicNotForced:y,onStopMicForced:T,onStopMicNotForced:M})=>{const A=e(f,p);c=t(A);const O=e(m,h);l=s(O);const N=e(E,y);u=r(N);const w=e(T,M);g=i(w)},C=()=>{c(),l(),u(),g()};return{start:f=>{S(f)},stop:()=>{C()}}},Ne=Object.freeze(Object.defineProperty({__proto__:null,PURGATORY_CONFERENCE_NUMBER:K,createSyncMediaState:Oe,error:fe,getExtraHeaders:me,getUserAgent:ye,hasPurgatory:I,sendDtmfAccumulated:Me},Symbol.toStringTag,{value:"Module"})),we=n=>[...n.keys()].map(e=>n.get(e)),Pe=(n,e)=>we(n).find(t=>(t==null?void 0:t.type)===e),Y=async n=>n.getStats().then(e=>{const t=Pe(e,"codec");return t==null?void 0:t.mimeType}),De=n=>n.find(e=>{var t;return((t=e.track)==null?void 0:t.kind)==="video"}),z=(n,e)=>n!==void 0&&e!==void 0&&n.toLowerCase().includes(e.toLowerCase()),Be=1e6,R=n=>n*Be,Q=R(.06),Ie=R(4),Fe=n=>n<=64?Q:n<=128?R(.12):n<=256?R(.25):n<=384?R(.32):n<=426?R(.38):n<=640?R(.5):n<=848?R(.7):n<=1280?R(1):n<=1920?R(2):Ie,ke="av1",Ve=n=>z(n,ke),Ue=.6,J=(n,e)=>Ve(e)?n*Ue:n,xe=n=>J(Q,n),Z=(n,e)=>{const t=Fe(n);return J(t,e)},H=1,ee=({videoTrack:n,targetSize:e,codec:t})=>{const s=n.getSettings(),r=s.width,i=s.height,c=r===void 0?H:r/e.width,l=i===void 0?H:i/e.height,u=Math.max(c,l,H),g=Z(e.width,t);return{scaleResolutionDownBy:u,maxBitrate:g}},ne=ie.createStackPromises(),Le=async()=>ne().catch(n=>{o.logger("videoSendingBalancer: error",n)}),$e=async n=>(ne.add(n),Le()),X=async({sender:n,scaleResolutionDownBy:e,maxBitrate:t,onSetParameters:s})=>$e(async()=>o.setEncodingsToSender(n,{scaleResolutionDownBy:e,maxBitrate:t},s)),He=async({sender:n,codec:e},t)=>{const r=xe(e);return X({sender:n,maxBitrate:r,onSetParameters:t,scaleResolutionDownBy:200})},V=async({sender:n,videoTrack:e,codec:t},s)=>{const c=e.getSettings().width,l=Z(c??0,t);return X({sender:n,maxBitrate:l,onSetParameters:s,scaleResolutionDownBy:1})},qe=async({sender:n,videoTrack:e,resolution:t,codec:s},r)=>{const[i,c]=t.split("x"),{maxBitrate:l,scaleResolutionDownBy:u}=ee({videoTrack:e,codec:s,targetSize:{width:Number(i),height:Number(c)}});return X({sender:n,maxBitrate:l,onSetParameters:r,scaleResolutionDownBy:u})},Xe=async({mainCam:n,resolutionMainCam:e,sender:t,videoTrack:s,codec:r},i)=>{switch(n){case o.EEventsMainCAM.PAUSE_MAIN_CAM:return He({sender:t,codec:r},i);case o.EEventsMainCAM.RESUME_MAIN_CAM:return V({sender:t,videoTrack:s,codec:r},i);case o.EEventsMainCAM.MAX_MAIN_CAM_RESOLUTION:return e!==void 0?qe({sender:t,videoTrack:s,codec:r,resolution:e},i):V({sender:t,videoTrack:s,codec:r},i);case o.EEventsMainCAM.ADMIN_STOP_MAIN_CAM:case o.EEventsMainCAM.ADMIN_START_MAIN_CAM:case void 0:return V({sender:t,videoTrack:s,codec:r},i);default:return V({sender:t,videoTrack:s,codec:r},i)}},j={isChanged:!1,parameters:{encodings:[{}],transactionId:"0",codecs:[],headerExtensions:[],rtcp:{}}},W=async({mainCam:n,resolutionMainCam:e,connection:t,onSetParameters:s,ignoreForCodec:r})=>{const i=t.getSenders(),c=De(i);if(!(c!=null&&c.track))return j;const l=await Y(c);return z(l,r)?j:Xe({mainCam:n,resolutionMainCam:e,sender:c,codec:l,videoTrack:c.track},s)},je=(n,{ignoreForCodec:e,onSetParameters:t}={})=>{const s=async()=>{const{connection:u}=n;if(!u)throw new Error("connection is not exist");return W({connection:u,onSetParameters:t,ignoreForCodec:e})};let r=s;const i=u=>{r=async()=>{const{mainCam:g,resolutionMainCam:S}=u,{connection:C}=n;if(!C)throw new Error("connection is not exist");return W({mainCam:g,resolutionMainCam:S,connection:C,onSetParameters:t,ignoreForCodec:e})},r().catch(_)};return{subscribe:()=>{n.onSession("main-cam-control",i)},unsubscribe:()=>{n.offSession("main-cam-control",i)},balanceByTrack:s,resetMainCamControl(){r=s},async reBalance(){return r()}}},We=n=>n.getVideoTracks()[0],D=({mediaStream:n,simulcastEncodings:e,sendEncodings:t})=>{if(e&&e.length>0){const s=t??[],r=We(n);if(r===void 0)throw new Error("No video track");return e.forEach((i,c)=>{const l=s[c]??{};l.active=!0,i.rid!==void 0&&(l.rid=i.rid),i.scalabilityMode!==void 0&&(l.scalabilityMode=i.scalabilityMode);const{maxBitrate:u,scaleResolutionDownBy:g}=ee({videoTrack:r,targetSize:{width:i.width,height:i.height}});l.maxBitrate=u,l.scaleResolutionDownBy=g,s[c]=l}),s}return t},Ge=(n,e)=>n.filter(s=>e.some(r=>r.clockRate===s.clockRate&&r.mimeType===s.mimeType&&r.channels===s.channels&&r.sdpFmtpLine===s.sdpFmtpLine)),Ke=n=>{const e=RTCRtpSender.getCapabilities(n),t=RTCRtpReceiver.getCapabilities(n),s=e===null?[]:e.codecs,r=t===null?[]:t.codecs;return Ge(s,r)},Ye=(n,e)=>e===void 0||e.length===0?n:n.sort((t,s)=>{const r=e.indexOf(t.mimeType),i=e.indexOf(s.mimeType),c=r===-1?Number.MAX_VALUE:r,l=i===-1?Number.MAX_VALUE:i;return c-l}),ze=(n,e)=>e===void 0||e.length===0?n:n.filter(t=>!e.includes(t.mimeType)),B=(n,{preferredMimeTypesVideoCodecs:e,excludeMimeTypesVideoCodecs:t})=>async s=>{var r;try{if(typeof s.setCodecPreferences=="function"&&((r=s.sender.track)==null?void 0:r.kind)==="video"&&(e!==void 0&&e.length>0||t!==void 0&&t.length>0)){const i=Ke("video"),c=ze(i,t),l=Ye(c,e);s.setCodecPreferences(l)}Object.keys(n).length>0&&await o.setParametersToSender(s.sender,n)}catch(i){o.logger("updateTransceiver error",i)}},q=n=>{if(!ce.isCanceledError(n)&&!ae.hasCanceledError(n))throw n;return{isSuccessful:!1}},Qe=({kind:n,readyState:e})=>n==="video"&&e==="live",Je=new Set(["on","once","onceRace","wait","off","onSession","onceSession","onceRaceSession","waitSession","offSession","sendDTMF","hangUp","declineToIncomingCall","sendChannels","checkTelephony","waitChannels","ping","connection","isConfigured","isRegistered"]);class Ze{constructor(e,{preferredMimeTypesVideoCodecs:t,excludeMimeTypesVideoCodecs:s}={}){a(this,"on");a(this,"once");a(this,"onceRace");a(this,"wait");a(this,"off");a(this,"onSession");a(this,"onceSession");a(this,"onceRaceSession");a(this,"waitSession");a(this,"offSession");a(this,"sendDTMF");a(this,"hangUp");a(this,"declineToIncomingCall");a(this,"sendChannels");a(this,"checkTelephony");a(this,"waitChannels");a(this,"ping");a(this,"connection");a(this,"isConfigured");a(this,"isRegistered");a(this,"sipConnector");a(this,"preferredMimeTypesVideoCodecs");a(this,"excludeMimeTypesVideoCodecs");a(this,"connectToServer",async e=>{const{userAgent:t,sipWebSocketServerURL:s,sipServerUrl:r,remoteAddress:i,displayName:c,name:l,password:u,isRegisteredUser:g,isDisconnectOnFail:S}=e;return o.logger("connectToServer",e),this.sipConnector.connect({userAgent:t,sipWebSocketServerURL:s,sipServerUrl:r,remoteAddress:i,displayName:c,password:u,user:l,register:g}).then(C=>(o.logger("connectToServer then"),{ua:C,isSuccessful:!0})).catch(async C=>(o.logger("connectToServer catch: error",C),S===!0?this.sipConnector.disconnect().then(()=>q(C)).catch(()=>q(C)):q(C)))});a(this,"callToServer",async e=>{const{conference:t,mediaStream:s,extraHeaders:r,iceServers:i,contentHint:c,simulcastEncodings:l,degradationPreference:u,sendEncodings:g,offerToReceiveAudio:S,offerToReceiveVideo:C,directionVideo:F,directionAudio:k,setRemoteStreams:f,onBeforeProgressCall:p,onSuccessProgressCall:m,onEnterPurgatory:h,onEnterConference:E,onFailProgressCall:y,onFinishProgressCall:T,onEndedCall:M}=e,A=this.resolveHandleReadyRemoteStreamsDebounced({onReadyRemoteStreams:f}),O=this.resolveHandleReadyRemoteStreams({onReadyRemoteStreams:()=>{A().catch(_)}}),N=B({degradationPreference:u},{preferredMimeTypesVideoCodecs:this.preferredMimeTypesVideoCodecs,excludeMimeTypesVideoCodecs:this.excludeMimeTypesVideoCodecs});o.logger("callToServer",e);const w=async()=>(o.logger("startCall"),this.sipConnector.call({mediaStream:s,extraHeaders:r,iceServers:i,contentHint:c,offerToReceiveAudio:S,offerToReceiveVideo:C,directionVideo:F,directionAudio:k,sendEncodings:D({mediaStream:s,simulcastEncodings:l,sendEncodings:g}),number:t,onAddedTransceiver:N,ontrack:O}));let b=!1,v;const P=(o.logger("subscribeEnterConference: onEnterConference",E),h??E?this.sipConnector.onSession("enterRoom",({room:d})=>{o.logger("enterRoom",{_room:d,isSuccessProgressCall:b}),v=d,I(v)?h&&h():E&&E({isSuccessProgressCall:b})}):()=>{}),x=d=>(o.logger("onSuccess"),b=!0,A().catch(_),m&&m({isPurgatory:I(v)}),this.sipConnector.onceRaceSession(["ended","failed"],()=>{P(),M&&M()}),d),L=d=>{throw o.logger("onFail"),y&&y(),P(),d},$=()=>{o.logger("onFinish"),T&&T()};return o.logger("onBeforeProgressCall"),p&&p(t),w().then(x).catch(d=>L(d)).finally($)});a(this,"disconnectFromServer",async()=>this.sipConnector.disconnect().then(()=>(o.logger("disconnectFromServer: then"),{isSuccessful:!0})).catch(e=>(o.logger("disconnectFromServer: catch",e),{isSuccessful:!1})));a(this,"answerIncomingCall",async e=>{const{mediaStream:t,extraHeaders:s,iceServers:r,contentHint:i,simulcastEncodings:c,degradationPreference:l,sendEncodings:u,offerToReceiveAudio:g,offerToReceiveVideo:S,directionVideo:C,directionAudio:F,setRemoteStreams:k,onBeforeProgressCall:f,onSuccessProgressCall:p,onEnterPurgatory:m,onEnterConference:h,onFailProgressCall:E,onFinishProgressCall:y,onEndedCall:T}=e,M=this.resolveHandleReadyRemoteStreamsDebounced({onReadyRemoteStreams:k}),A=this.resolveHandleReadyRemoteStreams({onReadyRemoteStreams:()=>{M().catch(_)}}),O=B({degradationPreference:l},{preferredMimeTypesVideoCodecs:this.preferredMimeTypesVideoCodecs,excludeMimeTypesVideoCodecs:this.excludeMimeTypesVideoCodecs});o.logger("answerIncomingCall",e);const N=async()=>this.sipConnector.answerToIncomingCall({mediaStream:t,extraHeaders:s,iceServers:r,contentHint:i,offerToReceiveAudio:g,offerToReceiveVideo:S,directionVideo:C,directionAudio:F,sendEncodings:D({mediaStream:t,simulcastEncodings:c,sendEncodings:u}),onAddedTransceiver:O,ontrack:A}),w=()=>{const{remoteCallerData:d}=this.sipConnector;return d.incomingNumber};let b=!1,v;const P=(o.logger("subscribeEnterConference: onEnterConference",h),m??h?this.sipConnector.onSession("enterRoom",d=>{o.logger("enterRoom",{_room:d,isSuccessProgressCall:b}),v=d,I(v)?m&&m():h&&h({isSuccessProgressCall:b})}):()=>{}),x=d=>(o.logger("onSuccess"),b=!0,M().catch(_),p&&p({isPurgatory:I(v)}),this.sipConnector.onceRaceSession(["ended","failed"],()=>{P(),T&&T()}),d),L=d=>{throw o.logger("onFail"),E&&E(),P(),d},$=()=>{o.logger("onFinish"),y&&y()};if(o.logger("onBeforeProgressCall"),f){const d=w();f(d)}return N().then(x).catch(d=>L(d)).finally($)});a(this,"updatePresentation",async({mediaStream:e,isP2P:t,maxBitrate:s,contentHint:r,simulcastEncodings:i,degradationPreference:c,sendEncodings:l,preferredMimeTypesVideoCodecs:u,excludeMimeTypesVideoCodecs:g})=>{const S=B({degradationPreference:c},{preferredMimeTypesVideoCodecs:u,excludeMimeTypesVideoCodecs:g});return o.logger("updatePresentation"),this.sipConnector.updatePresentation(e,{isP2P:t,maxBitrate:s,contentHint:r,sendEncodings:D({mediaStream:e,simulcastEncodings:i,sendEncodings:l}),onAddedTransceiver:S})});a(this,"startPresentation",async({mediaStream:e,isP2P:t,maxBitrate:s,contentHint:r,simulcastEncodings:i,degradationPreference:c,sendEncodings:l,preferredMimeTypesVideoCodecs:u,excludeMimeTypesVideoCodecs:g},S)=>{const C=B({degradationPreference:c},{preferredMimeTypesVideoCodecs:u,excludeMimeTypesVideoCodecs:g});return o.logger("startPresentation"),this.sipConnector.startPresentation(e,{isP2P:t,maxBitrate:s,contentHint:r,sendEncodings:D({mediaStream:e,simulcastEncodings:i,sendEncodings:l}),onAddedTransceiver:C},S)});a(this,"stopShareSipConnector",async({isP2P:e=!1}={})=>(o.logger("stopShareSipConnector"),this.sipConnector.stopPresentation({isP2P:e}).catch(t=>{o.logger(t)})));a(this,"sendRefusalToTurnOnMic",async()=>{this.sipConnector.isCallActive&&(o.logger("sendRefusalToTurnOnMic"),await this.sipConnector.sendRefusalToTurnOnMic().catch(e=>{o.logger("sendRefusalToTurnOnMic: error",e)}))});a(this,"sendRefusalToTurnOnCam",async()=>{this.sipConnector.isCallActive&&(o.logger("sendRefusalToTurnOnCam"),await this.sipConnector.sendRefusalToTurnOnCam().catch(e=>{o.logger("sendRefusalToTurnOnCam: error",e)}))});a(this,"sendMediaState",async({isEnabledCam:e,isEnabledMic:t})=>{this.sipConnector.isCallActive&&(o.logger("sendMediaState"),await this.sipConnector.sendMediaState({cam:e,mic:t}))});a(this,"replaceMediaStream",async(e,{deleteExisting:t,addMissing:s,forceRenegotiation:r,contentHint:i,simulcastEncodings:c,degradationPreference:l,sendEncodings:u}={})=>{const g=B({degradationPreference:l},{preferredMimeTypesVideoCodecs:this.preferredMimeTypesVideoCodecs,excludeMimeTypesVideoCodecs:this.excludeMimeTypesVideoCodecs});return o.logger("replaceMediaStream"),this.sipConnector.replaceMediaStream(e,{deleteExisting:t,addMissing:s,forceRenegotiation:r,contentHint:i,sendEncodings:D({mediaStream:e,simulcastEncodings:c,sendEncodings:u}),onAddedTransceiver:g})});a(this,"askPermissionToEnableCam",async()=>{this.sipConnector.isCallActive&&(o.logger("askPermissionToEnableCam"),await this.sipConnector.askPermissionToEnableCam())});a(this,"resolveHandleReadyRemoteStreamsDebounced",({onReadyRemoteStreams:e})=>le.debounce(()=>{const t=this.sipConnector.getRemoteStreams();o.logger("remoteStreams",t),t&&e(t)},200));a(this,"resolveHandleReadyRemoteStreams",({onReadyRemoteStreams:e})=>({track:t})=>{Qe(t)&&e()});a(this,"getRemoteStreams",()=>(o.logger("getRemoteStreams"),this.sipConnector.getRemoteStreams()));a(this,"onUseLicense",e=>(o.logger("onUseLicense"),this.sipConnector.onSession("useLicense",e)));a(this,"onMustStopPresentation",e=>(o.logger("onMustStopPresentation"),this.sipConnector.onSession("mustStopPresentation",e)));a(this,"onMoveToSpectators",e=>(o.logger("onMoveToSpectators"),this.sipConnector.onSession(o.PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS,e)));a(this,"onMoveToParticipants",e=>(o.logger("onMoveToParticipants"),this.sipConnector.onSession(o.PARTICIPANT_MOVE_REQUEST_TO_PARTICIPANTS,e)));return this.preferredMimeTypesVideoCodecs=t,this.excludeMimeTypesVideoCodecs=s,this.sipConnector=e,new Proxy(this,{get:(r,i,c)=>{if(typeof i=="string"&&Je.has(i)&&i in this.sipConnector){const u=Reflect.get(this.sipConnector,i,this.sipConnector);return typeof u=="function"?u.bind(this.sipConnector):u}const l=Reflect.get(r,i,c);return typeof l=="function"?l.bind(r):l}})}}exports.EEventsMainCAM=o.EEventsMainCAM;exports.EEventsMic=o.EEventsMic;exports.EEventsSyncMediaState=o.EEventsSyncMediaState;exports.EMimeTypesVideoCodecs=o.EMimeTypesVideoCodecs;exports.EUseLicense=o.EUseLicense;exports.SipConnector=o.SipConnector;exports.causes=o.causes;exports.constants=o.constants;exports.disableDebug=o.disableDebug;exports.enableDebug=o.enableDebug;exports.eventNames=o.eventNames;exports.hasCanceledCallError=o.hasCanceledCallError;exports.hasCanceledStartPresentationError=o.hasCanceledStartPresentationError;exports.setParametersToSender=o.setParametersToSender;exports.debug=_;exports.SipConnectorFacade=Ze;exports.getCodecFromSender=Y;exports.resolveVideoSendingBalancer=je;exports.tools=Ne;
|
|
1
|
+
"use strict";var se=Object.defineProperty;var oe=(n,e,t)=>e in n?se(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var a=(n,e,t)=>oe(n,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./SipConnector-CZwqeStw.cjs"),re=require("sequent-promises"),ie=require("stack-promises"),_=require("debug"),ce=require("@krivega/cancelable-promise"),ae=require("repeated-calls"),le=require("ts-debounce"),U=n=>{const{url:e,cause:t}=n;let s=e;return(t===o.BAD_MEDIA_DESCRIPTION||t===o.NOT_FOUND)&&(s=`${n.message.to.uri.user}@${n.message.to.uri.host}`),s};var G=(n=>(n.CONNECT_SERVER_FAILED="CONNECT_SERVER_FAILED",n.WRONG_USER_OR_PASSWORD="WRONG_USER_OR_PASSWORD",n.BAD_MEDIA_ERROR="BAD_MEDIA_ERROR",n.NOT_FOUND_ERROR="NOT_FOUND_ERROR",n.WS_CONNECTION_FAILED="WS_CONNECTION_FAILED",n.CONNECT_SERVER_FAILED_BY_LINK="CONNECT_SERVER_FAILED_BY_LINK",n))(G||{});const ue=new Error("Unknown error"),de=(n=ue)=>{var r;const{cause:e,socket:t}=n;let s="CONNECT_SERVER_FAILED";switch(e){case"Forbidden":{s="WRONG_USER_OR_PASSWORD";break}case o.BAD_MEDIA_DESCRIPTION:{s="BAD_MEDIA_ERROR";break}case o.NOT_FOUND:{s="NOT_FOUND_ERROR";break}default:t!==void 0&&((r=t._ws)==null?void 0:r.readyState)===3?s="WS_CONNECTION_FAILED":U(n)!==void 0&&U(n)!==""&&(s="CONNECT_SERVER_FAILED_BY_LINK")}return s},ge=n=>{let e="";try{e=JSON.stringify(n)}catch(t){o.logger("failed to stringify message",t)}return e},Ce=new Error("Unknown error"),Se=(n=Ce)=>{const{code:e,cause:t,message:s}=n,r=U(n),i={code:"",cause:"",message:""};return typeof s=="object"&&s!==null?i.message=ge(s):s&&(i.message=String(s)),r!==void 0&&r!==""&&(i.link=r),e!==void 0&&e!==""&&(i.code=e),t!==void 0&&t!==""&&(i.cause=t),i},fe=Object.freeze(Object.defineProperty({__proto__:null,EErrorTypes:G,getLinkError:U,getTypeFromError:de,getValuesFromError:Se},Symbol.toStringTag,{value:"Module"})),me=({sessionId:n,remoteAddress:e,isMutedAudio:t,isMutedVideo:s,isRegistered:r,isPresentationCall:i})=>{const c=[],l=t?"0":"1",u=s?"0":"1";return c.push(`X-Vinteo-Mic-State: ${l}`,`X-Vinteo-MainCam-State: ${u}`),(r===!1||r===void 0)&&c.push("X-Vinteo-Purgatory-Call: yes"),n!==void 0&&n!==""&&c.push(`X-Vinteo-Session: ${n}`),i===!0&&c.push("X-Vinteo-Presentation-Call: yes"),e!==void 0&&e!==""&&c.push(`X-Vinteo-Remote: ${e}`),c},he="[@*!|]",Re="_",pe=n=>{let e=n;return e=e.replaceAll(new RegExp(he,"g"),Re),e},Ee=({appName:n,appVersion:e,browserName:t,browserVersion:s})=>{const i=`${pe(n)} ${e}`;return`ChromeNew - ${t===void 0?i:`${t} ${s}, ${i}`}`},ye=({isUnifiedSdpSemantic:n,appVersion:e,browserName:t,browserVersion:s,appName:r})=>n?Ee({appVersion:e,browserName:t,browserVersion:s,appName:r}):"Chrome",K="purgatory",I=n=>n===K,Te=n=>e=>[...e].map(s=>async()=>n(s)),Me=async({accumulatedKeys:n,sendKey:e,canRunTask:t})=>{const r=Te(e)(n);return re.sequentPromises(r,t)},be=n=>t=>(o.logger("onStartMainCam"),n.onSession("admin-start-main-cam",t)),ve=n=>t=>(o.logger("onStartMic"),n.onSession("admin-start-mic",t)),Ae=n=>t=>(o.logger("onStopMainCam"),n.onSession("admin-stop-main-cam",t)),_e=n=>t=>(o.logger("onStopMic"),n.onSession("admin-stop-mic",t)),Oe=({sipConnector:n})=>{const e=(f,p)=>({isSyncForced:m=!1})=>{if(m){f();return}p()},t=be(n),s=Ae(n),r=ve(n),i=_e(n);let c=()=>{},l=()=>{},u=()=>{},g=()=>{};const S=({onStartMainCamForced:f,onStartMainCamNotForced:p,onStopMainCamForced:m,onStopMainCamNotForced:h,onStartMicForced:E,onStartMicNotForced:y,onStopMicForced:T,onStopMicNotForced:M})=>{const A=e(f,p);c=t(A);const O=e(m,h);l=s(O);const N=e(E,y);u=r(N);const w=e(T,M);g=i(w)},C=()=>{c(),l(),u(),g()};return{start:f=>{S(f)},stop:()=>{C()}}},Ne=Object.freeze(Object.defineProperty({__proto__:null,PURGATORY_CONFERENCE_NUMBER:K,createSyncMediaState:Oe,error:fe,getExtraHeaders:me,getUserAgent:ye,hasPurgatory:I,sendDtmfAccumulated:Me},Symbol.toStringTag,{value:"Module"})),we=n=>[...n.keys()].map(e=>n.get(e)),Pe=(n,e)=>we(n).find(t=>(t==null?void 0:t.type)===e),Y=async n=>n.getStats().then(e=>{const t=Pe(e,"codec");return t==null?void 0:t.mimeType}),De=n=>n.find(e=>{var t;return((t=e.track)==null?void 0:t.kind)==="video"}),z=(n,e)=>n!==void 0&&e!==void 0&&n.toLowerCase().includes(e.toLowerCase()),Be=1e6,R=n=>n*Be,Q=R(.06),Ie=R(4),Fe=n=>n<=64?Q:n<=128?R(.12):n<=256?R(.25):n<=384?R(.32):n<=426?R(.38):n<=640?R(.5):n<=848?R(.7):n<=1280?R(1):n<=1920?R(2):Ie,ke="av1",Ve=n=>z(n,ke),Ue=.6,J=(n,e)=>Ve(e)?n*Ue:n,xe=n=>J(Q,n),Z=(n,e)=>{const t=Fe(n);return J(t,e)},H=1,ee=({videoTrack:n,targetSize:e,codec:t})=>{const s=n.getSettings(),r=s.width,i=s.height,c=r===void 0?H:r/e.width,l=i===void 0?H:i/e.height,u=Math.max(c,l,H),g=Z(e.width,t);return{scaleResolutionDownBy:u,maxBitrate:g}},ne=ie.createStackPromises(),Le=async()=>ne().catch(n=>{o.logger("videoSendingBalancer: error",n)}),$e=async n=>(ne.add(n),Le()),X=async({sender:n,scaleResolutionDownBy:e,maxBitrate:t,onSetParameters:s})=>$e(async()=>o.setEncodingsToSender(n,{scaleResolutionDownBy:e,maxBitrate:t},s)),He=async({sender:n,codec:e},t)=>{const r=xe(e);return X({sender:n,maxBitrate:r,onSetParameters:t,scaleResolutionDownBy:200})},V=async({sender:n,videoTrack:e,codec:t},s)=>{const c=e.getSettings().width,l=Z(c??0,t);return X({sender:n,maxBitrate:l,onSetParameters:s,scaleResolutionDownBy:1})},qe=async({sender:n,videoTrack:e,resolution:t,codec:s},r)=>{const[i,c]=t.split("x"),{maxBitrate:l,scaleResolutionDownBy:u}=ee({videoTrack:e,codec:s,targetSize:{width:Number(i),height:Number(c)}});return X({sender:n,maxBitrate:l,onSetParameters:r,scaleResolutionDownBy:u})},Xe=async({mainCam:n,resolutionMainCam:e,sender:t,videoTrack:s,codec:r},i)=>{switch(n){case o.EEventsMainCAM.PAUSE_MAIN_CAM:return He({sender:t,codec:r},i);case o.EEventsMainCAM.RESUME_MAIN_CAM:return V({sender:t,videoTrack:s,codec:r},i);case o.EEventsMainCAM.MAX_MAIN_CAM_RESOLUTION:return e!==void 0?qe({sender:t,videoTrack:s,codec:r,resolution:e},i):V({sender:t,videoTrack:s,codec:r},i);case o.EEventsMainCAM.ADMIN_STOP_MAIN_CAM:case o.EEventsMainCAM.ADMIN_START_MAIN_CAM:case void 0:return V({sender:t,videoTrack:s,codec:r},i);default:return V({sender:t,videoTrack:s,codec:r},i)}},j={isChanged:!1,parameters:{encodings:[{}],transactionId:"0",codecs:[],headerExtensions:[],rtcp:{}}},W=async({mainCam:n,resolutionMainCam:e,connection:t,onSetParameters:s,ignoreForCodec:r})=>{const i=t.getSenders(),c=De(i);if(!(c!=null&&c.track))return j;const l=await Y(c);return z(l,r)?j:Xe({mainCam:n,resolutionMainCam:e,sender:c,codec:l,videoTrack:c.track},s)},je=(n,{ignoreForCodec:e,onSetParameters:t}={})=>{const s=async()=>{const{connection:u}=n;if(!u)throw new Error("connection is not exist");return W({connection:u,onSetParameters:t,ignoreForCodec:e})};let r=s;const i=u=>{r=async()=>{const{mainCam:g,resolutionMainCam:S}=u,{connection:C}=n;if(!C)throw new Error("connection is not exist");return W({mainCam:g,resolutionMainCam:S,connection:C,onSetParameters:t,ignoreForCodec:e})},r().catch(_)};return{subscribe:()=>{n.onSession("main-cam-control",i)},unsubscribe:()=>{n.offSession("main-cam-control",i)},balanceByTrack:s,resetMainCamControl(){r=s},async reBalance(){return r()}}},We=n=>n.getVideoTracks()[0],D=({mediaStream:n,simulcastEncodings:e,sendEncodings:t})=>{if(e&&e.length>0){const s=t??[],r=We(n);if(r===void 0)throw new Error("No video track");return e.forEach((i,c)=>{const l=s[c]??{};l.active=!0,i.rid!==void 0&&(l.rid=i.rid),i.scalabilityMode!==void 0&&(l.scalabilityMode=i.scalabilityMode);const{maxBitrate:u,scaleResolutionDownBy:g}=ee({videoTrack:r,targetSize:{width:i.width,height:i.height}});l.maxBitrate=u,l.scaleResolutionDownBy=g,s[c]=l}),s}return t},Ge=(n,e)=>n.filter(s=>e.some(r=>r.clockRate===s.clockRate&&r.mimeType===s.mimeType&&r.channels===s.channels&&r.sdpFmtpLine===s.sdpFmtpLine)),Ke=n=>{const e=RTCRtpSender.getCapabilities(n),t=RTCRtpReceiver.getCapabilities(n),s=e===null?[]:e.codecs,r=t===null?[]:t.codecs;return Ge(s,r)},Ye=(n,e)=>e===void 0||e.length===0?n:n.sort((t,s)=>{const r=e.indexOf(t.mimeType),i=e.indexOf(s.mimeType),c=r===-1?Number.MAX_VALUE:r,l=i===-1?Number.MAX_VALUE:i;return c-l}),ze=(n,e)=>e===void 0||e.length===0?n:n.filter(t=>!e.includes(t.mimeType)),B=(n,{preferredMimeTypesVideoCodecs:e,excludeMimeTypesVideoCodecs:t})=>async s=>{var r;try{if(typeof s.setCodecPreferences=="function"&&((r=s.sender.track)==null?void 0:r.kind)==="video"&&(e!==void 0&&e.length>0||t!==void 0&&t.length>0)){const i=Ke("video"),c=ze(i,t),l=Ye(c,e);s.setCodecPreferences(l)}Object.keys(n).length>0&&await o.setParametersToSender(s.sender,n)}catch(i){o.logger("updateTransceiver error",i)}},q=n=>{if(!ce.isCanceledError(n)&&!ae.hasCanceledError(n))throw n;return{isSuccessful:!1}},Qe=({kind:n,readyState:e})=>n==="video"&&e==="live",Je=new Set(["on","once","onceRace","wait","off","onSession","onceSession","onceRaceSession","waitSession","offSession","sendDTMF","hangUp","declineToIncomingCall","sendChannels","checkTelephony","waitChannels","ping","connection","isConfigured","isRegistered"]);class Ze{constructor(e,{preferredMimeTypesVideoCodecs:t,excludeMimeTypesVideoCodecs:s}={}){a(this,"on");a(this,"once");a(this,"onceRace");a(this,"wait");a(this,"off");a(this,"onSession");a(this,"onceSession");a(this,"onceRaceSession");a(this,"waitSession");a(this,"offSession");a(this,"sendDTMF");a(this,"hangUp");a(this,"declineToIncomingCall");a(this,"sendChannels");a(this,"checkTelephony");a(this,"waitChannels");a(this,"ping");a(this,"connection");a(this,"isConfigured");a(this,"isRegistered");a(this,"sipConnector");a(this,"preferredMimeTypesVideoCodecs");a(this,"excludeMimeTypesVideoCodecs");a(this,"connectToServer",async e=>{const{userAgent:t,sipWebSocketServerURL:s,sipServerUrl:r,remoteAddress:i,displayName:c,name:l,password:u,isRegisteredUser:g,isDisconnectOnFail:S}=e;return o.logger("connectToServer",e),this.sipConnector.connect({userAgent:t,sipWebSocketServerURL:s,sipServerUrl:r,remoteAddress:i,displayName:c,password:u,user:l,register:g}).then(C=>(o.logger("connectToServer then"),{ua:C,isSuccessful:!0})).catch(async C=>(o.logger("connectToServer catch: error",C),S===!0?this.sipConnector.disconnect().then(()=>q(C)).catch(()=>q(C)):q(C)))});a(this,"callToServer",async e=>{const{conference:t,mediaStream:s,extraHeaders:r,iceServers:i,contentHint:c,simulcastEncodings:l,degradationPreference:u,sendEncodings:g,offerToReceiveAudio:S,offerToReceiveVideo:C,directionVideo:F,directionAudio:k,setRemoteStreams:f,onBeforeProgressCall:p,onSuccessProgressCall:m,onEnterPurgatory:h,onEnterConference:E,onFailProgressCall:y,onFinishProgressCall:T,onEndedCall:M}=e,A=this.resolveHandleReadyRemoteStreamsDebounced({onReadyRemoteStreams:f}),O=this.resolveHandleReadyRemoteStreams({onReadyRemoteStreams:()=>{A().catch(_)}}),N=B({degradationPreference:u},{preferredMimeTypesVideoCodecs:this.preferredMimeTypesVideoCodecs,excludeMimeTypesVideoCodecs:this.excludeMimeTypesVideoCodecs});o.logger("callToServer",e);const w=async()=>(o.logger("startCall"),this.sipConnector.call({mediaStream:s,extraHeaders:r,iceServers:i,contentHint:c,offerToReceiveAudio:S,offerToReceiveVideo:C,directionVideo:F,directionAudio:k,sendEncodings:D({mediaStream:s,simulcastEncodings:l,sendEncodings:g}),number:t,onAddedTransceiver:N,ontrack:O}));let b=!1,v;const P=(o.logger("subscribeEnterConference: onEnterConference",E),h??E?this.sipConnector.onSession("enterRoom",({room:d})=>{o.logger("enterRoom",{_room:d,isSuccessProgressCall:b}),v=d,I(v)?h&&h():E&&E({isSuccessProgressCall:b})}):()=>{}),x=d=>(o.logger("onSuccess"),b=!0,A().catch(_),m&&m({isPurgatory:I(v)}),this.sipConnector.onceRaceSession(["ended","failed"],()=>{P(),M&&M()}),d),L=d=>{throw o.logger("onFail"),y&&y(),P(),d},$=()=>{o.logger("onFinish"),T&&T()};return o.logger("onBeforeProgressCall"),p&&p(t),w().then(x).catch(d=>L(d)).finally($)});a(this,"disconnectFromServer",async()=>this.sipConnector.disconnect().then(()=>(o.logger("disconnectFromServer: then"),{isSuccessful:!0})).catch(e=>(o.logger("disconnectFromServer: catch",e),{isSuccessful:!1})));a(this,"answerIncomingCall",async e=>{const{mediaStream:t,extraHeaders:s,iceServers:r,contentHint:i,simulcastEncodings:c,degradationPreference:l,sendEncodings:u,offerToReceiveAudio:g,offerToReceiveVideo:S,directionVideo:C,directionAudio:F,setRemoteStreams:k,onBeforeProgressCall:f,onSuccessProgressCall:p,onEnterPurgatory:m,onEnterConference:h,onFailProgressCall:E,onFinishProgressCall:y,onEndedCall:T}=e,M=this.resolveHandleReadyRemoteStreamsDebounced({onReadyRemoteStreams:k}),A=this.resolveHandleReadyRemoteStreams({onReadyRemoteStreams:()=>{M().catch(_)}}),O=B({degradationPreference:l},{preferredMimeTypesVideoCodecs:this.preferredMimeTypesVideoCodecs,excludeMimeTypesVideoCodecs:this.excludeMimeTypesVideoCodecs});o.logger("answerIncomingCall",e);const N=async()=>this.sipConnector.answerToIncomingCall({mediaStream:t,extraHeaders:s,iceServers:r,contentHint:i,offerToReceiveAudio:g,offerToReceiveVideo:S,directionVideo:C,directionAudio:F,sendEncodings:D({mediaStream:t,simulcastEncodings:c,sendEncodings:u}),onAddedTransceiver:O,ontrack:A}),w=()=>{const{remoteCallerData:d}=this.sipConnector;return d.incomingNumber};let b=!1,v;const P=(o.logger("subscribeEnterConference: onEnterConference",h),m??h?this.sipConnector.onSession("enterRoom",d=>{o.logger("enterRoom",{_room:d,isSuccessProgressCall:b}),v=d,I(v)?m&&m():h&&h({isSuccessProgressCall:b})}):()=>{}),x=d=>(o.logger("onSuccess"),b=!0,M().catch(_),p&&p({isPurgatory:I(v)}),this.sipConnector.onceRaceSession(["ended","failed"],()=>{P(),T&&T()}),d),L=d=>{throw o.logger("onFail"),E&&E(),P(),d},$=()=>{o.logger("onFinish"),y&&y()};if(o.logger("onBeforeProgressCall"),f){const d=w();f(d)}return N().then(x).catch(d=>L(d)).finally($)});a(this,"updatePresentation",async({mediaStream:e,isP2P:t,maxBitrate:s,contentHint:r,simulcastEncodings:i,degradationPreference:c,sendEncodings:l,preferredMimeTypesVideoCodecs:u,excludeMimeTypesVideoCodecs:g})=>{const S=B({degradationPreference:c},{preferredMimeTypesVideoCodecs:u,excludeMimeTypesVideoCodecs:g});return o.logger("updatePresentation"),this.sipConnector.updatePresentation(e,{isP2P:t,maxBitrate:s,contentHint:r,sendEncodings:D({mediaStream:e,simulcastEncodings:i,sendEncodings:l}),onAddedTransceiver:S})});a(this,"startPresentation",async({mediaStream:e,isP2P:t,maxBitrate:s,contentHint:r,simulcastEncodings:i,degradationPreference:c,sendEncodings:l,preferredMimeTypesVideoCodecs:u,excludeMimeTypesVideoCodecs:g},S)=>{const C=B({degradationPreference:c},{preferredMimeTypesVideoCodecs:u,excludeMimeTypesVideoCodecs:g});return o.logger("startPresentation"),this.sipConnector.startPresentation(e,{isP2P:t,maxBitrate:s,contentHint:r,sendEncodings:D({mediaStream:e,simulcastEncodings:i,sendEncodings:l}),onAddedTransceiver:C},S)});a(this,"stopShareSipConnector",async({isP2P:e=!1}={})=>(o.logger("stopShareSipConnector"),this.sipConnector.stopPresentation({isP2P:e}).catch(t=>{o.logger(t)})));a(this,"sendRefusalToTurnOnMic",async()=>{this.sipConnector.isCallActive&&(o.logger("sendRefusalToTurnOnMic"),await this.sipConnector.sendRefusalToTurnOnMic().catch(e=>{o.logger("sendRefusalToTurnOnMic: error",e)}))});a(this,"sendRefusalToTurnOnCam",async()=>{this.sipConnector.isCallActive&&(o.logger("sendRefusalToTurnOnCam"),await this.sipConnector.sendRefusalToTurnOnCam().catch(e=>{o.logger("sendRefusalToTurnOnCam: error",e)}))});a(this,"sendMediaState",async({isEnabledCam:e,isEnabledMic:t})=>{this.sipConnector.isCallActive&&(o.logger("sendMediaState"),await this.sipConnector.sendMediaState({cam:e,mic:t}))});a(this,"replaceMediaStream",async(e,{deleteExisting:t,addMissing:s,forceRenegotiation:r,contentHint:i,simulcastEncodings:c,degradationPreference:l,sendEncodings:u}={})=>{const g=B({degradationPreference:l},{preferredMimeTypesVideoCodecs:this.preferredMimeTypesVideoCodecs,excludeMimeTypesVideoCodecs:this.excludeMimeTypesVideoCodecs});return o.logger("replaceMediaStream"),this.sipConnector.replaceMediaStream(e,{deleteExisting:t,addMissing:s,forceRenegotiation:r,contentHint:i,sendEncodings:D({mediaStream:e,simulcastEncodings:c,sendEncodings:u}),onAddedTransceiver:g})});a(this,"askPermissionToEnableCam",async()=>{this.sipConnector.isCallActive&&(o.logger("askPermissionToEnableCam"),await this.sipConnector.askPermissionToEnableCam())});a(this,"resolveHandleReadyRemoteStreamsDebounced",({onReadyRemoteStreams:e})=>le.debounce(()=>{const t=this.sipConnector.getRemoteStreams();o.logger("remoteStreams",t),t&&e(t)},200));a(this,"resolveHandleReadyRemoteStreams",({onReadyRemoteStreams:e})=>({track:t})=>{Qe(t)&&e()});a(this,"getRemoteStreams",()=>(o.logger("getRemoteStreams"),this.sipConnector.getRemoteStreams()));a(this,"onUseLicense",e=>(o.logger("onUseLicense"),this.sipConnector.onSession("useLicense",e)));a(this,"onMustStopPresentation",e=>(o.logger("onMustStopPresentation"),this.sipConnector.onSession("mustStopPresentation",e)));a(this,"onMoveToSpectators",e=>(o.logger("onMoveToSpectators"),this.sipConnector.onSession(o.PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS,e)));a(this,"onMoveToParticipants",e=>(o.logger("onMoveToParticipants"),this.sipConnector.onSession(o.PARTICIPANT_MOVE_REQUEST_TO_PARTICIPANTS,e)));return this.preferredMimeTypesVideoCodecs=t,this.excludeMimeTypesVideoCodecs=s,this.sipConnector=e,new Proxy(this,{get:(r,i,c)=>{if(typeof i=="string"&&Je.has(i)&&i in this.sipConnector){const u=Reflect.get(this.sipConnector,i,this.sipConnector);return typeof u=="function"?u.bind(this.sipConnector):u}const l=Reflect.get(r,i,c);return typeof l=="function"?l.bind(r):l}})}}exports.EEventsMainCAM=o.EEventsMainCAM;exports.EEventsMic=o.EEventsMic;exports.EEventsSyncMediaState=o.EEventsSyncMediaState;exports.EMimeTypesVideoCodecs=o.EMimeTypesVideoCodecs;exports.EUseLicense=o.EUseLicense;exports.SipConnector=o.SipConnector;exports.causes=o.causes;exports.constants=o.constants;exports.disableDebug=o.disableDebug;exports.enableDebug=o.enableDebug;exports.eventNames=o.eventNames;exports.hasCanceledCallError=o.hasCanceledCallError;exports.hasCanceledStartPresentationError=o.hasCanceledStartPresentationError;exports.setParametersToSender=o.setParametersToSender;exports.debug=_;exports.SipConnectorFacade=Ze;exports.getCodecFromSender=Y;exports.resolveVideoSendingBalancer=je;exports.tools=Ne;
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
var re = Object.defineProperty;
|
|
2
2
|
var ie = (n, e, t) => e in n ? re(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
|
|
3
3
|
var a = (n, e, t) => ie(n, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
-
import { B as Y, N as q, l as c, E as B, s as ce, a as ae, P as ue, b as de } from "./SipConnector-
|
|
5
|
-
import { j as Rn, k as gn, n as yn, m as Tn, S as En, c as Mn, d as bn, f as _n, g as An, e as vn, h as On, i as Nn } from "./SipConnector-
|
|
4
|
+
import { B as Y, N as q, l as c, E as B, s as ce, a as ae, P as ue, b as de } from "./SipConnector-DfaRIKWv.js";
|
|
5
|
+
import { j as Rn, k as gn, n as yn, m as Tn, S as En, c as Mn, d as bn, f as _n, g as An, e as vn, h as On, i as Nn } from "./SipConnector-DfaRIKWv.js";
|
|
6
6
|
import { sequentPromises as le } from "sequent-promises";
|
|
7
7
|
import { createStackPromises as Ce } from "stack-promises";
|
|
8
8
|
import D from "debug";
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function resolveSipUrl(serverUrl: string): (string: string) => string;
|
|
2
|
+
export declare const parseDisplayName: (displayName: string) => string;
|
|
3
|
+
export declare const generateUserId: () => number;
|
|
4
|
+
export declare const hasVideoTracks: (remoteTracks: MediaStreamTrack[]) => boolean;
|