@kaltura-sdk/avatars 1.21.0 → 1.21.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/index.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { UnisphereLoggerFactory, TinyDataStore, TinyPubSub, performanceMonitor,
|
|
1
|
+
import { UnisphereLoggerFactory, TinyDataStore, TinyPubSub, performanceMonitor, getOrCreateGlobalTinyDataStore } from '@unisphere/core';
|
|
2
2
|
import { getPartnerIdFromKs } from '@unisphere/runtime-js';
|
|
3
3
|
import { DisconnectReasons, getAvatarDefaultCapabilities, resolveActiveContextType, AvatarConnectionStatus } from '@unisphere/genie-types';
|
|
4
4
|
import { z as z$1 } from 'zod/mini';
|
|
@@ -1920,18 +1920,6 @@ PERFORMANCE OF THIS SOFTWARE.
|
|
|
1920
1920
|
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
1921
1921
|
|
|
1922
1922
|
|
|
1923
|
-
function __rest(s, e) {
|
|
1924
|
-
var t = {};
|
|
1925
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
1926
|
-
t[p] = s[p];
|
|
1927
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
1928
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
1929
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
1930
|
-
t[p[i]] = s[p[i]];
|
|
1931
|
-
}
|
|
1932
|
-
return t;
|
|
1933
|
-
}
|
|
1934
|
-
|
|
1935
1923
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
1936
1924
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
1937
1925
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -23840,239 +23828,6 @@ const avatarConnectionMachine = setup({
|
|
|
23840
23828
|
}
|
|
23841
23829
|
});
|
|
23842
23830
|
|
|
23843
|
-
const NAMESPACE = 'unisphere-global-tiny-data-store';
|
|
23844
|
-
const REGISTRY_KEY = 'globalTinyDataStore';
|
|
23845
|
-
function getRegistry(logger) {
|
|
23846
|
-
return getOrCreateGlobalUnisphere(REGISTRY_KEY, logger, {
|
|
23847
|
-
windowId: `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`,
|
|
23848
|
-
// null prototype: ids come off the wire, `__proto__`/`constructor` must be plain keys
|
|
23849
|
-
entries: Object.create(null),
|
|
23850
|
-
listening: false,
|
|
23851
|
-
lastTs: 0
|
|
23852
|
-
}).value;
|
|
23853
|
-
}
|
|
23854
|
-
// `length`/`frames` are readable cross-origin, so this reaches every frame
|
|
23855
|
-
// regardless of nesting depth or origin; we can't know which one holds an avatar.
|
|
23856
|
-
function collectWindows(root) {
|
|
23857
|
-
const result = [];
|
|
23858
|
-
const visit = w => {
|
|
23859
|
-
result.push(w);
|
|
23860
|
-
let count = 0;
|
|
23861
|
-
try {
|
|
23862
|
-
count = w.length;
|
|
23863
|
-
} catch (_a) {
|
|
23864
|
-
return;
|
|
23865
|
-
}
|
|
23866
|
-
for (let i = 0; i < count; i++) {
|
|
23867
|
-
try {
|
|
23868
|
-
visit(w.frames[i]);
|
|
23869
|
-
} catch (_b) {
|
|
23870
|
-
// frame navigated away or became inaccessible while enumerating
|
|
23871
|
-
}
|
|
23872
|
-
}
|
|
23873
|
-
};
|
|
23874
|
-
visit(root);
|
|
23875
|
-
return result;
|
|
23876
|
-
}
|
|
23877
|
-
// Cache frames seen by this window so a `pagehide` message dispatched by an iframe
|
|
23878
|
-
// just before removal is still recognized even after `contentWindow` detaches from the DOM.
|
|
23879
|
-
const knownFrames = new WeakSet();
|
|
23880
|
-
function getPageWindows(win) {
|
|
23881
|
-
var _a;
|
|
23882
|
-
const current = collectWindows((_a = win.top) !== null && _a !== void 0 ? _a : win);
|
|
23883
|
-
for (const w of current) {
|
|
23884
|
-
knownFrames.add(w);
|
|
23885
|
-
}
|
|
23886
|
-
return current;
|
|
23887
|
-
}
|
|
23888
|
-
function isKnownPageWindow(win, source) {
|
|
23889
|
-
if (getPageWindows(win).includes(source)) {
|
|
23890
|
-
return true;
|
|
23891
|
-
}
|
|
23892
|
-
return knownFrames.has(source);
|
|
23893
|
-
}
|
|
23894
|
-
function post(target, message) {
|
|
23895
|
-
try {
|
|
23896
|
-
// '*' because the host topology (and origins) are unknown. The payload is
|
|
23897
|
-
// non-sensitive and receivers only accept messages from this page's frames.
|
|
23898
|
-
target.postMessage(message, '*');
|
|
23899
|
-
} catch (_a) {
|
|
23900
|
-
// target is gone
|
|
23901
|
-
}
|
|
23902
|
-
}
|
|
23903
|
-
function broadcast(win, message) {
|
|
23904
|
-
for (const target of getPageWindows(win)) {
|
|
23905
|
-
if (target !== win) {
|
|
23906
|
-
post(target, message);
|
|
23907
|
-
}
|
|
23908
|
-
}
|
|
23909
|
-
}
|
|
23910
|
-
function compareRevisions(a, b) {
|
|
23911
|
-
if (a.ts !== b.ts) {
|
|
23912
|
-
return a.ts - b.ts;
|
|
23913
|
-
}
|
|
23914
|
-
return a.origin < b.origin ? -1 : a.origin > b.origin ? 1 : 0;
|
|
23915
|
-
}
|
|
23916
|
-
function isRevision(rev) {
|
|
23917
|
-
return !!rev && typeof rev.ts === 'number' && typeof rev.origin === 'string';
|
|
23918
|
-
}
|
|
23919
|
-
function handleMessage(win, registry, logger, event) {
|
|
23920
|
-
const data = event.data;
|
|
23921
|
-
if (!data || data.ns !== NAMESPACE || typeof data.id !== 'string') {
|
|
23922
|
-
return;
|
|
23923
|
-
}
|
|
23924
|
-
const source = event.source;
|
|
23925
|
-
if (!source || source === win || !isKnownPageWindow(win, source)) {
|
|
23926
|
-
logger.debug('ignored message from a window outside this page', {
|
|
23927
|
-
data: {
|
|
23928
|
-
id: data.id,
|
|
23929
|
-
kind: data.kind
|
|
23930
|
-
}
|
|
23931
|
-
});
|
|
23932
|
-
return;
|
|
23933
|
-
}
|
|
23934
|
-
const entry = registry.entries[data.id];
|
|
23935
|
-
if (data.kind === 'request-sync') {
|
|
23936
|
-
if (entry === null || entry === void 0 ? void 0 : entry.rev) {
|
|
23937
|
-
logger.debug('answering sync request', {
|
|
23938
|
-
data: {
|
|
23939
|
-
id: data.id
|
|
23940
|
-
}
|
|
23941
|
-
});
|
|
23942
|
-
post(source, {
|
|
23943
|
-
ns: NAMESPACE,
|
|
23944
|
-
from: registry.windowId,
|
|
23945
|
-
kind: 'update',
|
|
23946
|
-
id: data.id,
|
|
23947
|
-
value: entry.store.getData(),
|
|
23948
|
-
rev: entry.rev
|
|
23949
|
-
});
|
|
23950
|
-
}
|
|
23951
|
-
return;
|
|
23952
|
-
}
|
|
23953
|
-
if (data.kind !== 'update' || !isRevision(data.rev)) {
|
|
23954
|
-
return;
|
|
23955
|
-
}
|
|
23956
|
-
// Lamport-style: a write made after observing this one must sort after it,
|
|
23957
|
-
// even within the same millisecond.
|
|
23958
|
-
registry.lastTs = Math.max(registry.lastTs, data.rev.ts);
|
|
23959
|
-
if (!entry) {
|
|
23960
|
-
logger.debug('stored update for an id nobody here listens to yet', {
|
|
23961
|
-
data: {
|
|
23962
|
-
id: data.id,
|
|
23963
|
-
rev: data.rev
|
|
23964
|
-
}
|
|
23965
|
-
});
|
|
23966
|
-
registry.entries[data.id] = {
|
|
23967
|
-
store: new TinyDataStore({
|
|
23968
|
-
initialValue: data.value,
|
|
23969
|
-
compare: 'deep'
|
|
23970
|
-
}),
|
|
23971
|
-
rev: data.rev
|
|
23972
|
-
};
|
|
23973
|
-
return;
|
|
23974
|
-
}
|
|
23975
|
-
// Equal/older revisions are what stops echoes between frames.
|
|
23976
|
-
if (entry.rev && compareRevisions(data.rev, entry.rev) <= 0) {
|
|
23977
|
-
logger.debug('dropped stale or duplicate update', {
|
|
23978
|
-
data: {
|
|
23979
|
-
id: data.id,
|
|
23980
|
-
rev: data.rev
|
|
23981
|
-
}
|
|
23982
|
-
});
|
|
23983
|
-
return;
|
|
23984
|
-
}
|
|
23985
|
-
logger.debug('applied update from another frame', {
|
|
23986
|
-
data: {
|
|
23987
|
-
id: data.id,
|
|
23988
|
-
value: data.value,
|
|
23989
|
-
rev: data.rev
|
|
23990
|
-
}
|
|
23991
|
-
});
|
|
23992
|
-
entry.rev = data.rev;
|
|
23993
|
-
entry.store.setData(() => data.value);
|
|
23994
|
-
}
|
|
23995
|
-
// The listener is installed once per window by whichever bundle listens first,
|
|
23996
|
-
// so it keeps that bundle's logger.
|
|
23997
|
-
function ensureListener(win, registry, logger) {
|
|
23998
|
-
if (registry.listening) {
|
|
23999
|
-
return;
|
|
24000
|
-
}
|
|
24001
|
-
registry.listening = true;
|
|
24002
|
-
win.addEventListener('message', event => handleMessage(win, registry, logger, event));
|
|
24003
|
-
}
|
|
24004
|
-
/**
|
|
24005
|
-
* A `TinyDataStore` shared by id between every workspace in this window and,
|
|
24006
|
-
* via `postMessage`, every other frame on the page (parent, siblings, nested).
|
|
24007
|
-
* Last write wins (timestamp, then window id as tie-break).
|
|
24008
|
-
*/
|
|
24009
|
-
function listenToGlobalTinyDataStore({
|
|
24010
|
-
id,
|
|
24011
|
-
initialValue,
|
|
24012
|
-
onChanges,
|
|
24013
|
-
logger = avatarClientLoggerFactory.getOrCreateLogger('service', 'global-tiny-data-store')
|
|
24014
|
-
}) {
|
|
24015
|
-
const win = window;
|
|
24016
|
-
const registry = getRegistry(logger);
|
|
24017
|
-
ensureListener(win, registry, logger);
|
|
24018
|
-
let entry = registry.entries[id];
|
|
24019
|
-
const isNew = !entry;
|
|
24020
|
-
if (!entry) {
|
|
24021
|
-
entry = registry.entries[id] = {
|
|
24022
|
-
store: new TinyDataStore({
|
|
24023
|
-
initialValue,
|
|
24024
|
-
compare: 'deep'
|
|
24025
|
-
}),
|
|
24026
|
-
rev: null
|
|
24027
|
-
};
|
|
24028
|
-
}
|
|
24029
|
-
const store = entry.store;
|
|
24030
|
-
const unsubscribe = store.onChanges(onChanges, {
|
|
24031
|
-
replayLastValue: false
|
|
24032
|
-
});
|
|
24033
|
-
logger.debug('listening to global store', {
|
|
24034
|
-
data: {
|
|
24035
|
-
id,
|
|
24036
|
-
isNew
|
|
24037
|
-
}
|
|
24038
|
-
});
|
|
24039
|
-
if (isNew) {
|
|
24040
|
-
broadcast(win, {
|
|
24041
|
-
ns: NAMESPACE,
|
|
24042
|
-
from: registry.windowId,
|
|
24043
|
-
kind: 'request-sync',
|
|
24044
|
-
id
|
|
24045
|
-
});
|
|
24046
|
-
}
|
|
24047
|
-
return {
|
|
24048
|
-
unsubscribe,
|
|
24049
|
-
getData: () => store.getData(),
|
|
24050
|
-
setData: value => {
|
|
24051
|
-
const rev = {
|
|
24052
|
-
ts: registry.lastTs = Math.max(Date.now(), registry.lastTs + 1),
|
|
24053
|
-
origin: registry.windowId
|
|
24054
|
-
};
|
|
24055
|
-
logger.debug('updating global store', {
|
|
24056
|
-
data: {
|
|
24057
|
-
id,
|
|
24058
|
-
value,
|
|
24059
|
-
rev
|
|
24060
|
-
}
|
|
24061
|
-
});
|
|
24062
|
-
entry.rev = rev;
|
|
24063
|
-
store.setData(() => value);
|
|
24064
|
-
broadcast(win, {
|
|
24065
|
-
ns: NAMESPACE,
|
|
24066
|
-
from: registry.windowId,
|
|
24067
|
-
kind: 'update',
|
|
24068
|
-
id,
|
|
24069
|
-
value,
|
|
24070
|
-
rev
|
|
24071
|
-
});
|
|
24072
|
-
}
|
|
24073
|
-
};
|
|
24074
|
-
}
|
|
24075
|
-
|
|
24076
23831
|
const ACTIVE_SESSION_STORE_ID = 'agenticExperienceAvatar';
|
|
24077
23832
|
function createId() {
|
|
24078
23833
|
return typeof crypto !== 'undefined' && crypto.randomUUID ? crypto.randomUUID() : `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
|
|
@@ -24094,20 +23849,13 @@ class ActiveSessionCoordinator {
|
|
|
24094
23849
|
});
|
|
24095
23850
|
this._win = window;
|
|
24096
23851
|
this._onPageHide = () => this.release();
|
|
24097
|
-
const _a = listenToGlobalTinyDataStore({
|
|
24098
|
-
id: ACTIVE_SESSION_STORE_ID,
|
|
24099
|
-
initialValue: null,
|
|
24100
|
-
onChanges: value => this._handle(value),
|
|
24101
|
-
logger: _options.logger
|
|
24102
|
-
}),
|
|
24103
|
-
{
|
|
24104
|
-
unsubscribe
|
|
24105
|
-
} = _a,
|
|
24106
|
-
global = __rest(_a, ["unsubscribe"]);
|
|
24107
23852
|
this._logger = _options.logger;
|
|
24108
|
-
this._global =
|
|
24109
|
-
|
|
24110
|
-
|
|
23853
|
+
this._global = getOrCreateGlobalTinyDataStore({
|
|
23854
|
+
id: ACTIVE_SESSION_STORE_ID,
|
|
23855
|
+
initialValue: null,
|
|
23856
|
+
logger: _options.logger
|
|
23857
|
+
});
|
|
23858
|
+
this._unsubscribe = this._global.onChanges(value => this._handle(value));
|
|
24111
23859
|
// A closed iframe must not leave the page locked.
|
|
24112
23860
|
this._win.addEventListener('pagehide', this._onPageHide);
|
|
24113
23861
|
}
|
|
@@ -24127,19 +23875,19 @@ class ActiveSessionCoordinator {
|
|
|
24127
23875
|
preventDisconnections
|
|
24128
23876
|
}
|
|
24129
23877
|
});
|
|
24130
|
-
this._global.setData({
|
|
23878
|
+
this._global.setData(() => ({
|
|
24131
23879
|
id: this.id,
|
|
24132
23880
|
preventDisconnections
|
|
24133
|
-
});
|
|
23881
|
+
}));
|
|
24134
23882
|
}
|
|
24135
23883
|
/** Republishes the flag only while this avatar owns the call; never claims an idle one */
|
|
24136
23884
|
updateFlag(preventDisconnections) {
|
|
24137
23885
|
var _a, _b;
|
|
24138
23886
|
if (this._owns && ((_a = this._global.getData()) === null || _a === void 0 ? void 0 : _a.id) === this.id && ((_b = this._global.getData()) === null || _b === void 0 ? void 0 : _b.preventDisconnections) !== preventDisconnections) {
|
|
24139
|
-
this._global.setData({
|
|
23887
|
+
this._global.setData(() => ({
|
|
24140
23888
|
id: this.id,
|
|
24141
23889
|
preventDisconnections
|
|
24142
|
-
});
|
|
23890
|
+
}));
|
|
24143
23891
|
}
|
|
24144
23892
|
}
|
|
24145
23893
|
/** Clears the record only if it is still ours, so a taken-over avatar can't wipe the new owner */
|
|
@@ -24152,7 +23900,7 @@ class ActiveSessionCoordinator {
|
|
|
24152
23900
|
id: this.id
|
|
24153
23901
|
}
|
|
24154
23902
|
});
|
|
24155
|
-
this._global.setData(null);
|
|
23903
|
+
this._global.setData(() => null);
|
|
24156
23904
|
}
|
|
24157
23905
|
}
|
|
24158
23906
|
dispose() {
|
|
@@ -25086,4 +24834,4 @@ class AvatarClientManager extends ActorManager {
|
|
|
25086
24834
|
}
|
|
25087
24835
|
}
|
|
25088
24836
|
|
|
25089
|
-
export { ApplicationFeatures, AvatarClientManager, AvatarConnectionMachineEventTypes, AvatarConnectionMachineId, AvatarNotificationCode, ButtonNames, PageNames, agentRawTextClientToolDeltaSchema, agentRawTextDeltaSchema, agentRawTextSchema, agentTurnToTalkSchema, askPermissionsSchema, avatarClientLoggerFactory, avatarConnectionMachine, avatarRTCClientManager, clientConfigurationSchema, conversationEndedSchema, conversationTimeWarningSchema, createTinyPubsubEventsHandler, createTinyPubsubEventsSource, generatingSpeechSchema, getAvatarDisconnectNotificationVariant, getQueryParam, initializeLogsCollectionIfNeeded, isMappedAvatarDisconnectReason, isMobileDevice, joinCompleteSchema,
|
|
24837
|
+
export { ApplicationFeatures, AvatarClientManager, AvatarConnectionMachineEventTypes, AvatarConnectionMachineId, AvatarNotificationCode, ButtonNames, PageNames, agentRawTextClientToolDeltaSchema, agentRawTextDeltaSchema, agentRawTextSchema, agentTurnToTalkSchema, askPermissionsSchema, avatarClientLoggerFactory, avatarConnectionMachine, avatarRTCClientManager, clientConfigurationSchema, conversationEndedSchema, conversationTimeWarningSchema, createTinyPubsubEventsHandler, createTinyPubsubEventsSource, generatingSpeechSchema, getAvatarDisconnectNotificationVariant, getQueryParam, initializeLogsCollectionIfNeeded, isMappedAvatarDisconnectReason, isMobileDevice, joinCompleteSchema, noAgentSchema, onServerConnectedSchema, pauseExpiryWarningSchema, resetWebsocketClientTeardownState, showAgentSchema, showStartSpeechSchema, stvFinishedTalkingSchema, stvNewSessionSchema, stvSpeechChunkSchema, stvStartedTalkingSchema, timingTracker, unsupportedClientSchema, websocketClientManager, websocketDebugInfo, websocketMessage, websocketNonRecoveredReconnect, websocketRecoveryState, websocketSystemMessage };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kaltura-sdk/avatars",
|
|
3
|
-
"version": "1.21.
|
|
3
|
+
"version": "1.21.1",
|
|
4
4
|
"author": "kaltura",
|
|
5
5
|
"license": "AGPL-3.0",
|
|
6
6
|
"repository": {
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"@kaltura-sdk/rtc-avatar": "^1.33.4",
|
|
13
13
|
"@kaltura-sdk/rtc-core": "^1.26.2",
|
|
14
14
|
"@local/genie-shared-utils": "^1.0.0",
|
|
15
|
-
"@unisphere/core": "^1.
|
|
15
|
+
"@unisphere/core": "^1.101.1",
|
|
16
16
|
"@unisphere/genie-types": "^1.47.0",
|
|
17
17
|
"@unisphere/notifications-core": "^1.25.0",
|
|
18
18
|
"@unisphere/runtime": "^1.98.0",
|
package/src/index.d.ts
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
1
|
import type { ActiveSessionCoordinator } from '../avatar-client-manager/utils/active-session-coordinator';
|
|
2
|
-
import type { listenToGlobalTinyDataStore } from '../global-tiny-data-store';
|
|
3
2
|
type CoordinatorOptions = ConstructorParameters<typeof ActiveSessionCoordinator>[0];
|
|
4
3
|
export declare function getRealTopWindow(): Window;
|
|
5
4
|
export declare function addFrame(parent: Window): Window;
|
|
6
5
|
export declare function installBrowserLikePostMessage(windows: Window[]): void;
|
|
7
6
|
export declare function createFrameApi(win: Window): Promise<{
|
|
8
|
-
listen: (options: Parameters<typeof listenToGlobalTinyDataStore>[0]) => {
|
|
9
|
-
unsubscribe: () => void;
|
|
10
|
-
getData: () => unknown;
|
|
11
|
-
setData: (value: unknown) => void;
|
|
12
|
-
};
|
|
13
7
|
createCoordinator: (options: CoordinatorOptions) => ActiveSessionCoordinator;
|
|
14
8
|
cleanup: () => void;
|
|
15
9
|
}>;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './listen-to-global-tiny-data-store';
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { UnisphereLoggerType } from '@unisphere/core';
|
|
2
|
-
/**
|
|
3
|
-
* A `TinyDataStore` shared by id between every workspace in this window and,
|
|
4
|
-
* via `postMessage`, every other frame on the page (parent, siblings, nested).
|
|
5
|
-
* Last write wins (timestamp, then window id as tie-break).
|
|
6
|
-
*/
|
|
7
|
-
export declare function listenToGlobalTinyDataStore<T>({ id, initialValue, onChanges, logger, }: {
|
|
8
|
-
id: string;
|
|
9
|
-
initialValue: T;
|
|
10
|
-
onChanges: (value: T) => void;
|
|
11
|
-
logger?: UnisphereLoggerType;
|
|
12
|
-
}): {
|
|
13
|
-
unsubscribe: () => void;
|
|
14
|
-
getData: () => T;
|
|
15
|
-
setData: (value: T) => void;
|
|
16
|
-
};
|