|
1 /* |
|
2 * This file is part of the TraKERS\Front IDILL package. |
|
3 * |
|
4 * (c) IRI <http://www.iri.centrepompidou.fr/> |
|
5 * |
|
6 * For the full copyright and license information, please view the LICENSE |
|
7 * file that was distributed with this source code. |
|
8 */ |
|
9 |
|
10 /* |
|
11 * Projet : TraKERS |
|
12 * Module : Front IDILL |
|
13 * Fichier : client.js |
|
14 * |
|
15 * Auteur : alexandre.bastien@iri.centrepompidou.fr |
|
16 * |
|
17 * Fonctionnalités : Définit la "classe" client permettant de recevoir les instructions du Middleware, sous forme de sockets (via le serveur WebSocket du Middleware). |
|
18 */ |
|
19 |
1 /* |
20 /* |
2 * Un client est défini par une socket, qui permettra de recevoir les données du server websocket du Middleware. |
21 * Un client est défini par une socket, qui permettra de recevoir les données du server websocket du Middleware. |
3 * On accède aussi à la mosaïque. |
22 * On accède aussi à la mosaïque. |
4 */ |
23 * Est appelé dans le fichier : |
5 function client(host, port, _mosaic) |
24 * mosaic > fonction loadParameters. |
|
25 */ |
|
26 function Client(host, port, _mosaic) |
6 { |
27 { |
7 this.socket; |
28 this.socket = null; |
8 this.mosaic = _mosaic; |
29 this.mosaic = _mosaic; |
9 |
30 |
10 this.pointerLeft = false; |
31 this.pointerLeft = false; |
11 this.pointerRight = false; |
32 this.pointerRight = false; |
12 this.timePointers = 100; |
33 this.timePointers = 100; |
13 this.pointerLeftTimeout; |
34 this.pointerLeftTimeout = null; |
14 this.pointerRightTimeout; |
35 this.pointerRightTimeout = null; |
15 this.isLeftHanded = false; |
36 this.isLeftHanded = false; |
16 |
37 |
17 this.createWebSocket('ws://' + host + ':' + port + '/'); |
38 this.createWebSocket('ws://' + host + ':' + port + '/'); |
18 } |
39 } |
19 |
40 |
20 /* |
41 /* |
21 * Création et Initialisation des sockets et listeners permettant d'écouter le server. |
42 * Création et Initialisation des sockets et listeners permettant d'écouter le server. |
22 */ |
43 * Est appelé dans le fichier : |
23 client.prototype.createWebSocket = function(host) |
44 * client > fonction Client. |
|
45 */ |
|
46 Client.prototype.createWebSocket = function(host) |
24 { |
47 { |
25 var _this = this; |
48 var _this = this; |
26 |
49 |
27 //Initialise la fonctionnalité websocket du naviguateur. |
50 //Initialise la fonctionnalité websocket du naviguateur. |
28 if(window.MozWebSocket) |
51 if(window.MozWebSocket) |
101 clearTimeout(this.pointerLeftTimeout); |
126 clearTimeout(this.pointerLeftTimeout); |
102 |
127 |
103 if(!this.mosaic.mouseInteractions && this.mosaic.currentMode != 'NO-USER' && this.mosaic.currentMode.indexOf('INCOMING') == -1) |
128 if(!this.mosaic.mouseInteractions && this.mosaic.currentMode != 'NO-USER' && this.mosaic.currentMode.indexOf('INCOMING') == -1) |
104 { |
129 { |
105 // console.log('pt'); |
130 // console.log('pt'); |
106 this.mosaic.refreshMainPointer(x, y); |
131 this.mosaic.refreshPointers(x, y, true); |
107 } |
132 } |
108 |
133 |
109 // /!\ // |
134 // /!\ // |
110 if(!this.mosaic.isMainPointerDisplayed) |
135 if(!this.mosaic.isMainPointerDisplayed) |
111 { |
136 { |
136 this.pointerRight = true; |
161 this.pointerRight = true; |
137 clearTimeout(this.pointerRightTimeout); |
162 clearTimeout(this.pointerRightTimeout); |
138 |
163 |
139 if(!this.mosaic.mouseInteractions && this.mosaic.currentMode != 'NO-USER' && this.mosaic.currentMode.indexOf('INCOMING') == -1) |
164 if(!this.mosaic.mouseInteractions && this.mosaic.currentMode != 'NO-USER' && this.mosaic.currentMode.indexOf('INCOMING') == -1) |
140 { |
165 { |
141 this.mosaic.refreshSecondPointer(x, y); |
166 this.mosaic.refreshPointers(x, y, false); |
142 } |
167 } |
143 |
168 |
144 if(!this.mosaic.isSecondPointerDisplayed) |
169 if(!this.mosaic.isSecondPointerDisplayed) |
145 { |
170 { |
146 this.mosaic.secondPointerDisplay(true); |
171 this.mosaic.secondPointerDisplay(true); |
270 this.mosaic.pointersIdleAvailable = true; |
295 this.mosaic.pointersIdleAvailable = true; |
271 this.mosaic.pointersIdleNeedLaunch = true; |
296 this.mosaic.pointersIdleNeedLaunch = true; |
272 } |
297 } |
273 // /!\/!\ // |
298 // /!\/!\ // |
274 } |
299 } |
275 |
|
276 /* |
|
277 * Permet d'envoyer un message au Middleware (optionnel). |
|
278 */ |
|
279 client.prototype.sendMessage = function(data) |
|
280 { |
|
281 //Si data est un objet, on le change en chaine. |
|
282 if(typeof data === 'object') |
|
283 { |
|
284 data = JSON.stringify(data); |
|
285 } |
|
286 this.socket.send(data); |
|
287 } |
|