223
|
1
|
|
2
|
|
3 // Global context used by "library.js"
|
|
4 var viewport = null;
|
|
5 var WasmWebService_NotifyError = null;
|
|
6 var WasmWebService_NotifySuccess = null;
|
|
7 //var NotifyRestApiGet = null;
|
|
8 var NotifyUpdateContent = null;
|
|
9
|
|
10 function UpdateContentThread()
|
|
11 {
|
|
12 if (NotifyUpdateContent != null) {
|
|
13 NotifyUpdateContent();
|
|
14 }
|
|
15
|
|
16 setTimeout(UpdateContentThread, 100); // Update the viewport content every 100ms if need be
|
|
17 }
|
|
18
|
|
19
|
|
20 function GetUriParameters()
|
|
21 {
|
|
22 var parameters = window.location.search.substr(1);
|
|
23
|
|
24 if (parameters != null &&
|
|
25 parameters != '')
|
|
26 {
|
|
27 var result = {};
|
|
28 var tokens = parameters.split('&');
|
|
29
|
|
30 for (var i = 0; i < tokens.length; i++) {
|
|
31 var tmp = tokens[i].split('=');
|
|
32 if (tmp.length == 2) {
|
|
33 result[tmp[0]] = decodeURIComponent(tmp[1]);
|
|
34 }
|
|
35 }
|
|
36
|
|
37 return result;
|
|
38 }
|
|
39 else
|
|
40 {
|
|
41 return {};
|
|
42 }
|
|
43 }
|
|
44
|
|
45
|
|
46
|
|
47 function InitializeWasmApplication(canvasId)
|
|
48 {
|
|
49 console.log("Initializing wasm-app");
|
|
50
|
227
|
51 console.log("Connecting C++ methods to JS methods");
|
223
|
52 SetStartupParameter = StoneFrameworkModule.cwrap('SetStartupParameter', null, [ 'string', 'string' ]);
|
227
|
53 CreateWasmApplication = StoneFrameworkModule.cwrap('CreateWasmApplication', null, [ 'any' ], [ ]);
|
|
54 CreateCppViewport = StoneFrameworkModule.cwrap('CreateCppViewport', 'any', [ ], [ ]);
|
|
55 ReleaseCppViewport = StoneFrameworkModule.cwrap('ReleaseCppViewport', null, [ 'any' ], [ ]);
|
223
|
56 StartWasmApplication = StoneFrameworkModule.cwrap('StartWasmApplication', null, [ ], [ ]);
|
|
57 WasmWebService_NotifySuccess = StoneFrameworkModule.cwrap('WasmWebService_NotifySuccess', null,
|
|
58 [ 'number', 'string', 'array', 'number', 'number' ]);
|
|
59 WasmWebService_NotifyError = StoneFrameworkModule.cwrap('WasmWebService_NotifyError', null,
|
|
60 [ 'number', 'string', 'number' ]);
|
|
61 NotifyUpdateContent = StoneFrameworkModule.cwrap('NotifyUpdateContent', null, [ ]);
|
227
|
62
|
|
63 console.log("Creating main viewport");
|
|
64
|
|
65 viewport = new Stone.WasmViewport(StoneFrameworkModule, 'canvas');
|
|
66 viewport.Initialize(CreateCppViewport());
|
223
|
67
|
|
68 // Prevent scrolling
|
|
69 document.body.addEventListener('touchmove', function(event) {
|
|
70 event.preventDefault();
|
|
71 }, false);
|
|
72
|
|
73 document.getElementById('canvas').onclick = function() {
|
|
74 viewport.Redraw();
|
|
75 };
|
|
76
|
|
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 if (!('WebAssembly' in window)) {
|
|
97 alert('Sorry, your browser does not support WebAssembly :(');
|
|
98 } else {
|
|
99
|
|
100 }
|