(socket, options)
| 10 | // end node |
| 11 | |
| 12 | function BinaryClient(socket, options) { |
| 13 | if (!(this instanceof BinaryClient)) return new BinaryClient(socket, options); |
| 14 | |
| 15 | EventEmitter.call(this); |
| 16 | |
| 17 | var self = this; |
| 18 | |
| 19 | this._options = util.extend({ |
| 20 | chunkSize: 40960 |
| 21 | }, options); |
| 22 | |
| 23 | this.streams = {}; |
| 24 | |
| 25 | if(typeof socket === 'string') { |
| 26 | this._nextId = 0; |
| 27 | this._socket = new WebSocket(socket); |
| 28 | } else { |
| 29 | // Use odd numbered ids for server originated streams |
| 30 | this._nextId = 1; |
| 31 | this._socket = socket; |
| 32 | } |
| 33 | |
| 34 | this._socket.binaryType = 'arraybuffer'; |
| 35 | |
| 36 | this._socket.addEventListener('open', function(){ |
| 37 | self.emit('open'); |
| 38 | }); |
| 39 | // if node |
| 40 | this._socket.on('drain', function(){ |
| 41 | var ids = Object.keys(self.streams); |
| 42 | for (var i = 0, ii = ids.length; i < ii; i++) { |
| 43 | self.streams[ids[i]]._onDrain(); |
| 44 | } |
| 45 | }); |
| 46 | // end node |
| 47 | this._socket.addEventListener('error', function(error){ |
| 48 | var ids = Object.keys(self.streams); |
| 49 | for (var i = 0, ii = ids.length; i < ii; i++) { |
| 50 | self.streams[ids[i]]._onError(error); |
| 51 | } |
| 52 | self.emit('error', error); |
| 53 | }); |
| 54 | this._socket.addEventListener('close', function(code, message){ |
| 55 | var ids = Object.keys(self.streams); |
| 56 | for (var i = 0, ii = ids.length; i < ii; i++) { |
| 57 | self.streams[ids[i]]._onClose(); |
| 58 | } |
| 59 | self.emit('close', code, message); |
| 60 | }); |
| 61 | this._socket.addEventListener('message', function(data, flags){ |
| 62 | util.setZeroTimeout(function(){ |
| 63 | |
| 64 | // Message format |
| 65 | // [type, payload, bonus ] |
| 66 | // |
| 67 | // Reserved |
| 68 | // [ 0 , X , X ] |
| 69 | // |
nothing calls this directly
no outgoing calls
no test coverage detected