@nuancelabs/js-sdk 0.2.1 → 0.2.2
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/index.js +57 -5
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -4,7 +4,7 @@ function isRecord(value) {
|
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
// src/core/sdk-version.ts
|
|
7
|
-
var SDK_HEADER = `js/${"0.2.
|
|
7
|
+
var SDK_HEADER = `js/${"0.2.2"}`;
|
|
8
8
|
|
|
9
9
|
// src/utils.ts
|
|
10
10
|
function normalizeHost(host) {
|
|
@@ -1167,6 +1167,15 @@ function microphonePublishOptions(resilient) {
|
|
|
1167
1167
|
return;
|
|
1168
1168
|
return { dtx: false, audioPreset: AudioPresets.speech };
|
|
1169
1169
|
}
|
|
1170
|
+
var SCREEN_CAPTURE = {
|
|
1171
|
+
audio: false,
|
|
1172
|
+
resolution: { width: 1920, height: 1080, frameRate: 2 },
|
|
1173
|
+
contentHint: "detail"
|
|
1174
|
+
};
|
|
1175
|
+
var SCREEN_PUBLISH = {
|
|
1176
|
+
screenShareEncoding: { maxBitrate: 1500000, maxFramerate: 2 },
|
|
1177
|
+
simulcast: false
|
|
1178
|
+
};
|
|
1170
1179
|
|
|
1171
1180
|
class LiveKitUserParticipant {
|
|
1172
1181
|
room;
|
|
@@ -1174,6 +1183,8 @@ class LiveKitUserParticipant {
|
|
|
1174
1183
|
onSpeakingChanged;
|
|
1175
1184
|
onMicrophoneChanged;
|
|
1176
1185
|
onCameraChanged;
|
|
1186
|
+
onScreenShareChanged;
|
|
1187
|
+
screenTrack;
|
|
1177
1188
|
inputs = {
|
|
1178
1189
|
audioinput: { changing: false, unavailable: false },
|
|
1179
1190
|
videoinput: { changing: false, unavailable: false }
|
|
@@ -1188,7 +1199,7 @@ class LiveKitUserParticipant {
|
|
|
1188
1199
|
lastAudioSource = null;
|
|
1189
1200
|
_isSpeaking = false;
|
|
1190
1201
|
speakingHandler = null;
|
|
1191
|
-
constructor(room, onTracksChanged, onSpeakingChanged, onMicrophoneChanged, onCameraChanged = () => {}, initialCameraFacing, resilient = false) {
|
|
1202
|
+
constructor(room, onTracksChanged, onSpeakingChanged, onMicrophoneChanged, onCameraChanged = () => {}, initialCameraFacing, resilient = false, onScreenShareChanged = () => {}) {
|
|
1192
1203
|
this.room = room;
|
|
1193
1204
|
this.onTracksChanged = onTracksChanged;
|
|
1194
1205
|
this.onSpeakingChanged = onSpeakingChanged;
|
|
@@ -1196,7 +1207,9 @@ class LiveKitUserParticipant {
|
|
|
1196
1207
|
this.onCameraChanged = onCameraChanged;
|
|
1197
1208
|
this.initialCameraFacing = initialCameraFacing;
|
|
1198
1209
|
this.microphoneOptions = microphonePublishOptions(resilient);
|
|
1210
|
+
this.onScreenShareChanged = onScreenShareChanged;
|
|
1199
1211
|
this.room.on(RoomEvent2.ActiveDeviceChanged, this.handleDeviceChanged);
|
|
1212
|
+
this.room.localParticipant.on(ParticipantEvent2.LocalTrackUnpublished, this.handleTrackUnpublished);
|
|
1200
1213
|
}
|
|
1201
1214
|
updateTracks() {
|
|
1202
1215
|
let changed = false;
|
|
@@ -1357,9 +1370,14 @@ class LiveKitUserParticipant {
|
|
|
1357
1370
|
this.notifyInput(kind);
|
|
1358
1371
|
}
|
|
1359
1372
|
};
|
|
1373
|
+
handleTrackUnpublished = (publication) => {
|
|
1374
|
+
if (!this.disposed && publication.source === Track5.Source.ScreenShare)
|
|
1375
|
+
this.onScreenShareChanged();
|
|
1376
|
+
};
|
|
1360
1377
|
cleanup() {
|
|
1361
1378
|
this.disposed = true;
|
|
1362
1379
|
this.room.off(RoomEvent2.ActiveDeviceChanged, this.handleDeviceChanged);
|
|
1380
|
+
this.room.localParticipant.off(ParticipantEvent2.LocalTrackUnpublished, this.handleTrackUnpublished);
|
|
1363
1381
|
if (this.inputs.audioinput.changing)
|
|
1364
1382
|
this.inputTrack("audioinput")?.stop();
|
|
1365
1383
|
if (this.inputs.videoinput.changing)
|
|
@@ -1437,10 +1455,44 @@ class LiveKitUserParticipant {
|
|
|
1437
1455
|
get isVideoEnabled() {
|
|
1438
1456
|
return this.room.localParticipant.isCameraEnabled;
|
|
1439
1457
|
}
|
|
1458
|
+
async startScreenShare() {
|
|
1459
|
+
await this.setScreenShare(true);
|
|
1460
|
+
}
|
|
1461
|
+
async stopScreenShare() {
|
|
1462
|
+
const track = this.screenTrack;
|
|
1463
|
+
this.screenTrack = undefined;
|
|
1464
|
+
try {
|
|
1465
|
+
if (!this.disposed)
|
|
1466
|
+
await this.setScreenShare(false);
|
|
1467
|
+
} finally {
|
|
1468
|
+
track?.stop();
|
|
1469
|
+
}
|
|
1470
|
+
}
|
|
1471
|
+
get isScreenSharing() {
|
|
1472
|
+
return this.room.localParticipant.isScreenShareEnabled;
|
|
1473
|
+
}
|
|
1474
|
+
async setScreenShare(enabled) {
|
|
1475
|
+
if (this.disposed)
|
|
1476
|
+
throw new Error("Participant is disconnected");
|
|
1477
|
+
try {
|
|
1478
|
+
const publication = await this.room.localParticipant.setScreenShareEnabled(enabled, SCREEN_CAPTURE, SCREEN_PUBLISH);
|
|
1479
|
+
if (this.disposed)
|
|
1480
|
+
publication?.track?.stop();
|
|
1481
|
+
else if (enabled)
|
|
1482
|
+
this.screenTrack = publication?.track;
|
|
1483
|
+
} catch (error) {
|
|
1484
|
+
throw new MediaAccessError(error);
|
|
1485
|
+
} finally {
|
|
1486
|
+
if (!this.disposed)
|
|
1487
|
+
this.onScreenShareChanged();
|
|
1488
|
+
}
|
|
1489
|
+
}
|
|
1440
1490
|
releaseDevices() {
|
|
1441
1491
|
for (const pub of this.room.localParticipant.trackPublications.values()) {
|
|
1442
1492
|
pub.track?.stop();
|
|
1443
1493
|
}
|
|
1494
|
+
this.screenTrack?.stop();
|
|
1495
|
+
this.screenTrack = undefined;
|
|
1444
1496
|
}
|
|
1445
1497
|
startSpeakingDetection() {
|
|
1446
1498
|
this.stopSpeakingDetection();
|
|
@@ -1601,7 +1653,7 @@ class LiveKitConversation {
|
|
|
1601
1653
|
type: "speaking-changed",
|
|
1602
1654
|
participant: "user",
|
|
1603
1655
|
isSpeaking
|
|
1604
|
-
}), () => this.emit({ type: "microphone-changed" }), () => this.emit({ type: "camera-changed" }), this.cameraFacing, this.resilient);
|
|
1656
|
+
}), () => this.emit({ type: "microphone-changed" }), () => this.emit({ type: "camera-changed" }), this.cameraFacing, this.resilient, () => this.emit({ type: "screen-share-changed" }));
|
|
1605
1657
|
this._user.startSpeakingDetection();
|
|
1606
1658
|
try {
|
|
1607
1659
|
await this._user.unmuteAudio();
|
|
@@ -1677,7 +1729,7 @@ class LiveKitConversation {
|
|
|
1677
1729
|
}
|
|
1678
1730
|
onChange(handler) {
|
|
1679
1731
|
return this.onEvent((event) => {
|
|
1680
|
-
if (event.type !== "data-event")
|
|
1732
|
+
if (event.type !== "data-event" && event.type !== "screen-share-changed")
|
|
1681
1733
|
handler(event);
|
|
1682
1734
|
});
|
|
1683
1735
|
}
|
|
@@ -2321,7 +2373,7 @@ class NuanceConversation {
|
|
|
2321
2373
|
}
|
|
2322
2374
|
onChange(handler) {
|
|
2323
2375
|
return this.onEvent((event) => {
|
|
2324
|
-
if (event.type !== "data-event")
|
|
2376
|
+
if (event.type !== "data-event" && event.type !== "screen-share-changed")
|
|
2325
2377
|
handler(event);
|
|
2326
2378
|
});
|
|
2327
2379
|
}
|