@illgrenoble/webx-client 0.1.1

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.
Files changed (201) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +8 -0
  3. package/dist/WebXClient.d.ts +94 -0
  4. package/dist/WebXClient.js +302 -0
  5. package/dist/WebXClient.js.map +1 -0
  6. package/dist/display/WebXCursor.d.ts +28 -0
  7. package/dist/display/WebXCursor.js +94 -0
  8. package/dist/display/WebXCursor.js.map +1 -0
  9. package/dist/display/WebXCursorFactory.d.ts +18 -0
  10. package/dist/display/WebXCursorFactory.js +36 -0
  11. package/dist/display/WebXCursorFactory.js.map +1 -0
  12. package/dist/display/WebXDisplay.d.ts +70 -0
  13. package/dist/display/WebXDisplay.js +248 -0
  14. package/dist/display/WebXDisplay.js.map +1 -0
  15. package/dist/display/WebXSubImage.d.ts +19 -0
  16. package/dist/display/WebXSubImage.js +20 -0
  17. package/dist/display/WebXSubImage.js.map +1 -0
  18. package/dist/display/WebXTextureFactory.d.ts +14 -0
  19. package/dist/display/WebXTextureFactory.js +101 -0
  20. package/dist/display/WebXTextureFactory.js.map +1 -0
  21. package/dist/display/WebXWindow.d.ts +59 -0
  22. package/dist/display/WebXWindow.js +205 -0
  23. package/dist/display/WebXWindow.js.map +1 -0
  24. package/dist/display/WebXWindowProperties.d.ts +14 -0
  25. package/dist/display/WebXWindowProperties.js +17 -0
  26. package/dist/display/WebXWindowProperties.js.map +1 -0
  27. package/dist/display/index.d.ts +7 -0
  28. package/dist/display/index.js +24 -0
  29. package/dist/display/index.js.map +1 -0
  30. package/dist/index.d.ts +8 -0
  31. package/dist/index.js +25 -0
  32. package/dist/index.js.map +1 -0
  33. package/dist/input/WebXKeyboard.d.ts +230 -0
  34. package/dist/input/WebXKeyboard.js +593 -0
  35. package/dist/input/WebXKeyboard.js.map +1 -0
  36. package/dist/input/WebXMouse.d.ts +97 -0
  37. package/dist/input/WebXMouse.js +205 -0
  38. package/dist/input/WebXMouse.js.map +1 -0
  39. package/dist/input/index.d.ts +4 -0
  40. package/dist/input/index.js +21 -0
  41. package/dist/input/index.js.map +1 -0
  42. package/dist/input/keyboard/WebXKeyEvent.d.ts +47 -0
  43. package/dist/input/keyboard/WebXKeyEvent.js +212 -0
  44. package/dist/input/keyboard/WebXKeyEvent.js.map +1 -0
  45. package/dist/input/keyboard/WebXKeyPressEvent.d.ts +13 -0
  46. package/dist/input/keyboard/WebXKeyPressEvent.js +26 -0
  47. package/dist/input/keyboard/WebXKeyPressEvent.js.map +1 -0
  48. package/dist/input/keyboard/WebXKeyUpEvent.d.ts +12 -0
  49. package/dist/input/keyboard/WebXKeyUpEvent.js +28 -0
  50. package/dist/input/keyboard/WebXKeyUpEvent.js.map +1 -0
  51. package/dist/input/keyboard/WebXKeyboardModifierState.d.ts +47 -0
  52. package/dist/input/keyboard/WebXKeyboardModifierState.js +87 -0
  53. package/dist/input/keyboard/WebXKeyboardModifierState.js.map +1 -0
  54. package/dist/input/keyboard/WebXKeyboardUtils.d.ts +9 -0
  55. package/dist/input/keyboard/WebXKeyboardUtils.js +48 -0
  56. package/dist/input/keyboard/WebXKeyboardUtils.js.map +1 -0
  57. package/dist/input/keyboard/WebXKeydownEvent.d.ts +29 -0
  58. package/dist/input/keyboard/WebXKeydownEvent.js +71 -0
  59. package/dist/input/keyboard/WebXKeydownEvent.js.map +1 -0
  60. package/dist/input/keyboard/index.d.ts +6 -0
  61. package/dist/input/keyboard/index.js +23 -0
  62. package/dist/input/keyboard/index.js.map +1 -0
  63. package/dist/input/mouse/WebXMouseState.d.ts +78 -0
  64. package/dist/input/mouse/WebXMouseState.js +104 -0
  65. package/dist/input/mouse/WebXMouseState.js.map +1 -0
  66. package/dist/input/mouse/index.d.ts +1 -0
  67. package/dist/input/mouse/index.js +18 -0
  68. package/dist/input/mouse/index.js.map +1 -0
  69. package/dist/instruction/WebXConnectInstruction.d.ts +4 -0
  70. package/dist/instruction/WebXConnectInstruction.js +12 -0
  71. package/dist/instruction/WebXConnectInstruction.js.map +1 -0
  72. package/dist/instruction/WebXCursorImageInstruction.d.ts +6 -0
  73. package/dist/instruction/WebXCursorImageInstruction.js +16 -0
  74. package/dist/instruction/WebXCursorImageInstruction.js.map +1 -0
  75. package/dist/instruction/WebXImageInstruction.d.ts +7 -0
  76. package/dist/instruction/WebXImageInstruction.js +19 -0
  77. package/dist/instruction/WebXImageInstruction.js.map +1 -0
  78. package/dist/instruction/WebXInstruction.d.ts +13 -0
  79. package/dist/instruction/WebXInstruction.js +34 -0
  80. package/dist/instruction/WebXInstruction.js.map +1 -0
  81. package/dist/instruction/WebXInstructionResponse.d.ts +13 -0
  82. package/dist/instruction/WebXInstructionResponse.js +40 -0
  83. package/dist/instruction/WebXInstructionResponse.js.map +1 -0
  84. package/dist/instruction/WebXInstructionType.d.ts +13 -0
  85. package/dist/instruction/WebXInstructionType.js +38 -0
  86. package/dist/instruction/WebXInstructionType.js.map +1 -0
  87. package/dist/instruction/WebXKeyboardInstruction.d.ts +10 -0
  88. package/dist/instruction/WebXKeyboardInstruction.js +26 -0
  89. package/dist/instruction/WebXKeyboardInstruction.js.map +1 -0
  90. package/dist/instruction/WebXMouseInstruction.d.ts +13 -0
  91. package/dist/instruction/WebXMouseInstruction.js +33 -0
  92. package/dist/instruction/WebXMouseInstruction.js.map +1 -0
  93. package/dist/instruction/WebXQualityInstruction.d.ts +7 -0
  94. package/dist/instruction/WebXQualityInstruction.js +19 -0
  95. package/dist/instruction/WebXQualityInstruction.js.map +1 -0
  96. package/dist/instruction/WebXScreenInstruction.d.ts +4 -0
  97. package/dist/instruction/WebXScreenInstruction.js +12 -0
  98. package/dist/instruction/WebXScreenInstruction.js.map +1 -0
  99. package/dist/instruction/WebXWindowsInstruction.d.ts +4 -0
  100. package/dist/instruction/WebXWindowsInstruction.js +12 -0
  101. package/dist/instruction/WebXWindowsInstruction.js.map +1 -0
  102. package/dist/instruction/index.d.ts +11 -0
  103. package/dist/instruction/index.js +28 -0
  104. package/dist/instruction/index.js.map +1 -0
  105. package/dist/message/WebXCursorImageMessage.d.ts +17 -0
  106. package/dist/message/WebXCursorImageMessage.js +36 -0
  107. package/dist/message/WebXCursorImageMessage.js.map +1 -0
  108. package/dist/message/WebXImageMessage.d.ts +15 -0
  109. package/dist/message/WebXImageMessage.js +32 -0
  110. package/dist/message/WebXImageMessage.js.map +1 -0
  111. package/dist/message/WebXMessage.d.ts +8 -0
  112. package/dist/message/WebXMessage.js +17 -0
  113. package/dist/message/WebXMessage.js.map +1 -0
  114. package/dist/message/WebXMessageType.d.ts +10 -0
  115. package/dist/message/WebXMessageType.js +15 -0
  116. package/dist/message/WebXMessageType.js.map +1 -0
  117. package/dist/message/WebXMouseMessage.d.ts +10 -0
  118. package/dist/message/WebXMouseMessage.js +24 -0
  119. package/dist/message/WebXMouseMessage.js.map +1 -0
  120. package/dist/message/WebXPollMessage.d.ts +4 -0
  121. package/dist/message/WebXPollMessage.js +12 -0
  122. package/dist/message/WebXPollMessage.js.map +1 -0
  123. package/dist/message/WebXScreenMessage.d.ts +12 -0
  124. package/dist/message/WebXScreenMessage.js +16 -0
  125. package/dist/message/WebXScreenMessage.js.map +1 -0
  126. package/dist/message/WebXSubImagesMessage.d.ts +11 -0
  127. package/dist/message/WebXSubImagesMessage.js +24 -0
  128. package/dist/message/WebXSubImagesMessage.js.map +1 -0
  129. package/dist/message/WebXWindowsMessage.d.ts +7 -0
  130. package/dist/message/WebXWindowsMessage.js +16 -0
  131. package/dist/message/WebXWindowsMessage.js.map +1 -0
  132. package/dist/message/index.d.ts +9 -0
  133. package/dist/message/index.js +26 -0
  134. package/dist/message/index.js.map +1 -0
  135. package/dist/tracer/WebXHandler.d.ts +3 -0
  136. package/dist/tracer/WebXHandler.js +3 -0
  137. package/dist/tracer/WebXHandler.js.map +1 -0
  138. package/dist/tracer/WebXInstructionHandler.d.ts +4 -0
  139. package/dist/tracer/WebXInstructionHandler.js +7 -0
  140. package/dist/tracer/WebXInstructionHandler.js.map +1 -0
  141. package/dist/tracer/WebXMessageHandler.d.ts +4 -0
  142. package/dist/tracer/WebXMessageHandler.js +7 -0
  143. package/dist/tracer/WebXMessageHandler.js.map +1 -0
  144. package/dist/tracer/WebXStatsHandler.d.ts +7 -0
  145. package/dist/tracer/WebXStatsHandler.js +7 -0
  146. package/dist/tracer/WebXStatsHandler.js.map +1 -0
  147. package/dist/tracer/index.d.ts +4 -0
  148. package/dist/tracer/index.js +21 -0
  149. package/dist/tracer/index.js.map +1 -0
  150. package/dist/transport/WebXBinarySerializer.d.ts +11 -0
  151. package/dist/transport/WebXBinarySerializer.js +43 -0
  152. package/dist/transport/WebXBinarySerializer.js.map +1 -0
  153. package/dist/transport/WebXInstructionBuffer.d.ts +35 -0
  154. package/dist/transport/WebXInstructionBuffer.js +80 -0
  155. package/dist/transport/WebXInstructionBuffer.js.map +1 -0
  156. package/dist/transport/WebXInstructionEncoder.d.ts +101 -0
  157. package/dist/transport/WebXInstructionEncoder.js +175 -0
  158. package/dist/transport/WebXInstructionEncoder.js.map +1 -0
  159. package/dist/transport/WebXMessageBuffer.d.ts +19 -0
  160. package/dist/transport/WebXMessageBuffer.js +58 -0
  161. package/dist/transport/WebXMessageBuffer.js.map +1 -0
  162. package/dist/transport/WebXMessageDecoder.d.ts +16 -0
  163. package/dist/transport/WebXMessageDecoder.js +156 -0
  164. package/dist/transport/WebXMessageDecoder.js.map +1 -0
  165. package/dist/transport/index.d.ts +5 -0
  166. package/dist/transport/index.js +22 -0
  167. package/dist/transport/index.js.map +1 -0
  168. package/dist/tunnel/WebXDefaultQoSHandler.d.ts +16 -0
  169. package/dist/tunnel/WebXDefaultQoSHandler.js +57 -0
  170. package/dist/tunnel/WebXDefaultQoSHandler.js.map +1 -0
  171. package/dist/tunnel/WebXQoSHandler.d.ts +6 -0
  172. package/dist/tunnel/WebXQoSHandler.js +7 -0
  173. package/dist/tunnel/WebXQoSHandler.js.map +1 -0
  174. package/dist/tunnel/WebXSocketIOTunnel.d.ts +15 -0
  175. package/dist/tunnel/WebXSocketIOTunnel.js +41 -0
  176. package/dist/tunnel/WebXSocketIOTunnel.js.map +1 -0
  177. package/dist/tunnel/WebXTunnel.d.ts +24 -0
  178. package/dist/tunnel/WebXTunnel.js +106 -0
  179. package/dist/tunnel/WebXTunnel.js.map +1 -0
  180. package/dist/tunnel/WebXWebSocketTunnel.d.ts +12 -0
  181. package/dist/tunnel/WebXWebSocketTunnel.js +41 -0
  182. package/dist/tunnel/WebXWebSocketTunnel.js.map +1 -0
  183. package/dist/tunnel/index.d.ts +5 -0
  184. package/dist/tunnel/index.js +22 -0
  185. package/dist/tunnel/index.js.map +1 -0
  186. package/dist/utils/Config.d.ts +4 -0
  187. package/dist/utils/Config.js +10 -0
  188. package/dist/utils/Config.js.map +1 -0
  189. package/dist/utils/WebXAsyncExec.d.ts +5 -0
  190. package/dist/utils/WebXAsyncExec.js +18 -0
  191. package/dist/utils/WebXAsyncExec.js.map +1 -0
  192. package/dist/utils/WebXColourGenerator.d.ts +5 -0
  193. package/dist/utils/WebXColourGenerator.js +27 -0
  194. package/dist/utils/WebXColourGenerator.js.map +1 -0
  195. package/dist/utils/WebXFileSize.d.ts +3 -0
  196. package/dist/utils/WebXFileSize.js +14 -0
  197. package/dist/utils/WebXFileSize.js.map +1 -0
  198. package/dist/utils/index.d.ts +4 -0
  199. package/dist/utils/index.js +21 -0
  200. package/dist/utils/index.js.map +1 -0
  201. package/package.json +43 -0
