comparison Platforms/Wasm/wasm-application.ts @ 236:f73d722d98c8 am

renamed folder
author am@osimis.io
date Tue, 19 Jun 2018 16:06:32 +0200
parents Platforms/WebAssembly/wasm-application.ts@68856534f005
children 126c9c0c9333
comparison
equal deleted inserted replaced
235:ce4405d98b92 236:f73d722d98c8
1 ///<reference path='stone-framework-loader.ts'/>
2 ///<reference path='wasm-viewport.ts'/>
3
4 if (!('WebAssembly' in window)) {
5 alert('Sorry, your browser does not support WebAssembly :(');
6 }
7
8 declare var StoneFrameworkModule : Stone.Framework;
9
10 // global functions
11 var WasmWebService_NotifyError: Function = null;
12 var WasmWebService_NotifySuccess: Function = null;
13 var NotifyUpdateContent: Function = null;
14 var SetStartupParameter: Function = null;
15 var CreateWasmApplication: Function = null;
16 var CreateCppViewport: Function = null;
17 var ReleaseCppViewport: Function = null;
18 var StartWasmApplication: Function = null;
19
20
21 function UpdateContentThread() {
22 if (NotifyUpdateContent != null) {
23 NotifyUpdateContent();
24 }
25
26 setTimeout(UpdateContentThread, 100); // Update the viewport content every 100ms if need be
27 }
28
29
30 function GetUriParameters() {
31 var parameters = window.location.search.substr(1);
32
33 if (parameters != null &&
34 parameters != '') {
35 var result = {};
36 var tokens = parameters.split('&');
37
38 for (var i = 0; i < tokens.length; i++) {
39 var tmp = tokens[i].split('=');
40 if (tmp.length == 2) {
41 result[tmp[0]] = decodeURIComponent(tmp[1]);
42 }
43 }
44
45 return result;
46 }
47 else {
48 return {};
49 }
50 }
51
52 module Stone {
53
54 // export declare type InitializationCallback = () => void;
55
56 // export declare var StoneFrameworkModule : any;
57
58 //const ASSETS_FOLDER : string = "assets/lib";
59 //const WASM_FILENAME : string = "orthanc-framework";
60
61 export class WasmApplication {
62
63 private viewport_: WasmViewport;
64 private canvasId_: string;
65
66 private pimpl_: any; // Private pointer to the underlying WebAssembly C++ object
67
68 public constructor(canvasId: string) {
69 this.canvasId_ = canvasId;
70 //this.module_ = module;
71 }
72 }
73 }
74
75
76 function InitializeWasmApplication(canvasId: string): void {
77
78 /************************************** */
79 CreateWasmApplication();
80
81 // parse uri and transmit the parameters to the app before initializing it
82 var parameters = GetUriParameters();
83
84 for (var key in parameters) {
85 if (parameters.hasOwnProperty(key)) {
86 SetStartupParameter(key, parameters[key]);
87 }
88 }
89
90 StartWasmApplication();
91 /************************************** */
92
93 UpdateContentThread();
94 }
95
96 // Wait for the Orthanc Framework to be initialized (this initializes
97 // the WebAssembly environment) and then, create and initialize the Wasm application
98 Stone.Framework.Initialize(true, function () {
99
100 console.log("Connecting C++ methods to JS methods");
101
102 SetStartupParameter = StoneFrameworkModule.cwrap('SetStartupParameter', null, ['string', 'string']);
103 CreateWasmApplication = StoneFrameworkModule.cwrap('CreateWasmApplication', null, ['number']);
104 CreateCppViewport = StoneFrameworkModule.cwrap('CreateCppViewport', 'number', []);
105 ReleaseCppViewport = StoneFrameworkModule.cwrap('ReleaseCppViewport', null, ['number']);
106 StartWasmApplication = StoneFrameworkModule.cwrap('StartWasmApplication', null, ['number']);
107
108 WasmWebService_NotifySuccess = StoneFrameworkModule.cwrap('WasmWebService_NotifySuccess', null, ['number', 'string', 'array', 'number', 'number']);
109 WasmWebService_NotifyError = StoneFrameworkModule.cwrap('WasmWebService_NotifyError', null, ['number', 'string', 'number']);
110 NotifyUpdateContent = StoneFrameworkModule.cwrap('NotifyUpdateContent', null, []);
111
112 // Prevent scrolling
113 document.body.addEventListener('touchmove', function (event) {
114 event.preventDefault();
115 }, false);
116
117
118 InitializeWasmApplication("canvas");
119 });