@ermis-network/ermis-chat-sdk 1.0.1 → 1.0.3
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/bin/init-call.js +52 -0
- package/dist/index.browser.cjs +174 -95
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.full-bundle.min.js +15 -15
- package/dist/index.browser.full-bundle.min.js.map +1 -1
- package/dist/index.browser.mjs +173 -95
- package/dist/index.browser.mjs.map +1 -1
- package/dist/index.cjs +174 -95
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +29 -9
- package/dist/index.d.ts +29 -9
- package/dist/index.mjs +173 -95
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -2
- package/public/call_incoming.mp3 +0 -0
- package/public/call_outgoing.mp3 +0 -0
- package/public/ermis_call_node_wasm_bg.wasm +0 -0
- package/src/client.ts +17 -6
- package/src/ermis_call_node.ts +77 -47
- package/src/index.ts +2 -1
- package/src/signal_message.ts +121 -71
package/dist/index.browser.mjs
CHANGED
|
@@ -3547,17 +3547,24 @@ var ErmisChat = class _ErmisChat {
|
|
|
3547
3547
|
async unpinChannel(channelType, channelId) {
|
|
3548
3548
|
return await this.post(this.baseURL + `/channels/${channelType}/${channelId}/unpin`);
|
|
3549
3549
|
}
|
|
3550
|
-
channel(channelType,
|
|
3550
|
+
channel(channelType, channelIDOrCustom, custom) {
|
|
3551
3551
|
if (!this.userID) {
|
|
3552
3552
|
throw Error("Call connectUser before creating a channel");
|
|
3553
3553
|
}
|
|
3554
3554
|
if (~channelType.indexOf(":")) {
|
|
3555
3555
|
throw Error(`Invalid channel group ${channelType}, can't contain the : character`);
|
|
3556
3556
|
}
|
|
3557
|
-
|
|
3557
|
+
let channelID = void 0;
|
|
3558
|
+
let customData = custom || {};
|
|
3559
|
+
if (typeof channelIDOrCustom === "string") {
|
|
3560
|
+
channelID = channelIDOrCustom;
|
|
3561
|
+
} else if (typeof channelIDOrCustom === "object" && channelIDOrCustom !== null) {
|
|
3562
|
+
customData = channelIDOrCustom;
|
|
3563
|
+
}
|
|
3564
|
+
return this.getChannelById(channelType, channelID, customData);
|
|
3558
3565
|
}
|
|
3559
3566
|
getChannelById = (channelType, channelID, custom) => {
|
|
3560
|
-
const cid = `${channelType}:${channelID}`;
|
|
3567
|
+
const cid = `${channelType}:${channelID || ""}`;
|
|
3561
3568
|
if (cid in this.activeChannels && !this.activeChannels[cid].disconnected) {
|
|
3562
3569
|
const channel2 = this.activeChannels[cid];
|
|
3563
3570
|
if (Object.keys(custom).length > 0) {
|
|
@@ -3600,7 +3607,7 @@ var ErmisChat = class _ErmisChat {
|
|
|
3600
3607
|
return pinExpires;
|
|
3601
3608
|
}
|
|
3602
3609
|
getUserAgent() {
|
|
3603
|
-
return this.userAgent || `ermis-chat-sdk-javascript-client-${this.node ? "node" : "browser"}-${"1.0.
|
|
3610
|
+
return this.userAgent || `ermis-chat-sdk-javascript-client-${this.node ? "node" : "browser"}-${"1.0.3"}`;
|
|
3604
3611
|
}
|
|
3605
3612
|
setUserAgent(userAgent) {
|
|
3606
3613
|
this.userAgent = userAgent;
|
|
@@ -6309,21 +6316,38 @@ var ErmisCallNode = class {
|
|
|
6309
6316
|
const mediaConstraints = await this.getMediaConstraints();
|
|
6310
6317
|
try {
|
|
6311
6318
|
const stream = await navigator.mediaDevices.getUserMedia(mediaConstraints);
|
|
6312
|
-
|
|
6313
|
-
|
|
6314
|
-
|
|
6315
|
-
|
|
6319
|
+
return this.applyLocalStream(stream);
|
|
6320
|
+
} catch (error) {
|
|
6321
|
+
console.warn("Error getting user media:", error?.message);
|
|
6322
|
+
if (this.callType === "video" && mediaConstraints.video) {
|
|
6323
|
+
try {
|
|
6324
|
+
const audioOnlyStream = await navigator.mediaDevices.getUserMedia({
|
|
6325
|
+
audio: mediaConstraints.audio,
|
|
6326
|
+
video: false
|
|
6327
|
+
});
|
|
6328
|
+
this.setConnectionMessage("Camera not available, using audio only");
|
|
6329
|
+
return this.applyLocalStream(audioOnlyStream);
|
|
6330
|
+
} catch {
|
|
6331
|
+
}
|
|
6316
6332
|
}
|
|
6317
|
-
if (this.
|
|
6318
|
-
this.
|
|
6333
|
+
if (typeof this.onError === "function") {
|
|
6334
|
+
this.onError("No microphone or camera found. Please check your device.");
|
|
6319
6335
|
}
|
|
6320
|
-
this.localStream = stream;
|
|
6321
|
-
return stream;
|
|
6322
|
-
} catch (error) {
|
|
6323
|
-
console.error("Error getting user media:", error);
|
|
6324
6336
|
return null;
|
|
6325
6337
|
}
|
|
6326
6338
|
}
|
|
6339
|
+
applyLocalStream(stream) {
|
|
6340
|
+
if (this.callStatus === "ended" /* ENDED */) {
|
|
6341
|
+
stream.getTracks().forEach((track) => track.stop());
|
|
6342
|
+
this.destroy();
|
|
6343
|
+
return;
|
|
6344
|
+
}
|
|
6345
|
+
if (this.onLocalStream) {
|
|
6346
|
+
this.onLocalStream(stream);
|
|
6347
|
+
}
|
|
6348
|
+
this.localStream = stream;
|
|
6349
|
+
return stream;
|
|
6350
|
+
}
|
|
6327
6351
|
setConnectionMessage(message) {
|
|
6328
6352
|
if (typeof this.onConnectionMessageChange === "function") {
|
|
6329
6353
|
this.onConnectionMessageChange(message);
|
|
@@ -6368,20 +6392,10 @@ var ErmisCallNode = class {
|
|
|
6368
6392
|
this.isDestroyed = false;
|
|
6369
6393
|
this.callStatus = "";
|
|
6370
6394
|
this.callType = is_video ? "video" : "audio";
|
|
6371
|
-
await this.startLocalStream();
|
|
6372
|
-
if (this.callStatus === "ended" /* ENDED */) return;
|
|
6373
6395
|
this.setUserInfo(cid, eventUserId);
|
|
6374
6396
|
this.setCallStatus("ringing" /* RINGING */);
|
|
6375
6397
|
this.cid = cid || "";
|
|
6376
6398
|
this.metadata = metadata || {};
|
|
6377
|
-
console.log("----metadata---", metadata);
|
|
6378
|
-
if (eventUserId !== this.userID) {
|
|
6379
|
-
await this.initialize();
|
|
6380
|
-
}
|
|
6381
|
-
if (this.localStream && this.mediaSender && this.mediaReceiver) {
|
|
6382
|
-
this.mediaSender?.initEncoders(this.localStream);
|
|
6383
|
-
this.mediaReceiver?.initDecoders(this.callType);
|
|
6384
|
-
}
|
|
6385
6399
|
if (typeof this.onCallEvent === "function") {
|
|
6386
6400
|
this.onCallEvent({
|
|
6387
6401
|
type: eventUserId !== this.userID ? "incoming" : "outgoing",
|
|
@@ -6392,6 +6406,15 @@ var ErmisCallNode = class {
|
|
|
6392
6406
|
metadata: this.metadata
|
|
6393
6407
|
});
|
|
6394
6408
|
}
|
|
6409
|
+
await this.startLocalStream();
|
|
6410
|
+
if (this.callStatus === "ended" /* ENDED */) return;
|
|
6411
|
+
if (eventUserId !== this.userID) {
|
|
6412
|
+
await this.initialize();
|
|
6413
|
+
}
|
|
6414
|
+
if (this.localStream && this.mediaSender && this.mediaReceiver) {
|
|
6415
|
+
this.mediaSender?.initEncoders(this.localStream);
|
|
6416
|
+
this.mediaReceiver?.initDecoders(this.callType);
|
|
6417
|
+
}
|
|
6395
6418
|
if (eventUserId === this.userID) {
|
|
6396
6419
|
if (this.missCallTimeout) clearTimeout(this.missCallTimeout);
|
|
6397
6420
|
this.missCallTimeout = setTimeout(async () => {
|
|
@@ -6652,21 +6675,30 @@ var ErmisCallNode = class {
|
|
|
6652
6675
|
}
|
|
6653
6676
|
async stopScreenShare() {
|
|
6654
6677
|
const mediaConstraints = await this.getMediaConstraints();
|
|
6655
|
-
|
|
6656
|
-
|
|
6657
|
-
|
|
6658
|
-
|
|
6659
|
-
|
|
6660
|
-
|
|
6661
|
-
|
|
6662
|
-
|
|
6663
|
-
|
|
6664
|
-
|
|
6665
|
-
|
|
6666
|
-
|
|
6667
|
-
|
|
6668
|
-
|
|
6669
|
-
|
|
6678
|
+
try {
|
|
6679
|
+
const cameraStream = await navigator.mediaDevices.getUserMedia({
|
|
6680
|
+
video: mediaConstraints.video,
|
|
6681
|
+
audio: false
|
|
6682
|
+
});
|
|
6683
|
+
const cameraTrack = cameraStream.getVideoTracks()[0];
|
|
6684
|
+
if (this.localStream) {
|
|
6685
|
+
this.localStream.getVideoTracks().forEach((track) => {
|
|
6686
|
+
track.stop();
|
|
6687
|
+
this.localStream?.removeTrack(track);
|
|
6688
|
+
});
|
|
6689
|
+
this.localStream.addTrack(cameraTrack);
|
|
6690
|
+
} else {
|
|
6691
|
+
this.localStream = cameraStream;
|
|
6692
|
+
}
|
|
6693
|
+
if (this.onLocalStream) {
|
|
6694
|
+
this.onLocalStream(this.localStream);
|
|
6695
|
+
this.mediaSender?.replaceVideoTrack(this.localStream.getVideoTracks()[0]);
|
|
6696
|
+
}
|
|
6697
|
+
if (typeof this.onScreenShareChange === "function") {
|
|
6698
|
+
this.onScreenShareChange(false);
|
|
6699
|
+
}
|
|
6700
|
+
} catch (error) {
|
|
6701
|
+
console.error("Error stopping screen share and reverting to camera:", error);
|
|
6670
6702
|
}
|
|
6671
6703
|
}
|
|
6672
6704
|
async toggleMic(enabled) {
|
|
@@ -6933,7 +6965,7 @@ var ErmisAuthProvider = class {
|
|
|
6933
6965
|
return data;
|
|
6934
6966
|
}
|
|
6935
6967
|
getUserAgent() {
|
|
6936
|
-
return this.userAgent || `ermis-chat-sdk-javascript-client-${this.node ? "node" : "browser"}-${"1.0.
|
|
6968
|
+
return this.userAgent || `ermis-chat-sdk-javascript-client-${this.node ? "node" : "browser"}-${"1.0.3"}`;
|
|
6937
6969
|
}
|
|
6938
6970
|
setUserAgent(userAgent) {
|
|
6939
6971
|
this.userAgent = userAgent;
|
|
@@ -7166,70 +7198,116 @@ function parseSystemMessage(value, userMap) {
|
|
|
7166
7198
|
}
|
|
7167
7199
|
|
|
7168
7200
|
// src/signal_message.ts
|
|
7169
|
-
|
|
7170
|
-
|
|
7171
|
-
|
|
7172
|
-
|
|
7173
|
-
|
|
7174
|
-
|
|
7175
|
-
|
|
7176
|
-
|
|
7177
|
-
|
|
7201
|
+
var CallType = {
|
|
7202
|
+
AUDIO: "audio",
|
|
7203
|
+
VIDEO: "video"
|
|
7204
|
+
};
|
|
7205
|
+
function formatDuration(durationMs) {
|
|
7206
|
+
if (!durationMs) return "";
|
|
7207
|
+
const ms = parseInt(durationMs, 10);
|
|
7208
|
+
if (isNaN(ms) || ms <= 0) return "";
|
|
7209
|
+
const totalSeconds = Math.floor(ms / 1e3);
|
|
7210
|
+
const minutes = Math.floor(totalSeconds / 60);
|
|
7211
|
+
const seconds = totalSeconds % 60;
|
|
7212
|
+
return `${minutes} min, ${seconds} sec`;
|
|
7178
7213
|
}
|
|
7179
|
-
function parseSignalMessage(value,
|
|
7180
|
-
if (!value || typeof value !== "string") return
|
|
7214
|
+
function parseSignalMessage(value, myUserId) {
|
|
7215
|
+
if (!value || typeof value !== "string") return null;
|
|
7181
7216
|
const trimmed = value.trim();
|
|
7182
|
-
if (!trimmed) return
|
|
7217
|
+
if (!trimmed) return null;
|
|
7183
7218
|
const parts = trimmed.split(" ");
|
|
7184
|
-
const
|
|
7185
|
-
const
|
|
7186
|
-
const
|
|
7187
|
-
|
|
7188
|
-
|
|
7189
|
-
|
|
7190
|
-
|
|
7191
|
-
|
|
7192
|
-
|
|
7193
|
-
|
|
7194
|
-
|
|
7195
|
-
|
|
7196
|
-
|
|
7197
|
-
|
|
7198
|
-
|
|
7199
|
-
|
|
7200
|
-
|
|
7201
|
-
|
|
7202
|
-
case
|
|
7203
|
-
|
|
7204
|
-
|
|
7205
|
-
|
|
7206
|
-
|
|
7207
|
-
|
|
7208
|
-
|
|
7209
|
-
|
|
7210
|
-
|
|
7211
|
-
|
|
7212
|
-
|
|
7213
|
-
|
|
7214
|
-
|
|
7215
|
-
|
|
7216
|
-
|
|
7217
|
-
|
|
7218
|
-
|
|
7219
|
-
|
|
7220
|
-
|
|
7221
|
-
case
|
|
7222
|
-
|
|
7223
|
-
|
|
7224
|
-
|
|
7225
|
-
|
|
7219
|
+
const number = parseInt(parts[0], 10);
|
|
7220
|
+
const callerId = parts[1] ?? "";
|
|
7221
|
+
const isMe = myUserId === callerId;
|
|
7222
|
+
let enderId = "";
|
|
7223
|
+
let duration = "";
|
|
7224
|
+
let callType = "";
|
|
7225
|
+
let color = "";
|
|
7226
|
+
if (number === 3 || number === 6) {
|
|
7227
|
+
enderId = parts[2] ?? "";
|
|
7228
|
+
duration = parts[3] === "0" ? "" : parts[3] ?? "";
|
|
7229
|
+
}
|
|
7230
|
+
let text;
|
|
7231
|
+
switch (number) {
|
|
7232
|
+
case 1:
|
|
7233
|
+
text = isMe ? "Calling..." : "Incoming audio call...";
|
|
7234
|
+
callType = CallType.AUDIO;
|
|
7235
|
+
color = "#54D62C";
|
|
7236
|
+
break;
|
|
7237
|
+
case 2:
|
|
7238
|
+
text = isMe ? "Outgoing audio call" : "You missed audio call";
|
|
7239
|
+
callType = CallType.AUDIO;
|
|
7240
|
+
color = "#FF4842";
|
|
7241
|
+
break;
|
|
7242
|
+
case 3:
|
|
7243
|
+
if (duration) {
|
|
7244
|
+
text = isMe ? "Outgoing audio call" : "Incoming audio call";
|
|
7245
|
+
color = "#54D62C";
|
|
7246
|
+
} else {
|
|
7247
|
+
if (enderId === myUserId) {
|
|
7248
|
+
text = "You cancel audio call";
|
|
7249
|
+
} else {
|
|
7250
|
+
text = "You missed audio call";
|
|
7251
|
+
}
|
|
7252
|
+
color = "#FF4842";
|
|
7253
|
+
}
|
|
7254
|
+
callType = CallType.AUDIO;
|
|
7255
|
+
break;
|
|
7256
|
+
case 4:
|
|
7257
|
+
text = isMe ? "Calling..." : "Incoming video call...";
|
|
7258
|
+
callType = CallType.VIDEO;
|
|
7259
|
+
color = "#54D62C";
|
|
7260
|
+
break;
|
|
7261
|
+
case 5:
|
|
7262
|
+
text = isMe ? "Outgoing video call" : "You missed video call";
|
|
7263
|
+
callType = CallType.VIDEO;
|
|
7264
|
+
color = "#FF4842";
|
|
7265
|
+
break;
|
|
7266
|
+
case 6:
|
|
7267
|
+
if (duration) {
|
|
7268
|
+
text = isMe ? "Outgoing video call" : "Incoming video call";
|
|
7269
|
+
color = "#54D62C";
|
|
7270
|
+
} else {
|
|
7271
|
+
if (enderId === myUserId) {
|
|
7272
|
+
text = "You cancel video call";
|
|
7273
|
+
} else {
|
|
7274
|
+
text = "You missed video call";
|
|
7275
|
+
}
|
|
7276
|
+
color = "#FF4842";
|
|
7277
|
+
}
|
|
7278
|
+
callType = CallType.VIDEO;
|
|
7279
|
+
break;
|
|
7280
|
+
case 7:
|
|
7281
|
+
text = isMe ? "Recipient rejected audio call" : "You rejected audio call";
|
|
7282
|
+
callType = CallType.AUDIO;
|
|
7283
|
+
color = "#FF4842";
|
|
7284
|
+
break;
|
|
7285
|
+
case 8:
|
|
7286
|
+
text = isMe ? "Recipient rejected video call" : "You rejected video call";
|
|
7287
|
+
callType = CallType.VIDEO;
|
|
7288
|
+
color = "#FF4842";
|
|
7289
|
+
break;
|
|
7290
|
+
case 9:
|
|
7291
|
+
text = isMe ? "Recipient was busy" : "You missed audio call";
|
|
7292
|
+
callType = CallType.AUDIO;
|
|
7293
|
+
color = "#FF4842";
|
|
7294
|
+
break;
|
|
7295
|
+
case 10:
|
|
7296
|
+
text = isMe ? "Recipient was busy" : "You missed video call";
|
|
7297
|
+
callType = CallType.VIDEO;
|
|
7298
|
+
color = "#FF4842";
|
|
7299
|
+
break;
|
|
7226
7300
|
default:
|
|
7227
|
-
|
|
7301
|
+
text = trimmed;
|
|
7302
|
+
callType = "";
|
|
7303
|
+
color = "";
|
|
7228
7304
|
}
|
|
7305
|
+
return { text, duration: formatDuration(duration), callType, color };
|
|
7229
7306
|
}
|
|
7230
7307
|
export {
|
|
7231
7308
|
CallAction,
|
|
7232
7309
|
CallStatus,
|
|
7310
|
+
CallType,
|
|
7233
7311
|
Channel,
|
|
7234
7312
|
ChannelState,
|
|
7235
7313
|
ClientState,
|