|
41 | 41 | this.url = url || 'Missing URL'; |
42 | 42 | this.ssl = /(wss)/i.test(this.url); |
43 | 43 |
|
| 44 | + // this.binaryType = ''; |
44 | 45 | // this.extensions = ''; |
45 | 46 | // this.bufferedAmount = 0; |
46 | 47 | // this.trasnmitting = false; |
|
53 | 54 | this.initialTimeout = options && options.initialTimeout || 500; // 500ms |
54 | 55 | this.maxTimeout = options && options.maxTimeout || 5 * 60 * 1000; // 5 minutes |
55 | 56 | this.reconnectIfNotNormalClose = options && options.reconnectIfNotNormalClose || false; |
56 | | - this.binaryType = options && options.binaryType || 'blob'; |
57 | 57 |
|
58 | 58 | this._reconnectAttempts = 0; |
59 | 59 | this.sendQueue = []; |
|
113 | 113 | this.socket.onopen = angular.bind(this, this._onOpenHandler); |
114 | 114 | this.socket.onerror = angular.bind(this, this._onErrorHandler); |
115 | 115 | this.socket.onclose = angular.bind(this, this._onCloseHandler); |
116 | | - this.socket.binaryType = this.binaryType; |
117 | 116 | } |
118 | 117 | }; |
119 | 118 |
|
|
122 | 121 | var data = this.sendQueue.shift(); |
123 | 122 |
|
124 | 123 | this.socket.send( |
125 | | - data.message |
| 124 | + isString(data.message) ? data.message : JSON.stringify(data.message) |
126 | 125 | ); |
127 | 126 | data.deferred.resolve(); |
128 | 127 | } |
|
186 | 185 | }; |
187 | 186 |
|
188 | 187 | $WebSocket.prototype._onCloseHandler = function _onCloseHandler(event) { |
189 | | - this.notifyCloseCallbacks(event); |
| 188 | + var self = this; |
| 189 | + if (self.useApplyAsync) { |
| 190 | + self.scope.$applyAsync(function() { |
| 191 | + self.notifyCloseCallbacks(event); |
| 192 | + }); |
| 193 | + } else { |
| 194 | + self.notifyCloseCallbacks(event); |
| 195 | + self.safeDigest(autoApply); |
| 196 | + } |
190 | 197 | if ((this.reconnectIfNotNormalClose && event.code !== this._normalCloseCode) || this._reconnectableStatusCodes.indexOf(event.code) > -1) { |
191 | 198 | this.reconnect(); |
192 | 199 | } |
193 | 200 | }; |
194 | 201 |
|
195 | 202 | $WebSocket.prototype._onErrorHandler = function _onErrorHandler(event) { |
196 | | - this.notifyErrorCallbacks(event); |
| 203 | + var self = this; |
| 204 | + if (self.useApplyAsync) { |
| 205 | + self.scope.$applyAsync(function() { |
| 206 | + self.notifyErrorCallbacks(event); |
| 207 | + }); |
| 208 | + } else { |
| 209 | + self.notifyErrorCallbacks(event); |
| 210 | + self.safeDigest(autoApply); |
| 211 | + } |
197 | 212 | }; |
198 | 213 |
|
199 | 214 | $WebSocket.prototype._onMessageHandler = function _onMessageHandler(message) { |
|
346 | 361 | } |
347 | 362 |
|
348 | 363 | // CommonJS |
349 | | - if (typeof exports === 'object' && typeof require === 'function') { |
| 364 | + if (typeof exports === 'object' && require) { |
350 | 365 | try { |
351 | 366 | ws = require('ws'); |
352 | 367 | Socket = (ws.Client || ws.client || ws); |
|
0 commit comments