@supraio/client-daemon-js 0.0.1-changedeploystructure.5 → 0.0.1-master.10

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.
@@ -0,0 +1 @@
1
+ export declare function injectScript(url: string): Promise<void>;
@@ -0,0 +1 @@
1
+ export declare const FORCE_PLAIN_KEY = "_forcePlain";
@@ -0,0 +1,5 @@
1
+ /// <reference types="node" />
2
+ declare global {
3
+ type NodeBuffer = Buffer;
4
+ }
5
+ export declare function initBrowserFS(): Promise<any>;
package/go/go.d.ts ADDED
@@ -0,0 +1,25 @@
1
+ /// <reference types="node" />
2
+ import nodeFs from 'fs';
3
+ declare global {
4
+ class Go {
5
+ /** Accessed by x264/decode_wasm.go directly to optimize memory usage */
6
+ h264: WebAssembly.Memory;
7
+ env: {
8
+ [name: string]: string;
9
+ };
10
+ importObject: WebAssembly.Imports;
11
+ argv: string[];
12
+ run(instance: WebAssembly.Instance): Promise<void>;
13
+ }
14
+ interface Window {
15
+ /** Make it global accessible for wasm_exec.js */
16
+ fs: typeof nodeFs;
17
+ module: any;
18
+ Go: new () => Go;
19
+ }
20
+ }
21
+ export declare function getGoEnv(): {
22
+ HOME: string;
23
+ USER: string;
24
+ };
25
+ export declare function initGoEnvironment(): Promise<void>;
package/package.json CHANGED
@@ -1,11 +1,14 @@
1
1
  {
2
2
  "name": "@supraio/client-daemon-js",
3
- "version": "0.0.1-changedeploystructure.5",
3
+ "version": "0.0.1-master.10",
4
4
  "description": "",
5
- "main": "daemon.js",
5
+ "main": "sdk.js",
6
6
  "scripts": {
7
- "build-daemon": "esbuild --bundle --sourcemap --target=chrome88,firefox86,edge89 --outfile=dist/daemon.js daemon.ts",
8
- "build-screen": "esbuild --bundle --sourcemap --target=chrome88,firefox86,edge89 --outfile=dist/screen.js screen.ts",
7
+ "build-daemon": "esbuild --bundle --sourcemap --target=chrome79,firefox86,edge89 --outfile=dist/daemon.js daemon.ts",
8
+ "build-screen": "esbuild --bundle --sourcemap --target=chrome79,firefox86,edge89 --outfile=dist/screen.js screen.ts",
9
+ "build-sdk": "esbuild --bundle --sourcemap --target=chrome79,firefox86,edge89 --outfile=dist/sdk.js --format=cjs sdk.ts",
10
+ "build-types": "tsc --declaration --emitDeclarationOnly",
11
+ "clean": "rm -rf dist/*",
9
12
  "check": "tsc --noEmit",
10
13
  "lint": "eslint \"**/*.ts\""
11
14
  },
@@ -0,0 +1,10 @@
1
+ export interface IScreenOptions {
2
+ screenID: string;
3
+ screenDriver: string;
4
+ screenHost: string;
5
+ metadataDriver: string;
6
+ metadataHost: string;
7
+ clientID: string;
8
+ clientSecret: string;
9
+ secure: boolean;
10
+ }
@@ -0,0 +1 @@
1
+ export declare function startPlainScreen(): Promise<void>;
@@ -0,0 +1,10 @@
1
+ import '../go/go';
2
+ import { H264Decoder } from 'h264decoder';
3
+ import { IScreenOptions } from './options';
4
+ declare global {
5
+ interface Window {
6
+ /** Make it global accessible for x264/decode_wasm.go */
7
+ h264Decoder: H264Decoder;
8
+ }
9
+ }
10
+ export declare function startWasmScreen(options?: IScreenOptions): Promise<void>;
package/screen.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {};
package/screen.js CHANGED
@@ -17233,14 +17233,14 @@
17233
17233
  return;
17234
17234
  }
17235
17235
  return origClose.call(this, ...args, function(err) {
17236
- return callback.call(this, err ?? null);
17236
+ return callback.call(this, err != null ? err : null);
17237
17237
  });
17238
17238
  };
