Skip to content

Commit 54c11f2

Browse files
committed
feat: digest onError onClose
1 parent 56b425c commit 54c11f2

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/angular-websocket.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,14 +185,30 @@
185185
};
186186

187187
$WebSocket.prototype._onCloseHandler = function _onCloseHandler(event) {
188-
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+
}
189197
if ((this.reconnectIfNotNormalClose && event.code !== this._normalCloseCode) || this._reconnectableStatusCodes.indexOf(event.code) > -1) {
190198
this.reconnect();
191199
}
192200
};
193201

194202
$WebSocket.prototype._onErrorHandler = function _onErrorHandler(event) {
195-
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+
}
196212
};
197213

198214
$WebSocket.prototype._onMessageHandler = function _onMessageHandler(message) {

0 commit comments

Comments
 (0)