equal
deleted
inserted
replaced
19 |
19 |
20 /* |
20 /* |
21 * 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. |
22 * On accède aussi à la classe des pointeurs. |
22 * On accède aussi à la classe des pointeurs. |
23 */ |
23 */ |
24 function client(host, port, _pointers) |
24 function Client(host, port, _pointers) |
25 { |
25 { |
26 this.socket; |
26 this.socket; |
27 this.pointers = _pointers; |
27 this.pointers = _pointers; |
28 |
28 |
29 this.pointerLeft = false; |
29 this.pointerLeft = false; |
37 } |
37 } |
38 |
38 |
39 /* |
39 /* |
40 * Création et Initialisation des sockets et listeners permettant d'écouter le server. |
40 * Création et Initialisation des sockets et listeners permettant d'écouter le server. |
41 */ |
41 */ |
42 client.prototype.createWebSocket = function(host) |
42 Client.prototype.createWebSocket = function(host) |
43 { |
43 { |
44 var _this = this; |
44 var _this = this; |
45 |
45 |
46 //Initialise la fonctionnalité websocket du naviguateur. |
46 //Initialise la fonctionnalité websocket du naviguateur. |
47 if(window.MozWebSocket) |
47 if(window.MozWebSocket) |
85 } |
85 } |
86 |
86 |
87 /* |
87 /* |
88 * Traite un message reçu du Middleware. |
88 * Traite un message reçu du Middleware. |
89 */ |
89 */ |
90 client.prototype.processMsg = function(msg) |
90 Client.prototype.processMsg = function(msg) |
91 { |
91 { |
92 if(typeof msg === 'undefined' || typeof msg.data === 'undefined') |
92 if(typeof msg === 'undefined' || typeof msg.data === 'undefined') |
93 { |
93 { |
94 return; |
94 return; |
95 } |
95 } |
109 |
109 |
110 if(!this.pointers.isMainPointerDisplayed) |
110 if(!this.pointers.isMainPointerDisplayed) |
111 { |
111 { |
112 this.pointers.mainPointerDisplay(true); |
112 this.pointers.mainPointerDisplay(true); |
113 this.pointers.isMainPointerDisplayed = true; |
113 this.pointers.isMainPointerDisplayed = true; |
|
114 |
|
115 this.pointers.textUpdate(); |
114 } |
116 } |
115 |
117 |
116 this.pointerLeftTimeout = setTimeout(function() |
118 this.pointerLeftTimeout = setTimeout(function() |
117 { |
119 { |
118 _this.pointerLeft = false; |
120 _this.pointerLeft = false; |
119 |
121 |
120 if(_this.pointers.isMainPointerDisplayed) |
122 if(_this.pointers.isMainPointerDisplayed) |
121 { |
123 { |
122 _this.pointers.isMainPointerDisplayed = false; |
124 _this.pointers.isMainPointerDisplayed = false; |
123 _this.pointers.mainPointerDisplay(false); |
125 _this.pointers.mainPointerDisplay(false); |
|
126 |
|
127 _this.pointers.textUpdate(); |
124 } |
128 } |
125 }, this.timePointers); |
129 }, this.timePointers); |
126 } |
130 } |
127 //Sinon si ce sont les coordonnées de la main gauche. |
131 //Sinon si ce sont les coordonnées de la main gauche. |
128 else if(msg.data[0] == '0') |
132 else if(msg.data[0] == '0') |
138 |
142 |
139 if(!this.pointers.isSecondPointerDisplayed) |
143 if(!this.pointers.isSecondPointerDisplayed) |
140 { |
144 { |
141 this.pointers.secondPointerDisplay(true); |
145 this.pointers.secondPointerDisplay(true); |
142 this.pointers.isSecondPointerDisplayed = true; |
146 this.pointers.isSecondPointerDisplayed = true; |
|
147 |
|
148 this.pointers.textUpdate(); |
143 } |
149 } |
144 |
150 |
145 this.pointerRightTimeout = setTimeout(function() |
151 this.pointerRightTimeout = setTimeout(function() |
146 { |
152 { |
147 _this.pointerRight = false; |
153 _this.pointerRight = false; |
148 |
154 |
149 if(_this.pointers.isSecondPointerDisplayed) |
155 if(_this.pointers.isSecondPointerDisplayed) |
150 { |
156 { |
151 _this.pointers.isSecondPointerDisplayed = false; |
157 _this.pointers.isSecondPointerDisplayed = false; |
152 _this.pointers.secondPointerDisplay(false); |
158 _this.pointers.secondPointerDisplay(false); |
|
159 |
|
160 _this.pointers.textUpdate(); |
153 } |
161 } |
154 }, this.timePointers); |
162 }, this.timePointers); |
155 } |
163 } |
156 |
164 |
157 if(this.pointerLeft && !this.pointerRight || !this.pointerLeft && this.pointerRight || !this.pointerLeft && !this.pointerRight) |
165 if(this.pointerLeft && !this.pointerRight || !this.pointerLeft && this.pointerRight || !this.pointerLeft && !this.pointerRight) |
158 { |
166 { |
159 this.pointers.areBothPointersHere = false; |
167 this.pointers.areBothPointersHere = false; |
|
168 this.pointers.textUpdate(); |
160 } |
169 } |
161 } |
170 } |