@naviedu/room-platform-react 0.0.65 → 0.0.68
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/README.md +13 -0
- package/index.d.ts +1 -0
- package/index.esm.js +1337 -511
- package/package.json +5 -1
- package/room-control.d.ts +94 -0
- package/room-control.esm.js +438 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naviedu/room-platform-react",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.68",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./index.esm.js",
|
|
6
6
|
"module": "./index.esm.js",
|
|
@@ -10,6 +10,10 @@
|
|
|
10
10
|
"types": "./index.d.ts",
|
|
11
11
|
"import": "./index.esm.js"
|
|
12
12
|
},
|
|
13
|
+
"./room-control": {
|
|
14
|
+
"types": "./room-control.d.ts",
|
|
15
|
+
"import": "./room-control.esm.js"
|
|
16
|
+
},
|
|
13
17
|
"./styles.css": "./styles.css"
|
|
14
18
|
},
|
|
15
19
|
"sideEffects": [
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
export declare type ClickPayload = {
|
|
2
|
+
x: number;
|
|
3
|
+
y: number;
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
export declare type ControlCommand<TPayload = unknown> = {
|
|
7
|
+
type: 'control-command';
|
|
8
|
+
version: typeof ROOM_CONTROL_VERSION;
|
|
9
|
+
scopeId: string;
|
|
10
|
+
commandId: string;
|
|
11
|
+
targetId?: string;
|
|
12
|
+
action: RoomControlAction;
|
|
13
|
+
payload: TPayload;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export declare type ControlDiscover = {
|
|
17
|
+
type: 'control-discover';
|
|
18
|
+
version: typeof ROOM_CONTROL_VERSION;
|
|
19
|
+
scopeId: string;
|
|
20
|
+
requestId: string;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export declare type ControlMessage = ControlTargetReady | ControlDiscover | ControlCommand | ControlState;
|
|
24
|
+
|
|
25
|
+
export declare type ControlState<TState = unknown> = {
|
|
26
|
+
type: 'control-state';
|
|
27
|
+
version: typeof ROOM_CONTROL_VERSION;
|
|
28
|
+
scopeId: string;
|
|
29
|
+
targetId: string;
|
|
30
|
+
commandId?: string;
|
|
31
|
+
state?: TState;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export declare type ControlTargetReady = {
|
|
35
|
+
type: 'control-target-ready';
|
|
36
|
+
version: typeof ROOM_CONTROL_VERSION;
|
|
37
|
+
scopeId: string;
|
|
38
|
+
targetId: string;
|
|
39
|
+
targetType?: string;
|
|
40
|
+
capabilities: string[];
|
|
41
|
+
requestId?: string;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
declare interface ControlTransport {
|
|
45
|
+
publish(message: unknown): void;
|
|
46
|
+
subscribe(handler: (message: unknown) => void): () => void;
|
|
47
|
+
close(): void;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export declare function createRoomControlTarget(options: RoomControlTargetOptions): RoomControlTarget;
|
|
51
|
+
|
|
52
|
+
export declare function normalizeCapturedPoint({ clientX, clientY, contentRect, }: {
|
|
53
|
+
clientX: number;
|
|
54
|
+
clientY: number;
|
|
55
|
+
contentRect: Pick<DOMRect, 'left' | 'top' | 'width' | 'height'>;
|
|
56
|
+
}): {
|
|
57
|
+
x: number;
|
|
58
|
+
y: number;
|
|
59
|
+
} | null;
|
|
60
|
+
|
|
61
|
+
export declare const ROOM_CONTROL_ACTIONS: {
|
|
62
|
+
readonly CLICK: "ui.click";
|
|
63
|
+
readonly SCROLL: "ui.scroll";
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export declare const ROOM_CONTROL_VERSION: 1;
|
|
67
|
+
|
|
68
|
+
export declare type RoomControlAction = (typeof ROOM_CONTROL_ACTIONS)[keyof typeof ROOM_CONTROL_ACTIONS];
|
|
69
|
+
|
|
70
|
+
export declare type RoomControlTarget = {
|
|
71
|
+
readonly targetId: string;
|
|
72
|
+
close: () => void;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
declare type RoomControlTargetHandlers = {
|
|
76
|
+
[action: string]: (payload: unknown) => void;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export declare type RoomControlTargetOptions = {
|
|
80
|
+
scopeId: string;
|
|
81
|
+
targetType?: string;
|
|
82
|
+
capabilities: readonly string[];
|
|
83
|
+
handlers: RoomControlTargetHandlers;
|
|
84
|
+
captureHandle?: {
|
|
85
|
+
roomOrigin?: string;
|
|
86
|
+
};
|
|
87
|
+
transport?: ControlTransport;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export declare type ScrollPayload = {
|
|
91
|
+
deltaY: number;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export { }
|
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
var ROOM_CONTROL_VERSION = 1;
|
|
2
|
+
var ROOM_CONTROL_ACTIONS = {
|
|
3
|
+
CLICK: 'ui.click',
|
|
4
|
+
SCROLL: 'ui.scroll'
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
function normalizeCapturedPoint(param) {
|
|
8
|
+
var clientX = param.clientX, clientY = param.clientY, contentRect = param.contentRect;
|
|
9
|
+
if (!Number.isFinite(clientX) || !Number.isFinite(clientY) || !Number.isFinite(contentRect.left) || !Number.isFinite(contentRect.top) || !Number.isFinite(contentRect.width) || !Number.isFinite(contentRect.height) || contentRect.width <= 0 || contentRect.height <= 0) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
var x = (clientX - contentRect.left) / contentRect.width;
|
|
13
|
+
var y = (clientY - contentRect.top) / contentRect.height;
|
|
14
|
+
if (x < 0 || x > 1 || y < 0 || y > 1) return null;
|
|
15
|
+
return {
|
|
16
|
+
x: x,
|
|
17
|
+
y: y
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function _type_of(obj) {
|
|
22
|
+
"@swc/helpers - typeof";
|
|
23
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
24
|
+
}
|
|
25
|
+
var MAX_CONTROL_SCOPE_LENGTH = 128;
|
|
26
|
+
var MAX_CONTROL_ID_LENGTH = 128;
|
|
27
|
+
var MAX_CONTROL_SCROLL_DELTA = 10000;
|
|
28
|
+
var isRecord = function(value) {
|
|
29
|
+
return (typeof value === "undefined" ? "undefined" : _type_of(value)) === 'object' && value !== null && !Array.isArray(value);
|
|
30
|
+
};
|
|
31
|
+
var hasOwn = function(value, key) {
|
|
32
|
+
return Object.prototype.hasOwnProperty.call(value, key);
|
|
33
|
+
};
|
|
34
|
+
var hasRequiredOwn = function(value) {
|
|
35
|
+
for(var _len = arguments.length, keys = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){
|
|
36
|
+
keys[_key - 1] = arguments[_key];
|
|
37
|
+
}
|
|
38
|
+
return keys.every(function(key) {
|
|
39
|
+
return hasOwn(value, key);
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
var isBoundedString = function(value, maxLength) {
|
|
43
|
+
return typeof value === 'string' && value === value.trim() && value.length > 0 && value.length <= maxLength;
|
|
44
|
+
};
|
|
45
|
+
var isValidId = function(value) {
|
|
46
|
+
return isBoundedString(value, MAX_CONTROL_ID_LENGTH);
|
|
47
|
+
};
|
|
48
|
+
var isValidScope = function(value) {
|
|
49
|
+
if (typeof value !== 'string') return false;
|
|
50
|
+
var normalized = normalizeScopeId(value);
|
|
51
|
+
return normalized !== null && normalized === value;
|
|
52
|
+
};
|
|
53
|
+
var isValidVersion = function(value) {
|
|
54
|
+
return value === ROOM_CONTROL_VERSION;
|
|
55
|
+
};
|
|
56
|
+
function normalizeScopeId(value) {
|
|
57
|
+
if (typeof value !== 'string') return null;
|
|
58
|
+
var normalized = value.trim();
|
|
59
|
+
return normalized.length > 0 && normalized.length <= MAX_CONTROL_SCOPE_LENGTH ? normalized : null;
|
|
60
|
+
}
|
|
61
|
+
function isValidScrollPayload(value) {
|
|
62
|
+
return isRecord(value) && hasRequiredOwn(value, 'deltaY') && typeof value.deltaY === 'number' && Number.isFinite(value.deltaY) && Math.abs(value.deltaY) <= MAX_CONTROL_SCROLL_DELTA;
|
|
63
|
+
}
|
|
64
|
+
function isValidClickPayload(value) {
|
|
65
|
+
return isRecord(value) && hasRequiredOwn(value, 'x', 'y') && typeof value.x === 'number' && typeof value.y === 'number' && Number.isFinite(value.x) && Number.isFinite(value.y) && value.x >= 0 && value.x <= 1 && value.y >= 0 && value.y <= 1;
|
|
66
|
+
}
|
|
67
|
+
function isValidControlPayload(action, payload) {
|
|
68
|
+
if (action === ROOM_CONTROL_ACTIONS.CLICK) return isValidClickPayload(payload);
|
|
69
|
+
if (action === ROOM_CONTROL_ACTIONS.SCROLL) return isValidScrollPayload(payload);
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
var isValidOptionalString = function(value, key) {
|
|
73
|
+
var maxLength = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : MAX_CONTROL_ID_LENGTH;
|
|
74
|
+
return !hasOwn(value, key) || isBoundedString(value[key], maxLength);
|
|
75
|
+
};
|
|
76
|
+
function isValidControlCommand(value) {
|
|
77
|
+
if (!isRecord(value) || !hasRequiredOwn(value, 'type', 'version', 'scopeId', 'commandId', 'action', 'payload')) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
if (value.type !== 'control-command' || !isValidVersion(value.version) || !isValidScope(value.scopeId) || !isValidId(value.commandId) || !isValidId(value.action) || !isValidControlPayload(value.action, value.payload)) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
return !hasOwn(value, 'targetId') || isValidId(value.targetId);
|
|
84
|
+
}
|
|
85
|
+
function isValidControlTargetReady(value) {
|
|
86
|
+
return hasRequiredOwn(value, 'type', 'version', 'scopeId', 'targetId', 'capabilities') && value.type === 'control-target-ready' && isValidVersion(value.version) && isValidScope(value.scopeId) && isValidId(value.targetId) && Array.isArray(value.capabilities) && value.capabilities.every(function(capability) {
|
|
87
|
+
return isBoundedString(capability, MAX_CONTROL_ID_LENGTH);
|
|
88
|
+
}) && isValidOptionalString(value, 'targetType') && isValidOptionalString(value, 'requestId');
|
|
89
|
+
}
|
|
90
|
+
function isValidControlDiscover(value) {
|
|
91
|
+
return hasRequiredOwn(value, 'type', 'version', 'scopeId', 'requestId') && value.type === 'control-discover' && isValidVersion(value.version) && isValidScope(value.scopeId) && isValidId(value.requestId);
|
|
92
|
+
}
|
|
93
|
+
function isValidControlState(value) {
|
|
94
|
+
return hasRequiredOwn(value, 'type', 'version', 'scopeId', 'targetId') && value.type === 'control-state' && isValidVersion(value.version) && isValidScope(value.scopeId) && isValidId(value.targetId) && isValidOptionalString(value, 'commandId');
|
|
95
|
+
}
|
|
96
|
+
function isValidControlMessage(value) {
|
|
97
|
+
if (!isRecord(value) || !hasOwn(value, 'type')) return false;
|
|
98
|
+
if (value.type === 'control-command') return isValidControlCommand(value);
|
|
99
|
+
if (value.type === 'control-target-ready') return isValidControlTargetReady(value);
|
|
100
|
+
if (value.type === 'control-discover') return isValidControlDiscover(value);
|
|
101
|
+
if (value.type === 'control-state') return isValidControlState(value);
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function controlChannelName(scopeId) {
|
|
106
|
+
var normalizedScopeId = normalizeScopeId(scopeId);
|
|
107
|
+
return normalizedScopeId === null ? '' : "naviedu:room-control:v".concat(ROOM_CONTROL_VERSION, ":").concat(normalizedScopeId);
|
|
108
|
+
}
|
|
109
|
+
function createBroadcastChannelTransport(scopeId) {
|
|
110
|
+
var normalizedScopeId = normalizeScopeId(scopeId);
|
|
111
|
+
if (normalizedScopeId === null || typeof window === 'undefined') return null;
|
|
112
|
+
try {
|
|
113
|
+
if (typeof window.BroadcastChannel !== 'function') return null;
|
|
114
|
+
var channel = new window.BroadcastChannel(controlChannelName(normalizedScopeId));
|
|
115
|
+
var handlers = new Set();
|
|
116
|
+
var closed = false;
|
|
117
|
+
channel.onmessage = function(event) {
|
|
118
|
+
if (closed) return;
|
|
119
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
120
|
+
try {
|
|
121
|
+
for(var _iterator = handlers[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
122
|
+
var handler = _step.value;
|
|
123
|
+
try {
|
|
124
|
+
handler(event.data);
|
|
125
|
+
} catch (unused) {
|
|
126
|
+
// A subscriber must not break delivery to other subscribers.
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
} catch (err) {
|
|
130
|
+
_didIteratorError = true;
|
|
131
|
+
_iteratorError = err;
|
|
132
|
+
} finally{
|
|
133
|
+
try {
|
|
134
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
135
|
+
_iterator.return();
|
|
136
|
+
}
|
|
137
|
+
} finally{
|
|
138
|
+
if (_didIteratorError) {
|
|
139
|
+
throw _iteratorError;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
return {
|
|
145
|
+
publish: function publish(message) {
|
|
146
|
+
if (closed) return;
|
|
147
|
+
try {
|
|
148
|
+
channel.postMessage(message);
|
|
149
|
+
} catch (unused) {
|
|
150
|
+
// Unsupported structured-clone values are intentionally ignored.
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
subscribe: function subscribe(handler) {
|
|
154
|
+
if (closed) return function() {
|
|
155
|
+
return undefined;
|
|
156
|
+
};
|
|
157
|
+
handlers.add(handler);
|
|
158
|
+
return function() {
|
|
159
|
+
return handlers.delete(handler);
|
|
160
|
+
};
|
|
161
|
+
},
|
|
162
|
+
close: function close() {
|
|
163
|
+
if (closed) return;
|
|
164
|
+
closed = true;
|
|
165
|
+
handlers.clear();
|
|
166
|
+
try {
|
|
167
|
+
channel.onmessage = null;
|
|
168
|
+
channel.close();
|
|
169
|
+
} catch (unused) {
|
|
170
|
+
// Closing an already-broken native channel is a no-op.
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
} catch (unused) {
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function encodeRoomControlCaptureHandle(handle) {
|
|
180
|
+
return JSON.stringify(handle);
|
|
181
|
+
}
|
|
182
|
+
function getCaptureHandleSetter() {
|
|
183
|
+
try {
|
|
184
|
+
if (typeof navigator === 'undefined' || !navigator.mediaDevices) return null;
|
|
185
|
+
var mediaDevices = navigator.mediaDevices;
|
|
186
|
+
var setCaptureHandleConfig = mediaDevices.setCaptureHandleConfig;
|
|
187
|
+
return typeof setCaptureHandleConfig === 'function' ? {
|
|
188
|
+
mediaDevices: mediaDevices,
|
|
189
|
+
setCaptureHandleConfig: setCaptureHandleConfig
|
|
190
|
+
} : null;
|
|
191
|
+
} catch (unused) {
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
function exactOrigin(roomOrigin) {
|
|
196
|
+
var origin = roomOrigin !== null && roomOrigin !== void 0 ? roomOrigin : typeof window === 'undefined' ? undefined : window.location.origin;
|
|
197
|
+
if (!origin || origin === 'null') return null;
|
|
198
|
+
try {
|
|
199
|
+
return new URL(origin).origin === origin ? origin : null;
|
|
200
|
+
} catch (unused) {
|
|
201
|
+
return null;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
function registerRoomControlCaptureHandle(handle, roomOrigin) {
|
|
205
|
+
var setter = getCaptureHandleSetter();
|
|
206
|
+
var permittedOrigin = exactOrigin(roomOrigin);
|
|
207
|
+
if (setter === null || permittedOrigin === null) return function() {
|
|
208
|
+
return undefined;
|
|
209
|
+
};
|
|
210
|
+
try {
|
|
211
|
+
setter.setCaptureHandleConfig.call(setter.mediaDevices, {
|
|
212
|
+
handle: encodeRoomControlCaptureHandle(handle),
|
|
213
|
+
permittedOrigins: [
|
|
214
|
+
permittedOrigin
|
|
215
|
+
]
|
|
216
|
+
});
|
|
217
|
+
} catch (unused) {
|
|
218
|
+
// Capture Handle is optional and must not break target startup.
|
|
219
|
+
}
|
|
220
|
+
return function() {
|
|
221
|
+
try {
|
|
222
|
+
setter.setCaptureHandleConfig.call(setter.mediaDevices, {
|
|
223
|
+
handle: '',
|
|
224
|
+
permittedOrigins: []
|
|
225
|
+
});
|
|
226
|
+
} catch (unused) {
|
|
227
|
+
// Cleanup is best effort because the browser API is optional.
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function storageKey(scopeId) {
|
|
233
|
+
var normalizedScopeId = normalizeScopeId(scopeId);
|
|
234
|
+
return normalizedScopeId === null ? null : "naviedu:room-control:v".concat(ROOM_CONTROL_VERSION, ":target-id:").concat(encodeURIComponent(normalizedScopeId));
|
|
235
|
+
}
|
|
236
|
+
function getSessionStorage() {
|
|
237
|
+
if (typeof window === 'undefined') return null;
|
|
238
|
+
try {
|
|
239
|
+
return window.sessionStorage;
|
|
240
|
+
} catch (unused) {
|
|
241
|
+
return null;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
function generateTargetId() {
|
|
245
|
+
try {
|
|
246
|
+
var _globalThis_crypto;
|
|
247
|
+
var randomUUID = (_globalThis_crypto = globalThis.crypto) === null || _globalThis_crypto === void 0 ? void 0 : _globalThis_crypto.randomUUID;
|
|
248
|
+
if (typeof randomUUID === 'function') {
|
|
249
|
+
var targetId = randomUUID.call(globalThis.crypto);
|
|
250
|
+
if (targetId) return targetId;
|
|
251
|
+
}
|
|
252
|
+
} catch (unused) {
|
|
253
|
+
// Fall through to a non-empty local ID.
|
|
254
|
+
}
|
|
255
|
+
return "target-".concat(Date.now().toString(36), "-").concat(Math.random().toString(36).slice(2));
|
|
256
|
+
}
|
|
257
|
+
function createTargetId(scopeId) {
|
|
258
|
+
var targetId = generateTargetId();
|
|
259
|
+
var key = storageKey(scopeId);
|
|
260
|
+
var storage = key === null ? null : getSessionStorage();
|
|
261
|
+
if (storage !== null && key !== null) {
|
|
262
|
+
try {
|
|
263
|
+
storage.setItem(key, targetId);
|
|
264
|
+
} catch (unused) {
|
|
265
|
+
// sessionStorage may be unavailable or quota-limited.
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
return targetId;
|
|
269
|
+
}
|
|
270
|
+
function restoreTargetId(scopeId) {
|
|
271
|
+
var key = storageKey(scopeId);
|
|
272
|
+
var storage = key === null ? null : getSessionStorage();
|
|
273
|
+
if (storage !== null && key !== null) {
|
|
274
|
+
try {
|
|
275
|
+
var targetId = storage.getItem(key);
|
|
276
|
+
if (targetId) return targetId;
|
|
277
|
+
} catch (unused) {
|
|
278
|
+
// Generate an in-memory ID when sessionStorage is unavailable.
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
return createTargetId(scopeId);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
function _array_like_to_array(arr, len) {
|
|
285
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
286
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
287
|
+
return arr2;
|
|
288
|
+
}
|
|
289
|
+
function _array_without_holes(arr) {
|
|
290
|
+
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
291
|
+
}
|
|
292
|
+
function _define_property(obj, key, value) {
|
|
293
|
+
if (key in obj) {
|
|
294
|
+
Object.defineProperty(obj, key, {
|
|
295
|
+
value: value,
|
|
296
|
+
enumerable: true,
|
|
297
|
+
configurable: true,
|
|
298
|
+
writable: true
|
|
299
|
+
});
|
|
300
|
+
} else {
|
|
301
|
+
obj[key] = value;
|
|
302
|
+
}
|
|
303
|
+
return obj;
|
|
304
|
+
}
|
|
305
|
+
function _iterable_to_array(iter) {
|
|
306
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
307
|
+
}
|
|
308
|
+
function _non_iterable_spread() {
|
|
309
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
310
|
+
}
|
|
311
|
+
function _object_spread(target) {
|
|
312
|
+
for(var i = 1; i < arguments.length; i++){
|
|
313
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
314
|
+
var ownKeys = Object.keys(source);
|
|
315
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
316
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
317
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
318
|
+
}));
|
|
319
|
+
}
|
|
320
|
+
ownKeys.forEach(function(key) {
|
|
321
|
+
_define_property(target, key, source[key]);
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
return target;
|
|
325
|
+
}
|
|
326
|
+
function ownKeys(object, enumerableOnly) {
|
|
327
|
+
var keys = Object.keys(object);
|
|
328
|
+
if (Object.getOwnPropertySymbols) {
|
|
329
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
330
|
+
keys.push.apply(keys, symbols);
|
|
331
|
+
}
|
|
332
|
+
return keys;
|
|
333
|
+
}
|
|
334
|
+
function _object_spread_props(target, source) {
|
|
335
|
+
source = source != null ? source : {};
|
|
336
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
337
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
338
|
+
} else {
|
|
339
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
340
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
return target;
|
|
344
|
+
}
|
|
345
|
+
function _to_consumable_array(arr) {
|
|
346
|
+
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
347
|
+
}
|
|
348
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
349
|
+
if (!o) return;
|
|
350
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
351
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
352
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
353
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
354
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
355
|
+
}
|
|
356
|
+
var isValidTargetId = function(value) {
|
|
357
|
+
return typeof value === 'string' && value === value.trim() && value.length > 0 && value.length <= MAX_CONTROL_ID_LENGTH;
|
|
358
|
+
};
|
|
359
|
+
function createRoomControlTarget(options) {
|
|
360
|
+
var _options_transport;
|
|
361
|
+
var scopeId = normalizeScopeId(options.scopeId);
|
|
362
|
+
if (scopeId === null) throw new Error('Invalid room-control scope');
|
|
363
|
+
var restoredTargetId = restoreTargetId(scopeId);
|
|
364
|
+
var targetId = isValidTargetId(restoredTargetId) ? restoredTargetId : createTargetId(scopeId);
|
|
365
|
+
var capabilities = _to_consumable_array(options.capabilities);
|
|
366
|
+
var supportedCapabilities = new Set(capabilities);
|
|
367
|
+
var transport = (_options_transport = options.transport) !== null && _options_transport !== void 0 ? _options_transport : createBroadcastChannelTransport(scopeId);
|
|
368
|
+
var closed = false;
|
|
369
|
+
var publishReady = function(requestId) {
|
|
370
|
+
if (transport === null || closed) return;
|
|
371
|
+
var ready = _object_spread(_object_spread_props(_object_spread({
|
|
372
|
+
type: 'control-target-ready',
|
|
373
|
+
version: ROOM_CONTROL_VERSION,
|
|
374
|
+
scopeId: scopeId,
|
|
375
|
+
targetId: targetId
|
|
376
|
+
}, options.targetType === undefined ? {} : {
|
|
377
|
+
targetType: options.targetType
|
|
378
|
+
}), {
|
|
379
|
+
capabilities: capabilities
|
|
380
|
+
}), requestId === undefined ? {} : {
|
|
381
|
+
requestId: requestId
|
|
382
|
+
});
|
|
383
|
+
transport.publish(ready);
|
|
384
|
+
};
|
|
385
|
+
var handleMessage = function(message) {
|
|
386
|
+
if (closed || !isValidControlMessage(message) || message.scopeId !== scopeId) return;
|
|
387
|
+
if (message.type === 'control-discover') {
|
|
388
|
+
publishReady(message.requestId);
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
if (message.type !== 'control-command') return;
|
|
392
|
+
if (message.targetId !== undefined && message.targetId !== targetId) return;
|
|
393
|
+
if (!supportedCapabilities.has(message.action)) return;
|
|
394
|
+
var handler = options.handlers[message.action];
|
|
395
|
+
if (typeof handler !== 'function') return;
|
|
396
|
+
try {
|
|
397
|
+
handler(message.payload);
|
|
398
|
+
} catch (unused) {
|
|
399
|
+
// An adapter failure must not break discovery or later commands.
|
|
400
|
+
}
|
|
401
|
+
};
|
|
402
|
+
var unsubscribe = transport === null ? function() {
|
|
403
|
+
return undefined;
|
|
404
|
+
} : transport.subscribe(handleMessage);
|
|
405
|
+
var cleanupCaptureHandle = options.captureHandle ? registerRoomControlCaptureHandle({
|
|
406
|
+
version: ROOM_CONTROL_VERSION,
|
|
407
|
+
scopeId: scopeId,
|
|
408
|
+
targetId: targetId
|
|
409
|
+
}, options.captureHandle.roomOrigin) : function() {
|
|
410
|
+
return undefined;
|
|
411
|
+
};
|
|
412
|
+
publishReady();
|
|
413
|
+
return {
|
|
414
|
+
targetId: targetId,
|
|
415
|
+
close: function close() {
|
|
416
|
+
if (closed) return;
|
|
417
|
+
closed = true;
|
|
418
|
+
try {
|
|
419
|
+
cleanupCaptureHandle();
|
|
420
|
+
} catch (unused) {
|
|
421
|
+
// Capture Handle cleanup is best effort.
|
|
422
|
+
}
|
|
423
|
+
try {
|
|
424
|
+
unsubscribe();
|
|
425
|
+
} catch (unused) {
|
|
426
|
+
// A broken transport subscription must not block other cleanup.
|
|
427
|
+
}
|
|
428
|
+
if (transport === null) return;
|
|
429
|
+
try {
|
|
430
|
+
transport.close();
|
|
431
|
+
} catch (unused) {
|
|
432
|
+
// A broken transport must not escape target cleanup.
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
export { ROOM_CONTROL_ACTIONS, ROOM_CONTROL_VERSION, createRoomControlTarget, normalizeCapturedPoint };
|