rxjs-websockets
Advanced tools
Comparing version 5.0.0 to 6.0.0
@@ -12,2 +12,3 @@ "use strict"; | ||
var open = false; | ||
var forcedClose = false; | ||
var closed = function () { | ||
@@ -35,3 +36,3 @@ if (!open) | ||
closed(); | ||
if (event.wasClean) | ||
if (forcedClose) | ||
observer.complete(); | ||
@@ -42,5 +43,6 @@ else | ||
return function () { | ||
forcedClose = true; | ||
if (inputSubscription) | ||
inputSubscription.unsubscribe(); | ||
if (socket) { | ||
if (open) { | ||
closed(); | ||
@@ -47,0 +49,0 @@ socket.close(); |
@@ -18,2 +18,3 @@ "use strict"; | ||
var operators_1 = require("rxjs/operators"); | ||
var throwError_1 = require("rxjs/internal/observable/throwError"); | ||
var chai = require("chai"); | ||
@@ -54,3 +55,3 @@ var sinon = require("sinon"); | ||
}); | ||
it('ends stream on clean websocket close', function () { | ||
it('closes websocket on unsubscribe', function () { | ||
var mockSocket = new /** @class */ (function (_super) { | ||
@@ -65,10 +66,18 @@ __extends(class_1, _super); | ||
}(MockSocket)); | ||
var _a = connectHelper(cold('a|'), mockSocket), connectionStatus = _a.connectionStatus, messages = _a.messages; | ||
var messages = connectHelper(cold('a|'), mockSocket).messages; | ||
scheduler.schedule(function () { return mockSocket.onopen(); }, 10); | ||
scheduler.schedule(function () { return mockSocket.onclose({ wasClean: true }); }, 30); | ||
expect(messages).toBe('-a-|'); | ||
expect(messages, '--!').toBe('-a'); | ||
flush(); | ||
mockSocket.close.should.have.been.calledOnce; | ||
}); | ||
it('errors on unclean websocket close', function () { | ||
var mockSocket = new MockSocket(); | ||
var messages = connectHelper(cold('a'), mockSocket).messages; | ||
scheduler.schedule(function () { return mockSocket.onopen(); }, 10); | ||
scheduler.schedule(function () { return mockSocket.onclose({ reason: 'Normal closure' }); }, 30); | ||
expect(messages.pipe(operators_1.catchError(function (error) { return throwError_1.throwError(error.message); }))) | ||
.toBe('-a-#', undefined, 'Normal closure'); | ||
flush(); | ||
}); | ||
}); | ||
//# sourceMappingURL=index.spec.js.map |
{ | ||
"name": "rxjs-websockets", | ||
"version": "5.0.0", | ||
"version": "6.0.0", | ||
"description": "rxjs 5 websockets library, ideal for use with angular 2", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -5,3 +5,4 @@ import 'mocha' | ||
import { Observable, of } from 'rxjs' | ||
import { delay, switchMapTo } from 'rxjs/operators'; | ||
import { delay, switchMapTo, catchError } from 'rxjs/operators'; | ||
import { throwError } from 'rxjs/internal/observable/throwError'; | ||
import * as chai from 'chai' | ||
@@ -49,10 +50,9 @@ import * as sinon from 'sinon' | ||
it('ends stream on clean websocket close', () => { | ||
it('closes websocket on unsubscribe', () => { | ||
const mockSocket = new class extends MockSocket { | ||
close = sinon.stub() | ||
} | ||
const { connectionStatus, messages } = connectHelper(cold('a|'), mockSocket) | ||
const { messages } = connectHelper(cold('a|'), mockSocket) | ||
scheduler.schedule(() => mockSocket.onopen(), 10) | ||
scheduler.schedule(() => mockSocket.onclose({ wasClean: true }), 30) | ||
expect(messages).toBe('-a-|') | ||
expect(messages, '--!').toBe('-a') | ||
flush() | ||
@@ -62,2 +62,12 @@ | ||
}) | ||
it('errors on unclean websocket close', () => { | ||
const mockSocket = new MockSocket() | ||
const { messages } = connectHelper(cold('a'), mockSocket) | ||
scheduler.schedule(() => mockSocket.onopen(), 10) | ||
scheduler.schedule(() => mockSocket.onclose({ reason: 'Normal closure' }), 30) | ||
expect(messages.pipe(catchError(error => throwError(error.message)))) | ||
.toBe('-a-#', undefined, 'Normal closure') | ||
flush() | ||
}) | ||
}) |
@@ -34,2 +34,4 @@ import { Observable, Subscription, BehaviorSubject } from 'rxjs' | ||
let open = false | ||
let forcedClose = false | ||
const closed = () => { | ||
@@ -62,3 +64,3 @@ if (! open) | ||
closed() | ||
if (event.wasClean) | ||
if (forcedClose) | ||
observer.complete() | ||
@@ -70,6 +72,7 @@ else | ||
return () => { | ||
forcedClose = true | ||
if (inputSubscription) | ||
inputSubscription.unsubscribe() | ||
if (socket) { | ||
if (open) { | ||
closed() | ||
@@ -76,0 +79,0 @@ socket.close() |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24613
292