diff options
author | Fraser Adams <fraser.adams@blueyonder.co.uk> | 2013-10-27 20:30:13 +0000 |
---|---|---|
committer | Fraser Adams <fraser.adams@blueyonder.co.uk> | 2013-10-27 20:30:13 +0000 |
commit | 7a902d9e4d79e370f44f94a9a7f7ed45ba3dfbb2 (patch) | |
tree | ad4d6721e331bdaf5ecfc8e77052014743f163d1 /src | |
parent | 14c6628d28648cd069a9e0e519cc69513e3d470b (diff) |
add support for node.js to act as a socket client
Diffstat (limited to 'src')
-rw-r--r-- | src/library_browser.js | 6 | ||||
-rw-r--r-- | src/library_sockfs.js | 6 |
2 files changed, 9 insertions, 3 deletions
diff --git a/src/library_browser.js b/src/library_browser.js index 59d2945e..5ec02eee 100644 --- a/src/library_browser.js +++ b/src/library_browser.js @@ -782,7 +782,11 @@ mergeInto(LibraryManager.library, { } } else { Browser.mainLoop.scheduler = function() { - Browser.requestAnimationFrame(Browser.mainLoop.runner); + if (typeof window === 'undefined') { // requestAnimationFrame will fail if window is undefined (e.g. in Node.js) + setTimeout(Browser.mainLoop.runner, 1000/60); + } else { + Browser.requestAnimationFrame(Browser.mainLoop.runner); + } } } Browser.mainLoop.scheduler(); diff --git a/src/library_sockfs.js b/src/library_sockfs.js index af29d11b..0e083bfd 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. + WebSocket = ENVIRONMENT_IS_NODE ? require('ws') : WebSocket; ws = new WebSocket(url, opts); ws.binaryType = 'arraybuffer'; } catch (e) { @@ -573,4 +575,4 @@ mergeInto(LibraryManager.library, { } } } -});
\ No newline at end of file +}); |