@nuancelabs/js-sdk 0.1.1 → 0.1.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 +32 -1
- 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.1.
|
|
7
|
+
var SDK_HEADER = `js/${"0.1.2"}`;
|
|
8
8
|
|
|
9
9
|
// src/utils.ts
|
|
10
10
|
function normalizeHost(host) {
|
|
@@ -1078,6 +1078,9 @@ function parseSessionEvent(payload) {
|
|
|
1078
1078
|
}
|
|
1079
1079
|
};
|
|
1080
1080
|
}
|
|
1081
|
+
if (decoded.type === "floor") {
|
|
1082
|
+
return { type: "floor", speaking: decoded.state === "speaking" };
|
|
1083
|
+
}
|
|
1081
1084
|
if (decoded.type === "session.status" && decoded.status === "ended") {
|
|
1082
1085
|
return {
|
|
1083
1086
|
type: "ended",
|
|
@@ -1520,6 +1523,7 @@ class LiveKitConversation {
|
|
|
1520
1523
|
eventsRegistered = false;
|
|
1521
1524
|
sessionEnded = false;
|
|
1522
1525
|
speaksProtocol = false;
|
|
1526
|
+
avatarSpeaking = false;
|
|
1523
1527
|
answered = null;
|
|
1524
1528
|
commands = new Map;
|
|
1525
1529
|
commandCount = 0;
|
|
@@ -1665,6 +1669,12 @@ class LiveKitConversation {
|
|
|
1665
1669
|
}
|
|
1666
1670
|
return this.command({ type: "scene.background", background });
|
|
1667
1671
|
}
|
|
1672
|
+
async sendText(text) {
|
|
1673
|
+
const line = text.trim();
|
|
1674
|
+
if (!line)
|
|
1675
|
+
throw new Error("Nothing to send: the text is blank");
|
|
1676
|
+
return this.command({ type: "input.text", text: line, respond: true });
|
|
1677
|
+
}
|
|
1668
1678
|
onChange(handler) {
|
|
1669
1679
|
return this.onEvent((event) => {
|
|
1670
1680
|
if (event.type !== "data-event")
|
|
@@ -1748,6 +1758,8 @@ class LiveKitConversation {
|
|
|
1748
1758
|
const mapped = mapConnectionState(lkState, this.resilient && this.everConnected);
|
|
1749
1759
|
if (mapped === "connected")
|
|
1750
1760
|
this.everConnected = true;
|
|
1761
|
+
if (lkState === ConnectionState2.Reconnecting)
|
|
1762
|
+
this.setAvatarSpeaking(false);
|
|
1751
1763
|
if (mapped !== this._state) {
|
|
1752
1764
|
this.setState(mapped);
|
|
1753
1765
|
}
|
|
@@ -1787,6 +1799,7 @@ class LiveKitConversation {
|
|
|
1787
1799
|
this.room.on(RoomEvent3.Disconnected, () => {
|
|
1788
1800
|
this.stats?.abandon();
|
|
1789
1801
|
this.stats = null;
|
|
1802
|
+
this.setAvatarSpeaking(false);
|
|
1790
1803
|
this.stopPresentation();
|
|
1791
1804
|
this.stopReadyFallback();
|
|
1792
1805
|
this.stopLayerFallback();
|
|
@@ -1902,6 +1915,8 @@ class LiveKitConversation {
|
|
|
1902
1915
|
this.commands.delete(id);
|
|
1903
1916
|
settle({ status: "rejected", error: `unknown command ${type}` });
|
|
1904
1917
|
}
|
|
1918
|
+
} else if (event.type === "floor") {
|
|
1919
|
+
this.setAvatarSpeaking(event.speaking);
|
|
1905
1920
|
} else if (event.type === "ended") {
|
|
1906
1921
|
this.answered?.();
|
|
1907
1922
|
if (!event.byClient)
|
|
@@ -1934,6 +1949,16 @@ class LiveKitConversation {
|
|
|
1934
1949
|
this.readyFallback?.stop();
|
|
1935
1950
|
this.readyFallback = null;
|
|
1936
1951
|
}
|
|
1952
|
+
setAvatarSpeaking(speaking) {
|
|
1953
|
+
if (speaking === this.avatarSpeaking)
|
|
1954
|
+
return;
|
|
1955
|
+
this.avatarSpeaking = speaking;
|
|
1956
|
+
this.emit({
|
|
1957
|
+
type: "speaking-changed",
|
|
1958
|
+
participant: "avatar",
|
|
1959
|
+
isSpeaking: speaking
|
|
1960
|
+
});
|
|
1961
|
+
}
|
|
1937
1962
|
markAvatarReady() {
|
|
1938
1963
|
this.stopReadyFallback();
|
|
1939
1964
|
if (this._avatar.isReady)
|
|
@@ -2281,6 +2306,12 @@ class NuanceConversation {
|
|
|
2281
2306
|
}
|
|
2282
2307
|
return this.delegate.setBackground(background);
|
|
2283
2308
|
}
|
|
2309
|
+
async sendText(text) {
|
|
2310
|
+
if (!this.delegate) {
|
|
2311
|
+
throw new Error("Not connected — call connect() first");
|
|
2312
|
+
}
|
|
2313
|
+
return this.delegate.sendText(text);
|
|
2314
|
+
}
|
|
2284
2315
|
onChange(handler) {
|
|
2285
2316
|
return this.onEvent((event) => {
|
|
2286
2317
|
if (event.type !== "data-event")
|