blinker / firefox.plugin / lib / main.js @ e75d6b65
History | View | Annotate | Download (8.837 KB)
1 |
/*
|
---|---|
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 |
|
21 |
var {
|
22 |
ToggleButton |
23 |
} = require("sdk/ui/button/toggle");
|
24 |
var panels = require("sdk/panel"); |
25 |
var tabs = require("sdk/tabs"); |
26 |
var pageMod = require("sdk/page-mod"); |
27 |
var pageWorker = require("sdk/page-worker"); |
28 |
var self = require("sdk/self"); |
29 |
var settings = require("sdk/simple-prefs"); |
30 |
var activeTABURL = "no"; |
31 |
var about_config = require("sdk/preferences/service"); |
32 |
var array = require("sdk/util/array"); |
33 |
about_config.set("network.websocket.allowInsecureFromHTTPS", true); |
34 |
|
35 |
var pageModWorkers = [];
|
36 |
var activeWorker;
|
37 |
var calibrationImage = self.data.url('calib.png'); |
38 |
var holeImage = self.data.url('hole_200.gif'); |
39 |
var currentPort = null; |
40 |
|
41 |
var arr;
|
42 |
|
43 |
//open the presentation.html on startup
|
44 |
tabs.open({ |
45 |
url: self.data.url("presentation.html"), |
46 |
inBackground: false, |
47 |
}); |
48 |
|
49 |
|
50 |
//initiation of the settings panel button
|
51 |
var button = ToggleButton({
|
52 |
id: "mozilla-link", |
53 |
label: "Visit Mozilla", |
54 |
icon: {
|
55 |
"16": "./eye-icon.png", |
56 |
"32": "./eye-icon.png", |
57 |
"64": "./eye-icon.png" |
58 |
}, |
59 |
onChange: handleChange
|
60 |
}); |
61 |
|
62 |
/*
|
63 |
* Initiate pageworker (WebSocketServer-Connector)
|
64 |
*/
|
65 |
var pw = pageWorker.Page({
|
66 |
contentURL: self.data.url("websocket.html") |
67 |
}); |
68 |
//pw.contentURL = self.data.url("websocket.html");
|
69 |
|
70 |
|
71 |
pw.port.on('getEyeTracker', function() { |
72 |
worker.port.emit("EyeTracker", eyeTracker);
|
73 |
}); |
74 |
|
75 |
/*
|
76 |
* If pageworker
|
77 |
*/
|
78 |
pw.port.on('getAllSettings', function() { |
79 |
emitAllPrefs(worker.port); |
80 |
}); |
81 |
|
82 |
/*
|
83 |
* If message with name: 'eyeTrackerData' is received from pageworker, send it to the according listener
|
84 |
* inside the active pagemod
|
85 |
*/
|
86 |
pw.port.on('eyeTrackerData', function(message) { |
87 |
//console.log("main.js :: pageMod :: port.on.eyeTrackerData" + ", message: " + message);
|
88 |
if (activeWorker !== undefined) { |
89 |
switch (settings.prefs.eyeTracker) {
|
90 |
case "eyetribe": |
91 |
activeWorker.port.emit('eyeTrackerData', message);
|
92 |
break;
|
93 |
case "smi": |
94 |
activeWorker.port.emit('smiData', message);
|
95 |
break;
|
96 |
case "mygaze": |
97 |
activeWorker.port.emit('myGazeData', message);
|
98 |
break;
|
99 |
default:
|
100 |
break;
|
101 |
} |
102 |
} |
103 |
}); |
104 |
|
105 |
|
106 |
|
107 |
|
108 |
/*
|
109 |
* Initiate pagemod and append listeners
|
110 |
*
|
111 |
*/
|
112 |
pageMod.PageMod({ |
113 |
include: ["*", "file://*", "resource://*"], |
114 |
contentScriptFile: [self.data.url("jquery-1.11.1.js"), self.data.url("notify.js"), self.data.url("jquery-ui.js"), self.data.url("jquery.knob.js"), self.data.url("eyeTribe.js"), self.data.url("withinViewport.js"), self.data.url("jquery.withinViewport.js"), self.data.url("circle-progress.js"), self.data.url("functions.js"), self.data.url("myscript.js"), self.data.url("jquery.nearest.js")], |
115 |
contentStyleFile: [self.data.url("style.css"), self.data.url("font-awesome.css")], |
116 |
attachTo: ["top"], |
117 |
onAttach: function(worker) { |
118 |
|
119 |
//set global activeworker to current pagemod
|
120 |
activeWorker = worker; |
121 |
|
122 |
/*
|
123 |
* if page tab / page is (re)-activated - reset the eyetribes configuration settings and refresh the
|
124 |
* blickBrowserSettings, that might have changed in another tab
|
125 |
*/
|
126 |
worker.tab.on('activate', function() { |
127 |
activeWorker = worker; |
128 |
activeWorker.port.emit("initializeEyeTribe", ""); |
129 |
emitAllPrefs(activeWorker.port); |
130 |
}); |
131 |
/*
|
132 |
* if page tab / page is (re)-activated - reset the eyetribes configuration settings and refresh the
|
133 |
* blickBrowserSettings, that might have changed in another tab
|
134 |
*/
|
135 |
worker.on('pageshow', function() { |
136 |
activeWorker = worker; |
137 |
activeWorker.port.emit("initializeEyeTribe", ""); |
138 |
array.add(pageModWorkers, this);
|
139 |
emitAllPrefs(activeWorker.port); |
140 |
}); |
141 |
|
142 |
/*
|
143 |
* if page tab / page is minimized, remove the actual worker from pagemodworkers
|
144 |
*/
|
145 |
worker.on('pagehide', function() { |
146 |
array.remove(pageModWorkers, this);
|
147 |
}); |
148 |
|
149 |
/*
|
150 |
* if page tab / page is closed, remove the actual worker from pagemodworkers
|
151 |
*/
|
152 |
worker.on('detach', function() { |
153 |
console.log("worker detached.");
|
154 |
array.remove(pageModWorkers, this);
|
155 |
}); |
156 |
|
157 |
|
158 |
/*
|
159 |
* ################################################################
|
160 |
* #################### PAGEMOD PORT LISTENERS ####################
|
161 |
* ################################################################
|
162 |
*/
|
163 |
|
164 |
/*
|
165 |
* Redirect message from pagemod to pageworker
|
166 |
*/
|
167 |
worker.port.on("sendToTracker", function(message) { |
168 |
pw.port.emit("toEyetracker", message);
|
169 |
}); |
170 |
|
171 |
|
172 |
/*
|
173 |
* Set panel button icon color
|
174 |
*/
|
175 |
worker.port.on('setIconGreen', function() { |
176 |
button.icon = "./eye-icon_green.png";
|
177 |
}); |
178 |
worker.port.on('setIconRed', function() { |
179 |
button.icon = "./eye-icon_red.png";
|
180 |
}); |
181 |
|
182 |
|
183 |
worker.port.on('blickBrowserMode', function(value) { |
184 |
settings.prefs.blickBrowserMode = value; |
185 |
emitAllPrefs(activeWorker.port); |
186 |
}); |
187 |
|
188 |
/*
|
189 |
* Settings have changed from inside the pagemod - adjust them globally
|
190 |
*/
|
191 |
worker.port.on("writeSettings", function(settings) { |
192 |
writeSettings(settings); |
193 |
}); |
194 |
|
195 |
/*
|
196 |
* ################################################################
|
197 |
* #################### PAGEMOD PORT EMITTERS #####################
|
198 |
* ################################################################
|
199 |
*/
|
200 |
|
201 |
/*
|
202 |
* Send calibration image file to pagemod
|
203 |
*/
|
204 |
worker.port.emit("calibrationImage", calibrationImage);
|
205 |
|
206 |
/*
|
207 |
* Send privacy image file to pagemod
|
208 |
*/
|
209 |
worker.port.emit("holeImage", holeImage);
|
210 |
|
211 |
|
212 |
} |
213 |
}); |
214 |
|
215 |
/*
|
216 |
* Initiate the settings panel
|
217 |
*/
|
218 |
var panel = panels.Panel({
|
219 |
contentURL: self.data.url("settings.html"), |
220 |
contentScriptFile: [self.data.url("settingsvariables.js"), self.data.url("jquery-1.11.1.js"), self.data.url("settings.js")], |
221 |
position: button,
|
222 |
//width: 400,
|
223 |
height: 700, |
224 |
onHide: handleHide
|
225 |
}); |
226 |
|
227 |
|
228 |
|
229 |
|
230 |
|
231 |
/*
|
232 |
* Send all blickbrowsersettings to the settings panel on request
|
233 |
*/
|
234 |
panel.port.on('getAllSettings', function() { |
235 |
emitAllPrefs(panel.port); |
236 |
//panel.port.emit('blickBrowserSettings', settings.prefs);
|
237 |
}); |
238 |
|
239 |
/*
|
240 |
* Settings have changed from inside the settings panel - adjust them globally
|
241 |
*/
|
242 |
panel.port.on("writeSettings", function(settings) { |
243 |
writeSettings(settings); |
244 |
}); |
245 |
|
246 |
/*
|
247 |
* Eyetracker calibration has been toggled from settings panel
|
248 |
* send request to eyetracker
|
249 |
*/
|
250 |
panel.port.on("toggleCalibrate", function(value) { |
251 |
if (settings.prefs.eyeTracker == "eyetribe") { |
252 |
activeWorker.port.emit('startCalibration', 'go'); |
253 |
} |
254 |
}); |
255 |
|
256 |
/*
|
257 |
* Calibration check is being called from settings panel - hide the panel and tell the pagemod
|
258 |
*/
|
259 |
panel.port.on("toggleCheckCalibration", function(value) { |
260 |
if (settings.prefs.eyeTracker == "eyetribe") { |
261 |
/*tabs.activeTab.reload();*/
|
262 |
panel.hide(); |
263 |
//handleChange();
|
264 |
activeWorker.port.emit('checkCalibration', 'go'); |
265 |
|
266 |
} |
267 |
}); |
268 |
|
269 |
/*
|
270 |
* Emit blickbrowsersettings to the panel
|
271 |
*/
|
272 |
panel.port.emit('loadSettings', 'go'); |
273 |
|
274 |
|
275 |
/*
|
276 |
* Is called when the button's state has changed (is it checked or not)
|
277 |
*/
|
278 |
function handleChange(state) { |
279 |
if (state.checked) {
|
280 |
panel.port.emit('loadSettings', 'go'); |
281 |
panel.show(); |
282 |
} |
283 |
} |
284 |
|
285 |
/*
|
286 |
* update settings and send them to the active tab
|
287 |
* @set: The settings array (e.g. blickBrowserSettings)
|
288 |
*/
|
289 |
function writeSettings(set) { |
290 |
//console.log("writeSettings()");
|
291 |
for (var name in set) { |
292 |
settings.prefs[name] = set [name]; |
293 |
} |
294 |
emitAllPrefs(activeWorker.port); |
295 |
} |
296 |
|
297 |
/*
|
298 |
* Update the panel settings button's state when settings panel is being hidden
|
299 |
*/
|
300 |
function handleHide() { |
301 |
button.state('window', {
|
302 |
checked: false |
303 |
}); |
304 |
} |
305 |
|
306 |
/*
|
307 |
* send all settings to the given port
|
308 |
* @port: The port the settings are sent to (e.g. )
|
309 |
*/
|
310 |
function emitAllPrefs(port) { |
311 |
port.emit("blickBrowserSettings", settings.prefs);
|
312 |
} |