Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed issues with dependent modules not working with latest Node.js. …

…Traded out webworker module with backgrounder.
  • Loading branch information...
commit a7b3f815e45a2c3ee97d8eb7b60e94ef532097d6 1 parent e6c8a0c
@jacwright jacwright authored
Showing with 16 additions and 18 deletions.
  1. +3 −4 lib/worker.js
  2. +11 −12 lib/wurfl.js
  3. +2 −2 package.json
View
7 lib/worker.js
@@ -1,8 +1,7 @@
var parser = require(__dirname + '/parser');
-onmessage = function(event) {
- var data = event.data;
+process.on('message', function(data) {
var method = data.method;
var file = data.file;
var groups = data.groups;
@@ -12,10 +11,10 @@ onmessage = function(event) {
parser[method](file, groups, function(devices) {
if (!devices) return;
- postMessage({
+ process.send({
method: method,
file: file,
devices: devices
});
});
-};
+});
View
23 lib/wurfl.js
@@ -2,7 +2,7 @@ var fs = require('fs');
var path = require('path');
var expat = require('node-expat');
var parser = require('./parser');
-var Worker = require('webworker').Worker;
+var backgrounder = require("backgrounder");
var wurflFile = path.join(__dirname, '../wurfl.xml');
@@ -26,21 +26,20 @@ function close() {
// lazily load the worker
function getWorker() {
if (!worker) {
- worker = new Worker(path.join(__dirname, './worker.js'));
+ worker = new backgrounder.spawn(path.join(__dirname, './worker.js'));
- worker.onmessage = function(event) {
- var data = event.data;
+ worker.on('message', function(data) {
var method = data.method;
var file = data.file;
var devices = data.devices;
packageDevices(devices);
var callback = callbacks[method][file];
if (callback) callback();
- };
+ });
- worker.onerror = function(error) {
+ worker.on('error', function(error) {
console.error(error);
- }
+ });
}
return worker;
@@ -49,7 +48,7 @@ function getWorker() {
function watch(options, callback) {
if (typeof options === 'function') {
- callback = file;
+ callback = options;
options = undefined;
}
if (typeof options === 'string') {
@@ -60,9 +59,9 @@ function watch(options, callback) {
if (callback) callbacks.watch[file] = callback;
- getWorker().postMessage({
+ getWorker().send({
method: 'watch',
- file: file,
+ file: options.file,
groups: options.groups
});
}
@@ -70,7 +69,7 @@ function watch(options, callback) {
function load(options, callback) {
if (typeof options === 'function') {
- callback = file;
+ callback = options;
options = undefined;
}
if (typeof options === 'string') {
@@ -81,7 +80,7 @@ function load(options, callback) {
if (callback) callbacks.load[options.file] = callback;
- getWorker().postMessage({
+ getWorker().send({
method: 'load',
file: options.file,
groups: options.groups
View
4 package.json
@@ -8,8 +8,8 @@
"test": "node test/test.js"
},
"dependencies": {
- "node-expat": "1.4.0",
- "webworker": "0.8.4"
+ "node-expat": "1.4.1",
+ "backgrounder": "0.2.7"
},
"homepage": "https://github.com/touchads/node-wurfl-api",
"repository": {
Please sign in to comment.
Something went wrong with that request. Please try again.