parsec.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029
  1. "use strict";
  2. var h;
  3. var counter = 0;
  4. var resizeFlag = true;
  5. function n(a) {
  6. var b = 0;
  7. return function () {
  8. return b < a.length ? { done: !1, value: a[b++] } : { done: !0 };
  9. };
  10. }
  11. function q(a) {
  12. var b =
  13. "undefined" != typeof Symbol && Symbol.iterator && a[Symbol.iterator];
  14. return b ? b.call(a) : { next: n(a) };
  15. }
  16. var r =
  17. "undefined" != typeof window && window === this
  18. ? this
  19. : "undefined" != typeof global && null != global
  20. ? global
  21. : this,
  22. u =
  23. "function" == typeof Object.defineProperties
  24. ? Object.defineProperty
  25. : function (a, b, d) {
  26. a != Array.prototype &&
  27. a != Object.prototype &&
  28. (a[b] = d.value);
  29. };
  30. function w(a, b) {
  31. if (b) {
  32. var d = r;
  33. a = a.split(".");
  34. for (var f = 0; f < a.length - 1; f++) {
  35. var g = a[f];
  36. g in d || (d[g] = {});
  37. d = d[g];
  38. }
  39. a = a[a.length - 1];
  40. f = d[a];
  41. b = b(f);
  42. b != f &&
  43. null != b &&
  44. u(d, a, { configurable: !0, writable: !0, value: b });
  45. }
  46. }
  47. w("Promise", function (a) {
  48. function b(c) {
  49. this.c = 0;
  50. this.h = void 0;
  51. this.b = [];
  52. var e = this.f();
  53. try {
  54. c(e.resolve, e.reject);
  55. } catch (k) {
  56. e.reject(k);
  57. }
  58. }
  59. function d() {
  60. this.b = null;
  61. }
  62. function f(c) {
  63. return c instanceof b
  64. ? c
  65. : new b(function (e) {
  66. e(c);
  67. });
  68. }
  69. if (a) return a;
  70. d.prototype.c = function (c) {
  71. if (null == this.b) {
  72. this.b = [];
  73. var e = this;
  74. this.f(function () {
  75. e.h();
  76. });
  77. }
  78. this.b.push(c);
  79. };
  80. var g = r.setTimeout;
  81. d.prototype.f = function (c) {
  82. g(c, 0);
  83. };
  84. d.prototype.h = function () {
  85. for (; this.b && this.b.length; ) {
  86. var c = this.b;
  87. this.b = [];
  88. for (var e = 0; e < c.length; ++e) {
  89. var k = c[e];
  90. c[e] = null;
  91. try {
  92. k();
  93. } catch (m) {
  94. this.g(m);
  95. }
  96. }
  97. }
  98. this.b = null;
  99. };
  100. d.prototype.g = function (c) {
  101. this.f(function () {
  102. throw c;
  103. });
  104. };
  105. b.prototype.f = function () {
  106. function c(m) {
  107. return function (p) {
  108. k || ((k = !0), m.call(e, p));
  109. };
  110. }
  111. var e = this,
  112. k = !1;
  113. return { resolve: c(this.s), reject: c(this.g) };
  114. };
  115. b.prototype.s = function (c) {
  116. if (c === this)
  117. this.g(new TypeError("A Promise cannot resolve to itself"));
  118. else if (c instanceof b) this.u(c);
  119. else {
  120. a: switch (typeof c) {
  121. case "object":
  122. var e = null != c;
  123. break a;
  124. case "function":
  125. e = !0;
  126. break a;
  127. default:
  128. e = !1;
  129. }
  130. e ? this.o(c) : this.i(c);
  131. }
  132. };
  133. b.prototype.o = function (c) {
  134. var e = void 0;
  135. try {
  136. e = c.then;
  137. } catch (k) {
  138. this.g(k);
  139. return;
  140. }
  141. "function" == typeof e ? this.v(e, c) : this.i(c);
  142. };
  143. b.prototype.g = function (c) {
  144. this.j(2, c);
  145. };
  146. b.prototype.i = function (c) {
  147. this.j(1, c);
  148. };
  149. b.prototype.j = function (c, e) {
  150. if (0 != this.c)
  151. throw Error(
  152. "Cannot settle(" +
  153. c +
  154. ", " +
  155. e +
  156. "): Promise already settled in state" +
  157. this.c
  158. );
  159. this.c = c;
  160. this.h = e;
  161. this.l();
  162. };
  163. b.prototype.l = function () {
  164. if (null != this.b) {
  165. for (var c = 0; c < this.b.length; ++c) l.c(this.b[c]);
  166. this.b = null;
  167. }
  168. };
  169. var l = new d();
  170. b.prototype.u = function (c) {
  171. var e = this.f();
  172. c.w(e.resolve, e.reject);
  173. };
  174. b.prototype.v = function (c, e) {
  175. var k = this.f();
  176. try {
  177. c.call(e, k.resolve, k.reject);
  178. } catch (m) {
  179. k.reject(m);
  180. }
  181. };
  182. b.prototype.then = function (c, e) {
  183. function k(t, v) {
  184. return "function" == typeof t
  185. ? function (B) {
  186. try {
  187. m(t(B));
  188. } catch (C) {
  189. p(C);
  190. }
  191. }
  192. : v;
  193. }
  194. var m,
  195. p,
  196. D = new b(function (t, v) {
  197. m = t;
  198. p = v;
  199. });
  200. this.w(k(c, m), k(e, p));
  201. return D;
  202. };
  203. b.prototype.catch = function (c) {
  204. return this.then(void 0, c);
  205. };
  206. b.prototype.w = function (c, e) {
  207. function k() {
  208. switch (m.c) {
  209. case 1:
  210. c(m.h);
  211. break;
  212. case 2:
  213. e(m.h);
  214. break;
  215. default:
  216. throw Error("Unexpected state: " + m.c);
  217. }
  218. }
  219. var m = this;
  220. null == this.b ? l.c(k) : this.b.push(k);
  221. };
  222. b.resolve = f;
  223. b.reject = function (c) {
  224. return new b(function (e, k) {
  225. k(c);
  226. });
  227. };
  228. b.race = function (c) {
  229. return new b(function (e, k) {
  230. for (var m = q(c), p = m.next(); !p.done; p = m.next())
  231. f(p.value).w(e, k);
  232. });
  233. };
  234. b.all = function (c) {
  235. var e = q(c),
  236. k = e.next();
  237. return k.done
  238. ? f([])
  239. : new b(function (m, p) {
  240. function D(B) {
  241. return function (C) {
  242. t[B] = C;
  243. v--;
  244. 0 == v && m(t);
  245. };
  246. }
  247. var t = [],
  248. v = 0;
  249. do
  250. t.push(void 0),
  251. v++,
  252. f(k.value).w(D(t.length - 1), p),
  253. (k = e.next());
  254. while (!k.done);
  255. });
  256. };
  257. return b;
  258. });
  259. function x() {
  260. x = function () {};
  261. r.Symbol || (r.Symbol = y);
  262. }
  263. function z(a, b) {
  264. this.b = a;
  265. u(this, "description", { configurable: !0, writable: !0, value: b });
  266. }
  267. z.prototype.toString = function () {
  268. return this.b;
  269. };
  270. var y = (function () {
  271. function a(d) {
  272. if (this instanceof a)
  273. throw new TypeError("Symbol is not a constructor");
  274. return new z("jscomp_symbol_" + (d || "") + "_" + b++, d);
  275. }
  276. var b = 0;
  277. return a;
  278. })();
  279. function A() {
  280. x();
  281. var a = r.Symbol.iterator;
  282. a || (a = r.Symbol.iterator = r.Symbol("Symbol.iterator"));
  283. "function" != typeof Array.prototype[a] &&
  284. u(Array.prototype, a, {
  285. configurable: !0,
  286. writable: !0,
  287. value: function () {
  288. return E(n(this));
  289. },
  290. });
  291. A = function () {};
  292. }
  293. function E(a) {
  294. A();
  295. a = { next: a };
  296. a[r.Symbol.iterator] = function () {
  297. return this;
  298. };
  299. return a;
  300. }
  301. function F() {
  302. this.g = !1;
  303. this.c = null;
  304. this.i = void 0;
  305. this.b = 1;
  306. this.l = this.h = 0;
  307. this.f = null;
  308. }
  309. function G(a) {
  310. if (a.g) throw new TypeError("Generator is already running");
  311. a.g = !0;
  312. }
  313. F.prototype.j = function (a) {
  314. this.i = a;
  315. };
  316. function H(a, b) {
  317. a.f = { F: b, Y: !0 };
  318. a.b = a.h || a.l;
  319. }
  320. F.prototype.return = function (a) {
  321. this.f = { return: a };
  322. this.b = this.l;
  323. };
  324. function I(a, b, d) {
  325. a.b = d;
  326. return { value: b };
  327. }
  328. function aa(a) {
  329. this.b = new F();
  330. this.c = a;
  331. }
  332. function ba(a, b) {
  333. G(a.b);
  334. var d = a.b.c;
  335. if (d)
  336. return J(
  337. a,
  338. "return" in d
  339. ? d["return"]
  340. : function (f) {
  341. return { value: f, done: !0 };
  342. },
  343. b,
  344. a.b.return
  345. );
  346. a.b.return(b);
  347. return K(a);
  348. }
  349. function J(a, b, d, f) {
  350. try {
  351. var g = b.call(a.b.c, d);
  352. if (!(g instanceof Object))
  353. throw new TypeError("Iterator result " + g + " is not an object");
  354. if (!g.done) return (a.b.g = !1), g;
  355. var l = g.value;
  356. } catch (c) {
  357. return (a.b.c = null), H(a.b, c), K(a);
  358. }
  359. a.b.c = null;
  360. f.call(a.b, l);
  361. return K(a);
  362. }
  363. function K(a) {
  364. for (; a.b.b; )
  365. try {
  366. var b = a.c(a.b);
  367. if (b) return (a.b.g = !1), { value: b.value, done: !1 };
  368. } catch (d) {
  369. (a.b.i = void 0), H(a.b, d);
  370. }
  371. a.b.g = !1;
  372. if (a.b.f) {
  373. b = a.b.f;
  374. a.b.f = null;
  375. if (b.Y) throw b.F;
  376. return { value: b.return, done: !0 };
  377. }
  378. return { value: void 0, done: !0 };
  379. }
  380. function ca(a) {
  381. this.next = function (b) {
  382. G(a.b);
  383. a.b.c ? (b = J(a, a.b.c.next, b, a.b.j)) : (a.b.j(b), (b = K(a)));
  384. return b;
  385. };
  386. this.throw = function (b) {
  387. G(a.b);
  388. a.b.c ? (b = J(a, a.b.c["throw"], b, a.b.j)) : (H(a.b, b), (b = K(a)));
  389. return b;
  390. };
  391. this.return = function (b) {
  392. return ba(a, b);
  393. };
  394. A();
  395. this[Symbol.iterator] = function () {
  396. return this;
  397. };
  398. }
  399. function da(a) {
  400. function b(f) {
  401. return a.next(f);
  402. }
  403. function d(f) {
  404. return a.throw(f);
  405. }
  406. return new Promise(function (f, g) {
  407. function l(c) {
  408. c.done
  409. ? f(c.value)
  410. : Promise.resolve(c.value).then(b, d).then(l, g);
  411. }
  412. l(a.next());
  413. });
  414. }
  415. function L(a) {
  416. return da(new ca(new aa(a)));
  417. }
  418. w("Object.entries", function (a) {
  419. return a
  420. ? a
  421. : function (b) {
  422. var d = [],
  423. f;
  424. for (f in b)
  425. Object.prototype.hasOwnProperty.call(b, f) &&
  426. d.push([f, b[f]]);
  427. return d;
  428. };
  429. });
  430. var Status = {
  431. PARSEC_OK: 0,
  432. PARSEC_NOT_RUNNING: -3,
  433. PARSEC_CONNECTING: 20,
  434. PARSEC_WRN_BROWSER: 30,
  435. };
  436. function addEvtListener(element, eventName, listener) {
  437. element.addEventListener(eventName, listener);
  438. return [element, eventName, listener];
  439. }
  440. function O(a, b, d, f, g) {
  441. a = new DataView(a);
  442. a.setInt32(0, d);
  443. a.setInt32(4, f);
  444. a.setInt32(8, g);
  445. a.setInt8(12, b);
  446. }
  447. function P(a, b, d, f) {
  448. var g = new ArrayBuffer(13);
  449. O(g, a, b, d, f);
  450. return g;
  451. }
  452. function Q(a, b, d) {
  453. var f = new ArrayBuffer(13 + d.length + 1);
  454. O(f, a, d.length + 1, b, 0);
  455. a = new TextEncoder().encode(d);
  456. b = new Int8Array(f, 13);
  457. for (var g = 0; g < d.length; g++) b[g] = a[g];
  458. return f;
  459. }
  460. function ea(a, b) {
  461. a = JSON.stringify({
  462. _version: 1,
  463. _max_w: 6e4,
  464. _max_h: 6e4,
  465. _flags: 0,
  466. resolutionX: a,
  467. resolutionY: b,
  468. refreshRate: 60,
  469. mediaContainer: 0,
  470. });
  471. return Q(11, 0, a);
  472. }
  473. function fa(a, b, d, f, g) {
  474. switch (a.type) {
  475. case 4:
  476. if (!a.relative) {
  477. var l = Math.min(f / b, g / d),
  478. c = b * l;
  479. l *= d;
  480. g = Math.max((g - l) / 2, 0);
  481. f = Math.round((b / c) * (a.x - Math.max((f - c) / 2, 0)));
  482. f === b - 1 && (f = b);
  483. f > b && (f = b);
  484. 0 > f && (f = 0);
  485. a.x = f;
  486. b = Math.round((d / l) * (a.y - g));
  487. b === d - 1 && (b = d);
  488. b > d && (b = d);
  489. 0 > b && (b = 0);
  490. a.y = b;
  491. }
  492. return P(3, a.relative ? 1 : 0, a.x, a.y);
  493. case 8:
  494. return (
  495. (d = new ArrayBuffer(28)),
  496. O(d, 23, a.id, 0, 0),
  497. (b = new DataView(d)),
  498. b.setUint16(16, a.buttons),
  499. b.setInt16(18, a.thumbLX),
  500. b.setInt16(20, a.thumbLY),
  501. b.setInt16(22, a.thumbRX),
  502. b.setInt16(24, a.thumbRY),
  503. b.setUint8(26, a.leftTrigger),
  504. b.setUint8(27, a.rightTrigger),
  505. d
  506. );
  507. case 2:
  508. return P(1, a.button, a.pressed ? 1 : 0, 0);
  509. case 1:
  510. return P(0, a.code, a.mod, a.pressed ? 1 : 0);
  511. case 3:
  512. return P(2, a.x, a.y, 0);
  513. case 5:
  514. return P(4, a.button, a.pressed ? 1 : 0, a.id);
  515. case 6:
  516. return P(5, a.axis, a.value, a.id);
  517. case 7:
  518. return P(6, 0, 0, a.id);
  519. case 9:
  520. return P(24, 0, 0, 0);
  521. }
  522. }
  523. var R = {},
  524. S = 1;
  525. function T(a) {
  526. var b = S++;
  527. R[b] = a;
  528. return b;
  529. }
  530. function ha(a) {
  531. var b = a.getInt16(32),
  532. d = a.getInt32(16),
  533. f = 0 < d ? new Uint8Array(a.buffer, 34, d) : null;
  534. f = f ? T(f) : 0;
  535. return {
  536. type: 1,
  537. cursor: {
  538. size: d,
  539. positionX: a.getInt16(24),
  540. positionY: a.getInt16(26),
  541. width: a.getInt16(20),
  542. height: a.getInt16(22),
  543. hotX: a.getInt16(28),
  544. hotY: a.getInt16(30),
  545. imageUpdate: 0 < f,
  546. relative: !!(b & 256),
  547. hidden: !!(b & 512),
  548. stream: 0,
  549. },
  550. key: f,
  551. };
  552. }
  553. function ia(a, b) {
  554. b = T(new Uint8Array(b.buffer, 13, a.m));
  555. return { type: 3, id: a.A, key: b };
  556. }
  557. function ja() {
  558. var a = new Uint8Array(16);
  559. crypto.getRandomValues(a);
  560. return a
  561. .map(function (b) {
  562. return b % 10;
  563. })
  564. .join("");
  565. }
  566. function U(a) {
  567. var b = this;
  568. this.l = a;
  569. this.i = !1;
  570. this.j = "";
  571. this.h = !1;
  572. this.b = this.sdp = null;
  573. this.c = {};
  574. this.g = [];
  575. this.f = null;
  576. this.b = new RTCPeerConnection({
  577. iceServers: [{ urls: "stun:47.114.174.231:3478" }],
  578. });
  579. this.b.onicecandidate = function (d) {
  580. d.candidate &&
  581. ((d = d.candidate.candidate.replace("candidate:", "").split(" ")),
  582. 8 <= d.length &&
  583. "udp" === d[2].toLowerCase() &&
  584. b.l(
  585. d[4],
  586. parseInt(d[5], 10),
  587. !1,
  588. "srflx" === d[7],
  589. "host" === d[7]
  590. ));
  591. };
  592. }
  593. U.prototype.close = function () {
  594. for (var a = q(Object.entries(this.c)), b = a.next(); !b.done; b = a.next())
  595. b.value[1].close();
  596. this.b.close();
  597. };
  598. function V(a, b, d, f, g) {
  599. a.c[d] = a.b.createDataChannel(b, { negotiated: !0, id: d });
  600. a.c[d].binaryType = "arraybuffer";
  601. a.c[d].onopen = f;
  602. a.c[d].onmessage = g;
  603. }
  604. function ka(a) {
  605. var b;
  606. return L(function (d) {
  607. if (1 == d.b) return (b = a), I(d, a.b.createOffer(), 2);
  608. b.f = d.i;
  609. for (var f = a.f.sdp.split("\n"), g = {}, l = 0; l < f.length; l++) {
  610. var c = f[l].split("="),
  611. e = c[0];
  612. c = c[1];
  613. e &&
  614. ("a" === e
  615. ? (g.a || (g.a = {}),
  616. (e = c.split(/:(.+)/)),
  617. (g.a[e[0]] = e[1]))
  618. : (g[e] = c));
  619. }
  620. a.sdp = g;
  621. return d.return({
  622. ice_ufrag: a.sdp.a["ice-ufrag"],
  623. ice_pwd: a.sdp.a["ice-pwd"],
  624. fingerprint: a.sdp.a.fingerprint,
  625. });
  626. });
  627. }
  628. U.prototype.send = function (a, b) {
  629. "open" == this.c[b].readyState && this.c[b].send(a);
  630. };
  631. function W(a) {
  632. for (; 0 < a.g.length; ) {
  633. var b = a.g.shift();
  634. a.b.addIceCandidate(
  635. new RTCIceCandidate({
  636. candidate:
  637. "candidate:2395300328 1 udp 2113937151 " +
  638. b.ip +
  639. " " +
  640. (b.port +
  641. " typ " +
  642. (b.from_stun ? "srflx" : "host") +
  643. " generation 0 ufrag " +
  644. a.j +
  645. " network-cost 50"),
  646. sdpMid: a.sdp.a.mid,
  647. sdpMLineIndex: 0,
  648. })
  649. );
  650. }
  651. }
  652. function la(a, b, d, f) {
  653. var g, l;
  654. L(function (c) {
  655. switch (c.b) {
  656. case 1:
  657. if (!a.f) throw "Offer is not set";
  658. if (a.h) {
  659. c.b = 0;
  660. break;
  661. }
  662. a.j = b;
  663. return I(c, a.b.setLocalDescription(a.f), 3);
  664. case 3:
  665. c.h = 4;
  666. var e = a.sdp.a.mid;
  667. g =
  668. "v=0\r\no=- " +
  669. (ja() +
  670. " 2 IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\na=group:BUNDLE ") +
  671. (e +
  672. "\r\na=msid-semantic: WMS *\r\nm=application 9 DTLS/SCTP 5000\r\nc=IN IP4 0.0.0.0\r\nb=AS:30\r\na=ice-ufrag:") +
  673. (b + "\r\na=ice-pwd:") +
  674. (d + "\r\na=ice-options:trickle\r\na=fingerprint:") +
  675. (f + "\r\na=setup:active\r\na=mid:") +
  676. (e +
  677. "\r\na=sendrecv\r\na=sctpmap:5000 webrtc-datachannel 256\r\na=max-message-size:1073741823\r\n");
  678. return I(
  679. c,
  680. a.b.setRemoteDescription(
  681. new RTCSessionDescription({ type: "answer", sdp: g })
  682. ),
  683. 6
  684. );
  685. case 6:
  686. c.b = 5;
  687. c.h = 0;
  688. break;
  689. case 4:
  690. (c.h = 0), (e = c.f.F), (c.f = null), (l = e), console.log(l);
  691. case 5:
  692. a.i && W(a), (a.h = !0), (c.b = 0);
  693. }
  694. });
  695. }
  696. function ma(a, b, d, f, g) {
  697. f
  698. ? ((a.i = !0),
  699. setTimeout(function () {
  700. a.l("1.2.3.4", 1234, !0, !1, !1);
  701. }, 500))
  702. : a.g.push({ ip: b.replace("::ffff:", ""), port: d, from_stun: g });
  703. a.h && a.i && W(a);
  704. }
  705. function Parsec(a) {
  706. var b = this;
  707. this.status = Status.PARSEC_NOT_RUNNING;
  708. this.G = performance.now();
  709. this.f = {
  710. encodeLatency: 0,
  711. decodeLatency: 0,
  712. networkLatency: 0,
  713. frameWidth: 0,
  714. frameHeight: 0,
  715. fullRange: !1,
  716. 444: !1,
  717. };
  718. this.h = [];
  719. this.b = null;
  720. this.B = [];
  721. this.j = "";
  722. this.c = a;
  723. this.l = a.getContext("2d");
  724. this.l.imageSmoothingEnabled = false;
  725. this.l.Z = "high";
  726. this.u = [];
  727. this.s = {};
  728. this.v = 0;
  729. this.o = [];
  730. this.i = this.g = null;
  731. this.B.push(
  732. addEvtListener(window, "beforeunload", function () {
  733. b.D();
  734. return null;
  735. })
  736. );
  737. }
  738. function na(a) {
  739. var last = performance.now();
  740. window.frameInterval = parseInt(
  741. localStorage.getItem("frameInterval") || "40"
  742. );
  743. a.g ||
  744. (a.g = new AudioDecoder({
  745. output: function (b) {
  746. if ("f32" == b.format) {
  747. var d = new ArrayBuffer(
  748. b.allocationSize({ planeIndex: 0 })
  749. );
  750. b.copyTo(d, { planeIndex: 0 });
  751. a.o.push(new Float32Array(d));
  752. b.close();
  753. }
  754. },
  755. error: function (b) {
  756. console.log("Audio decode error:", b);
  757. },
  758. }));
  759. a.i ||
  760. (a.i = new VideoDecoder({
  761. output: function (b) {
  762. window.requestAnimationFrame(function () {
  763. a.f.frameWidth = b.displayWidth;
  764. a.f.frameHeight = b.displayHeight;
  765. a.f.fullRange = b.colorSpace.fullRange;
  766. a.f["444"] = "I444" == b.format;
  767. a.f.decodeLatency =
  768. 0.9 * a.f.decodeLatency +
  769. 0.1 * (performance.now() - b.timestamp / 1e3);
  770. if (window.resizeFlag) {
  771. a.c.width = Math.round(
  772. document.body.clientWidth * window.devicePixelRatio
  773. );
  774. a.c.height = Math.round(
  775. document.body.clientHeight * window.devicePixelRatio
  776. );
  777. window.resizeFlag = false;
  778. }
  779. var d = b.displayWidth / b.displayHeight,
  780. f = 0,
  781. g = 0;
  782. if (
  783. (0 < a.c.height ? a.c.width / a.c.height : 1.77777777) >
  784. d
  785. ) {
  786. var l = a.c.height * d;
  787. d = a.c.height;
  788. f = (a.c.width - l) / 2;
  789. } else (l = a.c.width), (d = a.c.width / d), (g = (a.c.height - d) / 2);
  790. var now = performance.now();
  791. if (now - last > window.frameInterval) {
  792. a.l.drawImage(
  793. b,
  794. 0,
  795. 0,
  796. a.f.frameWidth,
  797. a.f.frameHeight,
  798. f,
  799. g,
  800. l,
  801. d
  802. );
  803. last = now;
  804. }
  805. b.close();
  806. });
  807. },
  808. error: function (b) {
  809. console.log("Video decode error:", b);
  810. },
  811. }));
  812. }
  813. function Y(a) {
  814. a.i && a.i.reset();
  815. a.g && a.g.reset();
  816. a.o = [];
  817. a.l.clearRect(0, 0, a.c.width, a.c.height);
  818. }
  819. function Z(a, b) {
  820. b != Status.PARSEC_OK &&
  821. (a.b && a.status == Status.PARSEC_OK && a.b.send(P(10, 0, 0, 0), 0),
  822. a.b && (a.b.close(), (a.b = null)),
  823. Y(a));
  824. a.status = b;
  825. a.u = [];
  826. a.s = {};
  827. a.v = 0;
  828. }
  829. h = Parsec.prototype;
  830. Parsec.prototype.destroy = function () {
  831. for (var a = q(this.B), b = a.next(); !b.done; b = a.next())
  832. (b = b.value), b[0].removeEventListener(b[1], b[2]);
  833. this.C(Status.PARSEC_NOT_RUNNING);
  834. };
  835. Parsec.prototype.getBufferSize = function (a) {
  836. a = R[a];
  837. return void 0 != a ? a.length : 0;
  838. };
  839. Parsec.prototype.getBuffer = function (a) {
  840. var b = R[a];
  841. void 0 != b && delete R[a];
  842. return void 0 == b ? null : b;
  843. };
  844. Parsec.prototype.clientNewAttempt = function (a) {
  845. var b = this,
  846. d,
  847. f,
  848. g;
  849. return L(function (l) {
  850. if (1 == l.b) {
  851. d =
  852. /Chrome/.test(navigator.userAgent) &&
  853. /Google Inc/.test(navigator.vendor);
  854. if (!d)
  855. return (b.status = Status.PARSEC_WRN_BROWSER), l.return(null);
  856. if (b.status != Status.PARSEC_NOT_RUNNING) return l.return(null);
  857. b.status = Status.PARSEC_CONNECTING;
  858. R = {};
  859. S = 1;
  860. na(b);
  861. Y(b);
  862. b.j = a;
  863. b.h = [];
  864. f = function (c, e, k, m, p) {
  865. b.h.push({
  866. type: 8,
  867. attemptID: b.j,
  868. ip: c,
  869. port: e,
  870. lan: p,
  871. fromStun: m,
  872. sync: k,
  873. });
  874. };
  875. g = function () {
  876. b.B.push(
  877. addEvtListener(document, "visibilitychange", function () {
  878. document.hidden
  879. ? b.b && b.b.send(P(19, 0, 0, 0), 0)
  880. : b.b && b.b.send(P(13, 0, 0, 0), 0);
  881. })
  882. );
  883. var c = window.screen.width,
  884. e = window.screen.height;
  885. if (800 > c || 600 > e || 1920 < c || 1080 < e)
  886. (c = 1920), (e = 1080);
  887. b.b && b.b.send(ea(c, e), 0);
  888. Z(b, Status.PARSEC_OK);
  889. };
  890. b.b = new U(f);
  891. V(b.b, "control", 0, g, function (c) {
  892. b.G = performance.now();
  893. var e = new DataView(c.data);
  894. c = {
  895. m: e.getInt32(0),
  896. A: e.getInt32(4),
  897. V: e.getInt32(8),
  898. type: e.getInt8(12),
  899. };
  900. switch (c.type) {
  901. case 10:
  902. b.status = c.m;
  903. break;
  904. case 21:
  905. b.f.encodeLatency = parseFloat(c.A) / 1e3;
  906. b.f.networkLatency = 0;
  907. break;
  908. case 20:
  909. b.h.push({
  910. type: 2,
  911. gamepadID: c.m,
  912. motorBig: c.A,
  913. motorSmall: c.V,
  914. });
  915. break;
  916. case 16:
  917. b.h.push({ type: c.m ? 4 : 5 });
  918. break;
  919. case 28:
  920. b.v = c.m;
  921. break;
  922. case 17:
  923. b.h.push(ia(c, e));
  924. break;
  925. case 9:
  926. b.h.push(ha(e));
  927. break;
  928. case 25:
  929. e = JSON.parse(
  930. new TextDecoder("utf-8").decode(
  931. new Uint8Array(e.buffer, 13, c.m - 1)
  932. )
  933. );
  934. for (var k = {}, m = 0; m < e.length; m++)
  935. e[m].id == c.A && (k = e[m]);
  936. c = { list: e, me: k };
  937. b.u = c.list;
  938. b.s = c.me;
  939. }
  940. });
  941. V(b.b, "video", 1, null, function (c) {
  942. "configured" != b.i.state &&
  943. b.i.configure({
  944. codec: "avc1.42001e",
  945. hardwareAcceleration: "prefer-hardware",
  946. optimizeForLatency: true,
  947. });
  948. c = new EncodedVideoChunk({
  949. type: "key",
  950. data: c.data,
  951. timestamp: 1e3 * performance.now(),
  952. duration: 1000000,
  953. });
  954. b.i.decode(c);
  955. });
  956. V(b.b, "audio", 2, null, function (c) {
  957. "configured" != b.g.state &&
  958. b.g.configure({
  959. codec: "opus",
  960. sampleRate: 48e3,
  961. numberOfChannels: 2,
  962. });
  963. c = new EncodedAudioChunk({
  964. type: "key",
  965. data: c.data,
  966. timestamp: 1e3 * performance.now(),
  967. duration: 0,
  968. });
  969. b.g.decode(c);
  970. });
  971. return I(l, ka(b.b), 2);
  972. }
  973. return l.return(l.i);
  974. });
  975. };
  976. Parsec.prototype.clientBeginP2P = function (a, b, d, f, g) {
  977. this.j == a && this.b && la(this.b, d, f, g);
  978. };
  979. Parsec.prototype.clientAddCandidate = function (a, b, d, f, g) {
  980. this.j == a && this.b && ma(this.b, b, d, f, g);
  981. };
  982. Parsec.prototype.clientGetStatus = function () {
  983. return this.status;
  984. };
  985. Parsec.prototype.clientGetSelf = function () {
  986. return this.s;
  987. };
  988. Parsec.prototype.clientGetHostMode = function () {
  989. return this.v;
  990. };
  991. Parsec.prototype.clientGetGuests = function () {
  992. return this.u;
  993. };
  994. Parsec.prototype.clientDisconnect = function (a) {
  995. Z(this, a);
  996. };
  997. Parsec.prototype.clientSendUserData = function (a, b) {
  998. this.b && this.status == Status.PARSEC_OK && this.b.send(Q(17, a, b), 0);
  999. };
  1000. Parsec.prototype.clientSendMessage = function (a) {
  1001. this.b &&
  1002. this.status == Status.PARSEC_OK &&
  1003. this.b.send(
  1004. fa(
  1005. a,
  1006. this.f.frameWidth,
  1007. this.f.frameHeight,
  1008. this.c.width,
  1009. this.c.height
  1010. ),
  1011. 0
  1012. );
  1013. };
  1014. Parsec.prototype.clientPollEvents = function () {
  1015. return this.h.shift();
  1016. };
  1017. Parsec.prototype.clientGetMetrics = function () {
  1018. return this.f;
  1019. };
  1020. Parsec.prototype.clientNetworkFailure = function () {
  1021. return this.status == Status.PARSEC_OK && 5e3 < performance.now() - this.G;
  1022. };
  1023. Parsec.prototype.clientPollAudio = function () {
  1024. return this.o.shift();
  1025. };
  1026. Parsec.prototype.Status = Status;
  1027. window.Parsec = Parsec;