aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/library_browser.js20
-rw-r--r--src/library_sockfs.js6
2 files changed, 16 insertions, 10 deletions
diff --git a/src/library_browser.js b/src/library_browser.js
index 71923743..b70dbc84 100644
--- a/src/library_browser.js
+++ b/src/library_browser.js
@@ -360,15 +360,19 @@ mergeInto(LibraryManager.library, {
},
requestAnimationFrame: function(func) {
- if (!window.requestAnimationFrame) {
- window.requestAnimationFrame = window['requestAnimationFrame'] ||
- window['mozRequestAnimationFrame'] ||
- window['webkitRequestAnimationFrame'] ||
- window['msRequestAnimationFrame'] ||
- window['oRequestAnimationFrame'] ||
- window['setTimeout'];
+ if (typeof window === 'undefined') { // Provide fallback to setTimeout if window is undefined (e.g. in Node.js)
+ setTimeout(func, 1000/60);
+ } else {
+ if (!window.requestAnimationFrame) {
+ window.requestAnimationFrame = window['requestAnimationFrame'] ||
+ window['mozRequestAnimationFrame'] ||
+ window['webkitRequestAnimationFrame'] ||
+ window['msRequestAnimationFrame'] ||
+ window['oRequestAnimationFrame'] ||
+ window['setTimeout'];
+ }
+ window.requestAnimationFrame(func);
}
- window.requestAnimationFrame(func);
},
// generic abort-aware wrapper for an async callback
diff --git a/src/library_sockfs.js b/src/library_sockfs.js
index a57a51a1..bc3aa997 100644
--- a/src/library_sockfs.js
+++ b/src/library_sockfs.js
@@ -138,7 +138,9 @@ mergeInto(LibraryManager.library, {
console.log('connect: ' + url);
#endif
// the node ws library API is slightly different than the browser's
- var opts = ENVIRONMENT_IS_NODE ? {} : ['binary'];
+ var opts = ENVIRONMENT_IS_NODE ? {headers: {'websocket-protocol': ['binary']}} : ['binary'];
+ // If node we use the ws library.
+ var WebSocket = ENVIRONMENT_IS_NODE ? require('ws') : window['WebSocket'];
ws = new WebSocket(url, opts);
ws.binaryType = 'arraybuffer';
} catch (e) {
@@ -573,4 +575,4 @@ mergeInto(LibraryManager.library, {
}
}
}
-}); \ No newline at end of file
+});