parsec.raw.js 29 KB

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