From 9f1ea6f372d6af0d33ebbf158d676853bb50a82d Mon Sep 17 00:00:00 2001 From: Aaron Gowatch Date: Mon, 30 Dec 2019 14:48:20 -0700 Subject: [PATCH] Ignore error on courtesy stop() - This raises an error if the viewer was not previously started; ignore such errors on courtesy-stop --- src/screenviewing/DefaultScreenViewing.ts | 6 ++++- .../DefaultScreenViewing.test.ts | 24 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/screenviewing/DefaultScreenViewing.ts b/src/screenviewing/DefaultScreenViewing.ts index d30d410db5..38fe594f58 100644 --- a/src/screenviewing/DefaultScreenViewing.ts +++ b/src/screenviewing/DefaultScreenViewing.ts @@ -29,7 +29,11 @@ export default class DefaultScreenViewing implements ScreenViewing { * Stops screen viewing and closes the screen signaling connection */ close(): Promise { - return this.stop().then(() => this.componentContext.signalingSession.close()); + return this.stop() + .catch(() => {}) + .finally(() => { + return this.componentContext.signalingSession.close(); + }); } /** diff --git a/test/screenviewing/DefaultScreenViewing.test.ts b/test/screenviewing/DefaultScreenViewing.test.ts index 559bdd7720..5e6e7ae780 100644 --- a/test/screenviewing/DefaultScreenViewing.test.ts +++ b/test/screenviewing/DefaultScreenViewing.test.ts @@ -29,6 +29,30 @@ describe('DefaultScreenViewing', () => { }); describe('close', () => { + describe('with error', () => { + it('is closed', () => { + return new DefaultScreenViewing({ + ...Substitute.for(), + viewer: { + ...Substitute.for(), + stop(): void {}, + }, + signalingSession: { + ...Substitute.for(), + close(): Promise { + return Promise.resolve(); + }, + }, + viewingSession: { + ...Substitute.for(), + closeConnection(): Promise { + return Promise.reject(new Error('bummers')); + }, + }, + }).close(); + }); + }); + it('calls viewer close', () => { return new DefaultScreenViewing({ ...Substitute.for(),