@@ -0,0 +1,94 @@
1
+ import { WebXQoSHandler, WebXTunnel } from './tunnel';
2
+ import { WebXDisplay } from './display';
3
+ import { WebXKeyboard, WebXMouse, WebXMouseState } from './input';
4
+ import { WebXHandler } from './tracer';
5
+ export declare class WebXClient {
6
+ private _tunnel;
7
+ private readonly _textureFactory;
8
+ private readonly _cursorFactory;
9
+ private _tracers;
10
+ private _onCloseCallback;
11
+ private _display;
12
+ private _mouse;
13
+ private _keyboard;
14
+ get tunnel(): WebXTunnel;
15
+ get tracers(): Map<string, WebXHandler>;
16
+ get display(): WebXDisplay;
17
+ get mouse(): WebXMouse;
18
+ get keyboard(): WebXKeyboard;
19
+ constructor(_tunnel: WebXTunnel);
20
+ connect(onCloseCallback: () => void, data: any): Promise<void>;
21
+ disconnect(): void;
22
+ /**
23
+ *
24
+ * @param containerElement The main container
25
+ * @param screenWidth the screen width
26
+ * @param screenHeight the screen height
27
+ */
28
+ initialise(containerElement: HTMLElement): Promise<WebXDisplay>;
29
+ /**
30
+ *
31
+ * @param containerElement The main container
32
+ * @param screenWidth the screen width
33
+ * @param screenHeight the screen height
34
+ */
35
+ createDisplay(containerElement: HTMLElement, screenWidth: number, screenHeight: number): WebXDisplay;
36
+ /**
37
+ * Create a new mouse and bind it to an element
38
+ * @param element the element to attach the mouse to
39
+ */
40
+ createMouse(element: HTMLElement): WebXMouse;
41
+ /**
42
+ * Create a new keyboard and bind it to an element
43
+ * @param element the element to attach the keyboard to
44
+ */
45
+ createKeyboard(element: HTMLElement): WebXKeyboard;
46
+ /**
47
+ * Sends a mouse event having the properties provided by the given mouse state
48
+ * @param mouseState the state of the mouse to send in the mouse event
49
+ */
50
+ sendMouse(mouseState: WebXMouseState): void;
51
+ /**
52
+ * Sends a key event
53
+ * @param pressed {Boolean} Whether the key is pressed (true) or released (false)
54
+ * @param key {number} the key to send
55
+ */
56
+ sendKeyEvent(key: number, pressed: boolean): void;
57
+ /**
58
+ * Sends a key down event
59
+ * @param key {number} the key to send
60
+ */
61
+ sendKeyDown(key: number): void;
62
+ /**
63
+ * Sends a key up event
64
+ * @param key {number} the key to send
65
+ */
66
+ sendKeyUp(key: number): void;
67
+ /**
68
+ * Register a new tracer handler
69
+ * @param name the name of the tracer (must be unique)
70
+ * @param handler the tracer handler
71
+ */
72
+ registerTracer(name: string, handler: WebXHandler): void;
73
+ resetInputs(): void;
74
+ resizeDisplay(): void;
75
+ /**
76
+ * Unregister a tracer
77
+ * @param name the name of the tracer
78
+ */
79
+ unregisterTracer(name: string): void;
80
+ setQualityIndex(qualityIndex: number): void;
81
+ setQoSHandler(qosHandler: WebXQoSHandler): void;
82
+ getQoSHandler(): WebXQoSHandler;
83
+ private _getScreenMessage;
84
+ private _sendInstruction;
85
+ private _sendRequest;
86
+ private _handleMessage;
87
+ private _handleReceivedBytes;
88
+ private _handleSentBytes;
89
+ private _handleQuality;
90
+ private _onTunnelClosed;
91
+ private _dispose;
92
+ private _addMouseListeners;
93
+ private _addKeyboardListeners;
94
+ }
@@ -0,0 +1,302 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.WebXClient = void 0;
13
+ const instruction_1 = require("./instruction");
14
+ const message_1 = require("./message");
15
+ const display_1 = require("./display");
16
+ const input_1 = require("./input");
17
+ const tracer_1 = require("./tracer");
18
+ const transport_1 = require("./transport");
19
+ class WebXClient {
20
+ constructor(_tunnel) {
21
+ this._tunnel = _tunnel;
22
+ this._tracers = new Map();
23
+ this._textureFactory = new display_1.WebXTextureFactory(this._tunnel);
24
+ this._cursorFactory = new display_1.WebXCursorFactory(this._tunnel);
25
+ }
26
+ get tunnel() {
27
+ return this._tunnel;
28
+ }
29
+ get tracers() {
30
+ return this._tracers;
31
+ }
32
+ get display() {
33
+ return this._display;
34
+ }
35
+ get mouse() {
36
+ return this._mouse;
37
+ }
38
+ get keyboard() {
39
+ return this._keyboard;
40
+ }
41
+ connect(onCloseCallback, data) {
42
+ return __awaiter(this, void 0, void 0, function* () {
43
+ this._onCloseCallback = onCloseCallback;
44
+ yield this._tunnel.connect(data, new transport_1.WebXBinarySerializer(this._textureFactory));
45
+ this._tunnel.handleMessage = this._handleMessage.bind(this);
46
+ this._tunnel.handleReceivedBytes = this._handleReceivedBytes.bind(this);
47
+ this._tunnel.handleSentBytes = this._handleSentBytes.bind(this);
48
+ this._tunnel.onClosed = this._onTunnelClosed.bind(this);
49
+ });
50
+ }
51
+ disconnect() {
52
+ this._tunnel.disconnect();
53
+ }
54
+ /**
55
+ *
56
+ * @param containerElement The main container
57
+ * @param screenWidth the screen width
58
+ * @param screenHeight the screen height
59
+ */
60
+ initialise(containerElement) {
61
+ return __awaiter(this, void 0, void 0, function* () {
62
+ // Request 1. : Get screen size
63
+ try {
64
+ const screenMessage = yield this._getScreenMessage();
65
+ const { width, height } = screenMessage.screenSize;
66
+ // Initialise the display
67
+ this._display = this.createDisplay(containerElement, width, height);
68
+ // Request 2. : Get visible windows
69
+ // Sec request for visible windows
70
+ const windowsMessage = yield this._sendRequest(new instruction_1.WebXWindowsInstruction());
71
+ // Requests 3. - N : Initialise all windows and wait for them to be visible (requests for window images)
72
+ yield this._display.updateWindows(windowsMessage.windows);
73
+ this._display.showScreen();
74
+ // Create mouse and add listeners
75
+ this._mouse = this.createMouse(containerElement);
76
+ this._addMouseListeners();
77
+ // Create keyboard and add listeners
78
+ this._keyboard = this.createKeyboard(document.body);
79
+ this._addKeyboardListeners();
80
+ return this._display;
81
+ }
82
+ catch (error) {
83
+ this._dispose();
84
+ throw new Error(`Failed to initialise display: ${error.message}`);
85
+ }
86
+ });
87
+ }
88
+ /**
89
+ *
90
+ * @param containerElement The main container
91
+ * @param screenWidth the screen width
92
+ * @param screenHeight the screen height
93
+ */
94
+ createDisplay(containerElement, screenWidth, screenHeight) {
95
+ return new display_1.WebXDisplay(containerElement, screenWidth, screenHeight, this._textureFactory, this._cursorFactory);
96
+ }
97
+ /**
98
+ * Create a new mouse and bind it to an element
99
+ * @param element the element to attach the mouse to
100
+ */
101
+ createMouse(element) {
102
+ return new input_1.WebXMouse(element);
103
+ }
104
+ /**
105
+ * Create a new keyboard and bind it to an element
106
+ * @param element the element to attach the keyboard to
107
+ */
108
+ createKeyboard(element) {
109
+ return new input_1.WebXKeyboard(element);
110
+ }
111
+ /**
112
+ * Sends a mouse event having the properties provided by the given mouse state
113
+ * @param mouseState the state of the mouse to send in the mouse event
114
+ */
115
+ sendMouse(mouseState) {
116
+ this._sendInstruction(new instruction_1.WebXMouseInstruction(mouseState.x, mouseState.y, mouseState.getButtonMask()));
117
+ }
118
+ /**
119
+ * Sends a key event
120
+ * @param pressed {Boolean} Whether the key is pressed (true) or released (false)
121
+ * @param key {number} the key to send
122
+ */
123
+ sendKeyEvent(key, pressed) {
124
+ this._sendInstruction(new instruction_1.WebXKeyboardInstruction(key, pressed));
125
+ }
126
+ /**
127
+ * Sends a key down event
128
+ * @param key {number} the key to send
129
+ */
130
+ sendKeyDown(key) {
131
+ this.sendKeyEvent(key, true);
132
+ }
133
+ /**
134
+ * Sends a key up event
135
+ * @param key {number} the key to send
136
+ */
137
+ sendKeyUp(key) {
138
+ this.sendKeyEvent(key, false);
139
+ }
140
+ /**
141
+ * Register a new tracer handler
142
+ * @param name the name of the tracer (must be unique)
143
+ * @param handler the tracer handler
144
+ */
145
+ registerTracer(name, handler) {
146
+ this._tracers.set(name, handler);
147
+ }
148
+ resetInputs() {
149
+ if (this._mouse) {
150
+ this._mouse.reset();
151
+ }
152
+ if (this._keyboard) {
153
+ this._keyboard.reset();
154
+ }
155
+ }
156
+ resizeDisplay() {
157
+ if (this._display) {
158
+ this._display.resize();
159
+ }
160
+ }
161
+ /**
162
+ * Unregister a tracer
163
+ * @param name the name of the tracer
164
+ */
165
+ unregisterTracer(name) {
166
+ const tracer = this._tracers.get(name);
167
+ if (tracer) {
168
+ // perform cleanup
169
+ tracer.destroy();
170
+ this._tracers.delete(name);
171
+ }
172
+ }
173
+ setQualityIndex(qualityIndex) {
174
+ const qualityInstruction = new instruction_1.WebXQualityInstruction(qualityIndex);
175
+ this._sendInstruction(qualityInstruction);
176
+ this._tunnel.getQoSHandler().setQuality(qualityIndex);
177
+ }
178
+ setQoSHandler(qosHandler) {
179
+ this._tunnel.setQoSHandler(qosHandler);
180
+ }
181
+ getQoSHandler() {
182
+ return this._tunnel.getQoSHandler();
183
+ }
184
+ _getScreenMessage() {
185
+ return __awaiter(this, void 0, void 0, function* () {
186
+ // Perform retries on the first instruction (client can sometimes be activated before the server connection$
187
+ // has been fully made (difficult to judge when the webx-engine subscribes to the webx-relay instruction publisher
188
+ let retry = 0;
189
+ while (retry < 3) {
190
+ try {
191
+ return yield this._sendRequest(new instruction_1.WebXScreenInstruction(), 5000);
192
+ }
193
+ catch (error) {
194
+ retry++;
195
+ console.log(`Failed to initialise screen size at attempt ${retry}/3...`);
196
+ if (retry == 3) {
197
+ throw new Error(`unable to get screen size: ${error.message}`);
198
+ }
199
+ }
200
+ }
201
+ });
202
+ }
203
+ _sendInstruction(command) {
204
+ this._tunnel.sendInstruction(command);
205
+ this._tracers.forEach((value) => {
206
+ if (value instanceof tracer_1.WebXInstructionHandler) {
207
+ value.handle(command);
208
+ }
209
+ });
210
+ }
211
+ _sendRequest(command, timeout) {
212
+ return this._tunnel.sendRequest(command, timeout);
213
+ }
214
+ _handleMessage(message) {
215
+ if (!this._display) {
216
+ return;
217
+ }
218
+ if (message.type === message_1.WebXMessageType.WINDOWS) {
219
+ const windows = message.windows;
220
+ this._display.updateWindows(windows);
221
+ }
222
+ else if (message.type === message_1.WebXMessageType.IMAGE) {
223
+ const imageMessage = message;
224
+ // console.log(`Updating image ${windowId} [${texture.image.width}, ${texture.image.height}]\n`);
225
+ this._display.updateImage(imageMessage.windowId, imageMessage.depth, imageMessage.colorMap, imageMessage.alphaMap);
226
+ }
227
+ else if (message.type === message_1.WebXMessageType.SUBIMAGES) {
228
+ const subImagesMessage = message;
229
+ // console.log(`Updating sub images ${windowId}\n`);
230
+ this._display.updateSubImages(subImagesMessage.windowId, subImagesMessage.subImages);
231
+ }
232
+ else if (message.type === message_1.WebXMessageType.MOUSE) {
233
+ const mouseMessage = message;
234
+ this._display.updateMouse(mouseMessage.x, mouseMessage.y, mouseMessage.cursorId);
235
+ }
236
+ this._tracers.forEach((value) => {
237
+ if (value instanceof tracer_1.WebXMessageHandler) {
238
+ value.handle(message);
239
+ }
240
+ });
241
+ }
242
+ _handleReceivedBytes(data) {
243
+ this._tracers.forEach((value) => {
244
+ if (value instanceof tracer_1.WebXStatsHandler) {
245
+ value.handle({ received: data.byteLength, sent: 0 });
246
+ }
247
+ });
248
+ }
249
+ _handleSentBytes(data) {
250
+ this._tracers.forEach((value) => {
251
+ if (value instanceof tracer_1.WebXStatsHandler) {
252
+ value.handle({ received: 0, sent: data.byteLength });
253
+ }
254
+ });
255
+ }
256
+ _handleQuality(data) {
257
+ this._tracers.forEach((value) => {
258
+ if (value instanceof tracer_1.WebXStatsHandler) {
259
+ value.handle({ received: 0, sent: data.byteLength });
260
+ }
261
+ });
262
+ }
263
+ _onTunnelClosed() {
264
+ this._dispose();
265
+ if (this._onCloseCallback) {
266
+ this._onCloseCallback();
267
+ }
268
+ }
269
+ _dispose() {
270
+ if (this._display) {
271
+ this._display.dispose();
272
+ }
273
+ if (this._mouse) {
274
+ this._mouse.dispose();
275
+ }
276
+ if (this._keyboard) {
277
+ this._keyboard.dispose();
278
+ }
279
+ }
280
+ _addMouseListeners() {
281
+ this._mouse.onMouseMove = this._mouse.onMouseOut = (mouseState) => {
282
+ const scale = this._display.scale;
283
+ mouseState.x = mouseState.x / scale;
284
+ mouseState.y = mouseState.y / scale;
285
+ this.sendMouse(mouseState);
286
+ this._display.updateMousePosition(mouseState.x, mouseState.y);
287
+ };
288
+ this._mouse.onMouseDown = this._mouse.onMouseUp = (mouseState) => {
289
+ this.sendMouse(mouseState);
290
+ };
291
+ }
292
+ _addKeyboardListeners() {
293
+ this._keyboard.onKeyDown = key => {
294
+ this.sendKeyDown(key);
295
+ };
296
+ this._keyboard.onKeyUp = key => {
297
+ this.sendKeyUp(key);
298
+ };
299
+ }
300
+ }
301
+ exports.WebXClient = WebXClient;
302
+ //# sourceMappingURL=WebXClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WebXClient.js","sourceRoot":"","sources":["../src/WebXClient.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,+CAOuB;AACvB,uCAQmB;AACnB,uCAA+E;AAC/E,mCAAkE;AAClE,qCAAqG;AACrG,2CAAmD;AAEnD,MAAa,UAAU;IAgCrB,YAAoB,OAAmB;QAAnB,YAAO,GAAP,OAAO,CAAY;QA3B/B,aAAQ,GAA6B,IAAI,GAAG,EAAE,CAAC;QA4BrD,IAAI,CAAC,eAAe,GAAG,IAAI,4BAAkB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC5D,IAAI,CAAC,cAAc,GAAG,IAAI,2BAAiB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC5D,CAAC;IAvBD,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAOK,OAAO,CAAC,eAA2B,EAAE,IAAS;;YAClD,IAAI,CAAC,gBAAgB,GAAG,eAAe,CAAC;YACxC,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,gCAAoB,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC;YAEjF,IAAI,CAAC,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC5D,I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QAChE,CAAC,CAAC;QAEF,IAAI,CAAC,MAAM,CAAC,WAAW,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,GAAG,CAAC,UAA0B,EAAE,EAAE;YAC/E,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QAC7B,CAAC,CAAC;IACJ,CAAC;IAEO,qBAAqB;QAC3B,IAAI,CAAC,SAAS,CAAC,SAAS,GAAG,GAAG,CAAC,EAAE;YAC/B,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;QACxB,CAAC,CAAC;QAEF,IAAI,CAAC,SAAS,CAAC,OAAO,GAAG,GAAG,CAAC,EAAE;YAC7B,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;QACtB,CAAC,CAAC;IACJ,CAAC;CACF;AA7UD,gCA6UC"}
@@ -0,0 +1,28 @@
1
+ import * as THREE from 'three';
2
+ import { Texture } from 'three';
3
+ import { WebXCursorFactory } from './WebXCursorFactory';
4
+ export declare class WebXCursor {
5
+ private _cursorFactory;
6
+ private static _PLANE_GEOMETRY;
7
+ private _cursorId;
8
+ private _texture;
9
+ private readonly _material;
10
+ private readonly _mesh;
11
+ private _x;
12
+ private _y;
13
+ private _xHot;
14
+ private _yHot;
15
+ private _width;
16
+ private _height;
17
+ get mesh(): THREE.Mesh;
18
+ get cursorId(): number;
19
+ get texture(): Texture;
20
+ set x(value: number);
21
+ set y(value: number);
22
+ constructor(_cursorFactory: WebXCursorFactory);
23
+ setPosition(x: number, y: number): void;
24
+ updateCursorId(x: number, y: number, cursorId: number): void;
25
+ update(x: number, y: number, xHot: number, yHot: number, cursorId: number, texture: Texture): void;
26
+ private _updateScale;
27
+ private _updatePosition;
28
+ }
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WebXCursor = void 0;
4
+ const THREE = require("three");
5
+ const three_1 = require("three");
6
+ class WebXCursor {
7
+ constructor(_cursorFactory) {
8
+ this._cursorFactory = _cursorFactory;
9
+ this._xHot = 0;
10
+ this._yHot = 0;
11
+ this._width = 1;
12
+ this._height = 1;
13
+ this._material = new THREE.MeshBasicMaterial({ transparent: true });
14
+ this._material.side = THREE.BackSide;
15
+ this._material.transparent = true;
16
+ this._material.visible = false;
17
+ this._mesh = new THREE.Mesh(WebXCursor._PLANE_GEOMETRY, this._material);
18
+ this._cursorId = 0;
19
+ this._x = 0;
20
+ this._y = 0;
21
+ this._xHot = 0;
22
+ this._yHot = 0;
23
+ this._width = 16;
24
+ this._height = 20;
25
+ this._updateScale();
26
+ this._updatePosition();
27
+ this._cursorFactory.getCursor().then(cursorData => {
28
+ const cursor = cursorData.cursor;
29
+ if (this._cursorId === 0 || this._cursorId === cursor.cursorId)
30
+ this.update(cursorData.x, cursorData.y, cursor.xHot, cursor.yHot, cursor.cursorId, cursor.texture);
31
+ });
32
+ }
33
+ get mesh() {
34
+ return this._mesh;
35
+ }
36
+ get cursorId() {
37
+ return this._cursorId;
38
+ }
39
+ get texture() {
40
+ return this._texture;
41
+ }
42
+ set x(value) {
43
+ this._x = value;
44
+ this._updatePosition();
45
+ }
46
+ set y(value) {
47
+ this._y = value;
48
+ this._updatePosition();
49
+ }
50
+ setPosition(x, y) {
51
+ this._x = x;
52
+ this._y = y;
53
+ this._updatePosition();
54
+ }
55
+ updateCursorId(x, y, cursorId) {
56
+ this._x = x;
57
+ this._y = y;
58
+ this._cursorId = cursorId;
59
+ this._cursorFactory.getCursor(cursorId).then(cursorData => {
60
+ const cursor = cursorData.cursor;
61
+ if (this._cursorId === 0 || this._cursorId === cursor.cursorId)
62
+ this.update(cursorData.x != null ? cursorData.x : this._x, cursorData.y != null ? cursorData.y : this._y, cursor.xHot, cursor.yHot, cursor.cursorId, cursor.texture);
63
+ });
64
+ this._updatePosition();
65
+ }
66
+ update(x, y, xHot, yHot, cursorId, texture) {
67
+ this._x = x;
68
+ this._y = y;
69
+ this._xHot = xHot;
70
+ this._yHot = yHot;
71
+ this._cursorId = cursorId;
72
+ if (texture != null && texture.image != null) {
73
+ this._width = texture.image.width;
74
+ this._height = texture.image.height;
75
+ this._texture = texture;
76
+ this._texture.minFilter = three_1.LinearFilter;
77
+ this._texture.repeat.set(this._width / this._texture.image.width, this._height / this._texture.image.height);
78
+ this._material.map = texture;
79
+ this._material.visible = true;
80
+ this._material.needsUpdate = true;
81
+ }
82
+ this._updateScale();
83
+ this._updatePosition();
84
+ }
85
+ _updateScale() {
86
+ this._mesh.scale.set(this._width, this._height, 1);
87
+ }
88
+ _updatePosition() {
89
+ this._mesh.position.set(this._x - this._xHot + 0.5 * this._width, this._y - this._yHot + 0.5 * this._height, 999);
90
+ }
91
+ }
92
+ exports.WebXCursor = WebXCursor;
93
+ WebXCursor._PLANE_GEOMETRY = new THREE.PlaneGeometry(1.0, 1.0, 2, 2);
94
+ //# sourceMappingURL=WebXCursor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WebXCursor.js","sourceRoot":"","sources":["../../src/display/WebXCursor.ts"],"names":[],"mappings":";;;AAAA,+BAA+B;AAC/B,iCAA8C;AAG9C,MAAa,UAAU;IAqCrB,YAAoB,cAAiC;QAAjC,mBAAc,GAAd,cAAc,CAAmB;QA3B7C,UAAK,GAAW,CAAC,CAAC;QAClB,UAAK,GAAW,CAAC,CAAC;QAClB,WAAM,GAAW,CAAC,CAAC;QACnB,YAAO,GAAW,CAAC,CAAC;QAyB1B,IAAI,CAAC,SAAS,GAAG,IAAI,KAAK,CAAC,iBAAiB,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC;QACpE,IAAI,CAAC,SAAS,CAAC,IAAI,GAAG,KAAK,CAAC,QAAQ,CAAC;QACrC,IAAI,CAAC,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC;QAClC,IAAI,CAAC,SAAS,CAAC,OAAO,GAAG,KAAK,CAAC;QAE/B,IAAI,CAAC,KAAK,GAAG,IAAI,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,eAAe,EAAE,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AAG,IAAI,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;IACpH,CAAC;;AAjHH,gCAkHC;AAjHgB,0BAAe,GAAwB,IAAI,KAAK,CAAC,aAAa,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC"}
@@ -0,0 +1,18 @@
1
+ import { WebXTunnel } from '../tunnel';
2
+ import { Texture } from 'three';
3
+ export interface WebXCursorData {
4
+ xHot: number;
5
+ yHot: number;
6
+ cursorId: number;
7
+ texture: Texture;
8
+ }
9
+ export declare class WebXCursorFactory {
10
+ private _tunnel;
11
+ private _cursorMap;
12
+ constructor(_tunnel: WebXTunnel);
13
+ getCursor(cursorId?: number): Promise<{
14
+ x?: number;
15
+ y?: number;
16
+ cursor: WebXCursorData;
17
+ }>;
18
+ }
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WebXCursorFactory = void 0;
4
+ const instruction_1 = require("../instruction");
5
+ class WebXCursorFactory {
6
+ constructor(_tunnel) {
7
+ this._tunnel = _tunnel;
8
+ this._cursorMap = new Map();
9
+ }
10
+ getCursor(cursorId) {
11
+ return new Promise((resolve) => {
12
+ const cursorData = this._cursorMap.get(cursorId);
13
+ if (cursorData != null) {
14
+ resolve({ cursor: cursorData });
15
+ }
16
+ else {
17
+ this._tunnel.sendRequest(new instruction_1.WebXCursorImageInstruction(cursorId)).then((response) => {
18
+ const newCursorData = {
19
+ xHot: response.xHot,
20
+ yHot: response.yHot,
21
+ cursorId: response.cursorId,
22
+ texture: response.texture
23
+ };
24
+ this._cursorMap.set(response.cursorId, newCursorData);
25
+ resolve({
26
+ x: response.x,
27
+ y: response.y,
28
+ cursor: newCursorData
29
+ });
30
+ });
31
+ }
32
+ });
33
+ }
34
+ }
35
+ exports.WebXCursorFactory = WebXCursorFactory;
36
+ //# sourceMappingURL=WebXCursorFactory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WebXCursorFactory.js","sourceRoot":"","sources":["../../src/display/WebXCursorFactory.ts"],"names":[],"mappings":";;;AAEA,gDAA4D;AAU5D,MAAa,iBAAiB;IAG5B,YAAoB,OAAmB;QAAnB,YAAO,GAAP,OAAO,CAAY;QAF/B,eAAU,GAAgC,IAAI,GAAG,EAAE,CAAC;IAElB,CAAC;IAEpC,SAAS,CAAC,QAAiB;QAChC,OAAO,IAAI,OAAO,CAAqD,CAAC,OAAO,EAAE,EAAE;YACjF,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YACjD,IAAI,UAAU,IAAI,IAAI,EAAE;gBACtB,OAAO,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC,CAAC;aACjC;iBAAM;gBACL,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,wCAA0B,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,QAAgC,EAAE,EAAE;oBAC3G,MAAM,aAAa,GAAG;wBACpB,IAAI,EAAE,QAAQ,CAAC,IAAI;wBACnB,IAAI,EAAE,QAAQ,CAAC,IAAI;wBACnB,QAAQ,EAAE,QAAQ,CAAC,QAAQ;wBAC3B,OAAO,EAAE,QAAQ,CAAC,OAAO;qBAC1B,CAAA;oBAED,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC;oBAEtD,OAAO,CAAC;wBACN,CAAC,EAAE,QAAQ,CAAC,CAAC;wBACb,CAAC,EAAE,QAAQ,CAAC,CAAC;wBACb,MAAM,EAAE,aAAa;qBACtB,CAAC,CAAC;gBACL,CAAC,CAAC,CAAC;aACJ;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AA9BD,8CA8BC"}
@@ -0,0 +1,70 @@
1
+ import * as THREE from 'three';
2
+ import { Texture } from 'three';
3
+ import { WebXWindow } from './WebXWindow';
4
+ import { WebXWindowProperties } from './WebXWindowProperties';
5
+ import { WebXSubImage } from './WebXSubImage';
6
+ import { WebXTextureFactory } from './WebXTextureFactory';
7
+ import { WebXCursorFactory } from './WebXCursorFactory';
8
+ export declare class WebXDisplay {
9
+ private readonly _scene;
10
+ private readonly _camera;
11
+ private readonly _renderer;
12
+ private readonly _screen;
13
+ private readonly _screenWidth;
14
+ private readonly _screenHeight;
15
+ private readonly _textureFactory;
16
+ private readonly _containerElement;
17
+ private _windows;
18
+ private _cursor;
19
+ private _scale;
20
+ private _displayElement;
21
+ private _boundsElement;
22
+ private _disposed;
23
+ get renderer(): THREE.WebGLRenderer;
24
+ get screenWidth(): number;
25
+ get screenHeight(): number;
26
+ get containerElement(): HTMLElement;
27
+ get scale(): number;
28
+ get scene(): THREE.Scene;
29
+ constructor(containerElement: HTMLElement, screenWidth: number, screenHeight: number, textureFactory: WebXTextureFactory, cursorFactory: WebXCursorFactory);
30
+ showScreen(): void;
31
+ hideScreen(): void;
32
+ dispose(): void;
33
+ animate(): void;
34
+ addWindow(window: WebXWindow): void;
35
+ removeWindow(window: WebXWindow): void;
36
+ updateWindows(windows: Array<WebXWindowProperties>): Promise<void>;
37
+ checkVisibility(windowIds: number[]): boolean;
38
+ updateImage(windowId: number, depth: number, colorMap: Texture, alphaMap: Texture): void;
39
+ updateSubImages(windowId: number, subImages: WebXSubImage[]): void;
40
+ updateMouse(x: number, y: number, cursorId: number): void;
41
+ updateMousePosition(x: number, y: number): void;
42
+ getWindow(id: number): WebXWindow;
43
+ /**
44
+ * Set the scale
45
+ * @param scale the scale (between 0 and 1)
46
+ */
47
+ setScale(scale: number): void;
48
+ /**
49
+ * Scale automatically
50
+ */
51
+ autoScale(): void;
52
+ /**
53
+ * Update the screen scale
54
+ * @param scale between 0 and 1 or empty. If empty then the display will autoscale
55
+ * to fit the dimensions of its container
56
+ */
57
+ resize(scale?: number): void;
58
+ private _clearElements;
59
+ private _createDisplayElement;
60
+ private _createDisplayBoundingElement;
61
+ /**
62
+ * Render the display to the screen
63
+ */
64
+ private _render;
65
+ /**
66
+ * Bind the event listeners
67
+ */
68
+ private _bindListeners;
69
+ private _handleWindowRefresh;
70
+ }