makedrive
Version:
Webmaker Filesystem
29 lines (23 loc) • 918 B
JavaScript
/**
* In node.js we want to use the ws module for WebSocket. In the
* browser we can just use the native WebSocket. Here we adapt
* the browser's WebSocket interface to more closely match ws
* so that we can use either.
*
* This module gets used by browserify, see package.json
*/
if (!global.WebSocket) return;
global.WebSocket.prototype.on = global.WebSocket.prototype.on || function(event, listener) {
this.addEventListener(event, listener);
};
global.WebSocket.prototype.removeListener = global.WebSocket.prototype.removeListener || function(event, listener) {
this.removeEventListener(event, listener);
};
global.WebSocket.prototype.once = global.WebSocket.prototype.once || function(event, listener) {
var ws = this;
this.addEventListener(event, function onEvent() {
ws.removeEventListener(event, onEvent);
listener.apply(null, arguments);
});
};
module.exports = global.WebSocket;