diff options
author | Fraser Adams <fraser.adams@blueyonder.co.uk> | 2013-10-29 20:53:51 +0000 |
---|---|---|
committer | Fraser Adams <fraser.adams@blueyonder.co.uk> | 2013-10-29 20:53:51 +0000 |
commit | e37d142969386b92616383cf8616e3ca2d92c3af (patch) | |
tree | baa5145cf5948162776c4992652fa0ae74e65f81 | |
parent | 7a902d9e4d79e370f44f94a9a7f7ed45ba3dfbb2 (diff) |
updated library_sockfs.js to make WebSocket a local var and updated library_browser.js to modify requestAnimationFrame to provide a fallback to setTimeout if window is undefined
-rw-r--r-- | src/library_browser.js | 26 | ||||
-rw-r--r-- | src/library_sockfs.js | 2 |
2 files changed, 14 insertions, 14 deletions
diff --git a/src/library_browser.js b/src/library_browser.js index 5ec02eee..0d5bf6db 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 @@ -782,11 +786,7 @@ mergeInto(LibraryManager.library, { } } else { Browser.mainLoop.scheduler = function() { - 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.requestAnimationFrame(Browser.mainLoop.runner); } } Browser.mainLoop.scheduler(); diff --git a/src/library_sockfs.js b/src/library_sockfs.js index 0e083bfd..c79661d8 100644 --- a/src/library_sockfs.js +++ b/src/library_sockfs.js @@ -140,7 +140,7 @@ mergeInto(LibraryManager.library, { // the node ws library API is slightly different than the browser's var opts = ENVIRONMENT_IS_NODE ? {headers: {'websocket-protocol': ['binary']}} : ['binary']; // If node we use the ws library. - WebSocket = ENVIRONMENT_IS_NODE ? require('ws') : WebSocket; + var WebSocket = ENVIRONMENT_IS_NODE ? require('ws') : window.WebSocket; ws = new WebSocket(url, opts); ws.binaryType = 'arraybuffer'; } catch (e) { |