17239
17239
  const origMkdir = fs.mkdir;
17240
17240
  fs.mkdir = function(...args) {
17241
17241
  const callback = args.pop();
17242
17242
  return origMkdir.call(this, ...args, function(err, path) {
17243
- return callback.call(this, err ?? null, path);
17243
+ return callback.call(this, err != null ? err : null, path);
17244
17244
  });
17245
17245
  };
17246
17246
  const origWrite = fs.write;
@@ -17275,12 +17275,25 @@
17275
17275
  }
17276
17276
 
17277
17277
  // go/go.ts
17278
+ var WASM_EXEC_URL = "wasm_exec.js";
17278
17279
  function getGoEnv() {
17279
17280
  return {
17280
17281
  HOME: "/",
17281
17282
  USER: "unknown"
17282
17283
  };
17283
17284
  }
17285
+ async function initGoEnvironment() {
17286
+ if (!window.fs) {
17287
+ const fs = await initBrowserFS();
17288
+ window.fs = fs;
17289
+ }
17290
+ if (!window.module) {
17291
+ window.module = {};
17292
+ }
17293
+ if (!window.Go) {
17294
+ await injectScript(WASM_EXEC_URL);
17295
+ }
17296
+ }
17284
17297
 
17285
17298
  // screen/plain.ts
17286
17299
  var SCREEN_JS_URL = "supra-client-screen.js";
@@ -17431,16 +17444,12 @@
17431
17444
 
17432
17445
  // screen/wasm.ts
17433
17446
  var SCREEN_WASM_URL = "supra-client-screen.wasm";
17434
- var WASM_EXEC_URL = "wasm_exec.js";
17435
- async function startWasmScreen() {
17436
- const options = parseQueryOptions();
17437
- const fs = await initBrowserFS();
17447
+ async function startWasmScreen(options) {
17448
+ const screenOptions = options != null ? options : parseQueryOptions();
17438
17449
  const h264Decoder = await createH264Decoder();
17439
17450
  window.h264Decoder = h264Decoder;
17440
- window.fs = fs;
17441
- window.module = {};
17442
- await injectScript(WASM_EXEC_URL);
17443
- await startGoScreen(h264Decoder, options);
17451
+ await initGoEnvironment();
17452
+ await startGoScreen(h264Decoder, screenOptions);
17444
17453
  }
17445
17454
  function parseQueryOptions() {
17446
17455
  const params = import_querystring.default.parse(window.location.search.substr(1));
@@ -17476,7 +17485,7 @@
17476
17485
  return h264Decoder;
17477
17486
  }
17478
17487
  async function startGoScreen(h264Decoder, options) {
17479
- const go = new Go();
17488
+ const go = new window.Go();
17480
17489
  go.h264 = h264Decoder.memory;
17481
17490
  const result = await WebAssembly.instantiateStreaming(fetch(SCREEN_WASM_URL), go.importObject);
17482
17491
  go.env = getGoEnv();
@@ -17497,6 +17506,15 @@
17497
17506
  ];
17498
17507
  }
17499
17508
 
17509
+ // sdk.ts
17510
+ async function startScreen(options) {
17511
+ if (localStorage.getItem(FORCE_PLAIN_KEY) || window.WebAssembly === void 0) {
17512
+ await startPlainScreen();
17513
+ } else {
17514
+ await startWasmScreen(options);
17515
+ }
17516
+ }
17517
+
17500
17518
  // screen.ts
17501
17519
  window.addEventListener("contextmenu", (ev) => ev.preventDefault());
17502
17520
  window.addEventListener("beforeunload", (ev) => {
@@ -17504,13 +17522,11 @@
17504
17522
  });
17505
17523
  window.addEventListener("load", async () => {
17506
17524
  try {
17507
- if (localStorage.getItem(FORCE_PLAIN_KEY) || window.WebAssembly === void 0) {
17508
- await startPlainScreen();
17509
- } else {
17510
- await startWasmScreen();
17511
- }
17525
+ await startScreen();
17526
+ } catch (error) {
17527
+ console.error("Error process", error);
17512
17528
  } finally {
17513
- console.error("Reloading window");
17529
+ console.log("Reloading window");
17514
17530
  location.reload();
17515
17531
  }
17516
17532
  });