blinker / firefox.plugin / data / websockethtmlscript.js @ e75d6b65
History | View | Annotate | Download (2.033 KB)
1 | a03cd52e | Thies Pfeiffer | /*
|
---|---|---|---|
2 | * Copyright 2015 Thies Pfeiffer and Dimitri Heil
|
||
3 | * Blinker is distributed under the terms of the GNU General Public License
|
||
4 | *
|
||
5 | * This file is part of Blinker.
|
||
6 | *
|
||
7 | * Blinker is free software: you can redistribute it and/or modify
|
||
8 | * it under the terms of the GNU General Public License as published by
|
||
9 | * the Free Software Foundation, either version 3 of the License, or
|
||
10 | * (at your option) any later version.
|
||
11 | *
|
||
12 | * Blinker is distributed in the hope that it will be useful,
|
||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
15 | * GNU General Public License for more details.
|
||
16 | *
|
||
17 | * You should have received a copy of the GNU General Public License
|
||
18 | * along with Blinker. If not, see <http://www.gnu.org/licenses/>.
|
||
19 | */
|
||
20 | var websocket = new WebSocket('ws://localhost:6777'); |
||
21 | websocket.onmessage = function(evt) { messageReceived(evt); }; |
||
22 | websocket.onopen = function(evt) { conReady(); }; |
||
23 | websocket.onerror = function(evt) { onError(evt); }; |
||
24 | |||
25 | function disconnect(){ |
||
26 | websocket.close(); |
||
27 | } |
||
28 | |||
29 | function onError(evt) { |
||
30 | console.log("An error occured in the websocket.html - is the WebSocket Server running?");
|
||
31 | } |
||
32 | |||
33 | function messageReceived(evt) { |
||
34 | |||
35 | addon.port.emit('eyeTrackerData',evt.data);
|
||
36 | |||
37 | } |
||
38 | |||
39 | function conReady() { |
||
40 | console.log("connection established");
|
||
41 | |||
42 | try{
|
||
43 | sendMessage("TYPE:browser");
|
||
44 | } catch (err){
|
||
45 | console.log("Error in Websocket Page-Worker: "+err.name);
|
||
46 | } |
||
47 | |||
48 | |||
49 | console.log("adding port listener");
|
||
50 | addon.port.on("toEyetracker",function (message){ |
||
51 | //console.log("websocket.html sending to websocketserver: "+message);
|
||
52 | try{
|
||
53 | sendMessage(message); |
||
54 | } catch (err){
|
||
55 | console.log("Error in Websocket Page-Worker: "+err.name);
|
||
56 | } |
||
57 | }); |
||
58 | |||
59 | addon.port.on("disconnect",function (){ |
||
60 | console.log("websocket.html disconnecting: ");
|
||
61 | try{
|
||
62 | disconnect(); |
||
63 | } catch (err){
|
||
64 | console.log("Error in Websocket Page-Worker: "+err.name);
|
||
65 | } |
||
66 | }); |
||
67 | |||
68 | addon.port.emit('conReady',"ready"); |
||
69 | websocket.send("HI.");
|
||
70 | } |
||
71 | |||
72 | function sendMessage(message){ |
||
73 | websocket.send(message); |
||
74 | } |
||
75 |