web3dlink 2.1.13 → 2.1.14

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/dist/web3dlink.js CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region \0rolldown/runtime.js
2
- var __commonJSMin = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t.exports), name = "web3dlink", version$1 = "2.1.13", description = "LarkSR / ZS 推流 GameAPI SDK", type = "module", main = "./dist/web3dlink.js", module$1 = "./dist/web3dlink.js", exports$1 = { ".": {
2
+ var __commonJSMin = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t.exports), name = "web3dlink", version$1 = "2.1.14", description = "LarkSR / ZS 推流 GameAPI SDK", type = "module", main = "./dist/web3dlink.js", module$1 = "./dist/web3dlink.js", exports$1 = { ".": {
3
3
  import: "./dist/web3dlink.js",
4
4
  default: "./dist/web3dlink.js"
5
5
  } }, files = ["dist"], scripts = {
@@ -11,7 +11,11 @@ var __commonJSMin = (e, t) => () => (t || (e((t = { exports: {} }).exports, t),
11
11
  "game-api",
12
12
  "streaming",
13
13
  "web3dlink"
14
- ], license = "MIT", sideEffects = ["./dist/web3dlink.js"], package_default = {
14
+ ], license = "MIT", sideEffects = [
15
+ "./dist/web3dlink.js",
16
+ "./zs-stream-parent.js",
17
+ "./version.js"
18
+ ], package_default = {
15
19
  name,
16
20
  version: version$1,
17
21
  description,
@@ -24240,6 +24244,145 @@ function getLarkSR() {
24240
24244
  }
24241
24245
  //#endregion
24242
24246
  //#region linkFlowzsStream.js
24247
+ (function(e) {
24248
+ let t = "zs-stream-parent", n = "zs-stream-embed";
24249
+ function r(e) {
24250
+ return e ? typeof e == "string" ? document.querySelector(e) : e : null;
24251
+ }
24252
+ function i(e, t, n) {
24253
+ let r = (e || "").replace(/\/+$/, "") || (typeof location < "u" ? location.origin : ""), i = new URLSearchParams({
24254
+ template: t || "default",
24255
+ autoconnect: "1",
24256
+ muted: "1"
24257
+ });
24258
+ return n && i.set("streamId", n), `${r}/embed?${i.toString()}`;
24259
+ }
24260
+ function a(e, n, r) {
24261
+ return e?.contentWindow ? (e.contentWindow.postMessage({
24262
+ source: t,
24263
+ streamId: n,
24264
+ ...r
24265
+ }, "*"), { ok: !0 }) : {
24266
+ ok: !1,
24267
+ error: "iframe 未就绪"
24268
+ };
24269
+ }
24270
+ class o {
24271
+ constructor({ streamId: t, template: n, container: i, baseUrl: a } = {}) {
24272
+ if (!t) throw Error("ZsStream: streamId 必填(同页多路时用于区分)");
24273
+ this.streamId = t, this.template = n || "default", this.baseUrl = a, this.container = r(i), this.iframe = null, this._handlers = /* @__PURE__ */ new Map(), this._ready = !1, this._inputReady = !1, this._onMessage = this._onMessage.bind(this), e.addEventListener("message", this._onMessage), this._mountIframe();
24274
+ }
24275
+ _mountIframe() {
24276
+ if (!this.container) throw Error("ZsStream: container 未找到");
24277
+ let e = document.createElement("iframe");
24278
+ e.src = i(this.baseUrl, this.template, this.streamId), e.style.width = "100%", e.style.height = "100%", e.style.border = "0", e.setAttribute("allow", "autoplay; fullscreen; encrypted-media"), e.title = `ZS Stream ${this.streamId}`, this.container.innerHTML = "", this.container.appendChild(e), this.iframe = e;
24279
+ }
24280
+ _onMessage(e) {
24281
+ let t = e.data;
24282
+ if (!t || t.source !== n || t.streamId && t.streamId !== this.streamId || t.type !== "event") return;
24283
+ let r = t.event;
24284
+ r === "ready" && (this._ready = !0), r === "inputready" && (this._inputReady = !0), this._emit(r, t.data);
24285
+ }
24286
+ _emit(e, t) {
24287
+ let n = this._handlers.get(e);
24288
+ if (n) for (let e of n) try {
24289
+ e(t);
24290
+ } catch (e) {
24291
+ console.error("[ZsStream]", e);
24292
+ }
24293
+ }
24294
+ on(e, t) {
24295
+ return this._handlers.has(e) || this._handlers.set(e, /* @__PURE__ */ new Set()), this._handlers.get(e).add(t), () => this.off(e, t);
24296
+ }
24297
+ off(e, t) {
24298
+ this._handlers.get(e)?.delete(t);
24299
+ }
24300
+ _send(e, t) {
24301
+ return a(this.iframe, this.streamId, {
24302
+ type: e,
24303
+ ...t
24304
+ });
24305
+ }
24306
+ invoke(e, t, n) {
24307
+ return this._send("invoke", {
24308
+ module: e,
24309
+ action: t,
24310
+ params: n ?? {}
24311
+ });
24312
+ }
24313
+ camera(e, t) {
24314
+ return this._send("camera", {
24315
+ action: e,
24316
+ params: t ?? {}
24317
+ });
24318
+ }
24319
+ sendRaw(e) {
24320
+ return this._send("sendRaw", { descriptor: String(e) });
24321
+ }
24322
+ sendCommand(e, t) {
24323
+ return this._send("larkCommand", {
24324
+ command: e,
24325
+ params: t ?? {}
24326
+ });
24327
+ }
24328
+ sendTextToDataChannel(e) {
24329
+ let t = typeof e == "string" ? e : JSON.stringify({
24330
+ command: e.command,
24331
+ params: e.params ?? {}
24332
+ });
24333
+ return this._send("sendRaw", { descriptor: t });
24334
+ }
24335
+ disconnect() {
24336
+ return this._send("disconnect", {});
24337
+ }
24338
+ destroy() {
24339
+ e.removeEventListener("message", this._onMessage), this.disconnect(), this.iframe?.parentNode && this.iframe.parentNode.removeChild(this.iframe), this.iframe = null, this._handlers.clear();
24340
+ }
24341
+ get isReady() {
24342
+ return this._ready;
24343
+ }
24344
+ get isInputReady() {
24345
+ return this._inputReady;
24346
+ }
24347
+ }
24348
+ class s {
24349
+ constructor() {
24350
+ this._streams = /* @__PURE__ */ new Map();
24351
+ }
24352
+ mount(e) {
24353
+ let t = e?.streamId;
24354
+ if (!t) throw Error("ZsStreamHub.mount: streamId 必填");
24355
+ this._streams.has(t) && this._streams.get(t).destroy();
24356
+ let n = new o(e);
24357
+ return this._streams.set(t, n), n;
24358
+ }
24359
+ get(e) {
24360
+ return this._streams.get(e) || null;
24361
+ }
24362
+ has(e) {
24363
+ return this._streams.has(e);
24364
+ }
24365
+ destroy(e) {
24366
+ let t = this._streams.get(e);
24367
+ t && (t.destroy(), this._streams.delete(e));
24368
+ }
24369
+ destroyAll() {
24370
+ for (let e of [...this._streams.keys()]) this.destroy(e);
24371
+ }
24372
+ list() {
24373
+ return [...this._streams.keys()];
24374
+ }
24375
+ }
24376
+ e.ZsStream = {
24377
+ mount(e) {
24378
+ return new o(e);
24379
+ },
24380
+ Hub: s,
24381
+ buildEmbedSrc: i,
24382
+ MSG_SOURCE_PARENT: t,
24383
+ MSG_SOURCE_EMBED: n
24384
+ }, e.ZsStreamHub = s;
24385
+ })(typeof window < "u" ? window : globalThis);
24243
24386
  var activeStream = null;
24244
24387
  async function ZsStreamMount(e, t = {}) {
24245
24388
  if (!globalThis.ZsStream?.mount) throw Error("ZsStream 未加载,请确认已引入 zs-stream-parent.js");