Skip to content

Commit 6b1c681

Browse files
committed
Merge pull request PatrickJS#34 from vanishs/master
support arraybuffer
2 parents 1c96d68 + d47114a commit 6b1c681

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

angular-websocket.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
this.url = url || 'Missing URL';
4242
this.ssl = /(wss)/i.test(this.url);
4343

44-
// this.binaryType = '';
4544
// this.extensions = '';
4645
// this.bufferedAmount = 0;
4746
// this.trasnmitting = false;
@@ -54,6 +53,7 @@
5453
this.initialTimeout = options && options.initialTimeout || 500; // 500ms
5554
this.maxTimeout = options && options.maxTimeout || 5 * 60 * 1000; // 5 minutes
5655
this.reconnectIfNotNormalClose = options && options.reconnectIfNotNormalClose || false;
56+
this.binaryType = options && options.binaryType || 'blob';
5757

5858
this._reconnectAttempts = 0;
5959
this.sendQueue = [];
@@ -109,6 +109,7 @@
109109
$WebSocket.prototype._connect = function _connect(force) {
110110
if (force || !this.socket || this.socket.readyState !== this._readyStateConstants.OPEN) {
111111
this.socket = $websocketBackend.create(this.url, this.protocols);
112+
this.socket.binaryType = this.binaryType;
112113
this.socket.onmessage = angular.bind(this, this._onMessageHandler);
113114
this.socket.onopen = angular.bind(this, this._onOpenHandler);
114115
this.socket.onerror = angular.bind(this, this._onErrorHandler);
@@ -121,7 +122,7 @@
121122
var data = this.sendQueue.shift();
122123

123124
this.socket.send(
124-
isString(data.message) ? data.message : JSON.stringify(data.message)
125+
data.message
125126
);
126127
data.deferred.resolve();
127128
}

0 commit comments

Comments
 (0)