From fcdb2cfa1a1717407b9c9d13a586b71866cfa92f Mon Sep 17 00:00:00 2001 From: Aaron Gowatch Date: Wed, 18 Dec 2019 14:45:42 -0700 Subject: [PATCH] Improve logging --- demos/browser/package.json | 2 +- src/domwebsocket/DOMWebSocket.ts | 1 + src/domwebsocket/DefaultDOMWebSocket.ts | 4 ++++ src/promisedwebsocket/DefaultPromisedWebSocket.ts | 4 ++++ src/promisedwebsocket/PromisedWebSocket.ts | 2 ++ src/promisedwebsocket/ReconnectingPromisedWebSocket.ts | 2 +- src/screensharingsession/DefaultScreenSharingSession.ts | 2 ++ .../deltarenderer/DefaultScreenViewingDeltaRenderer.ts | 1 + test/domwebsocket/DefaultDOMWebSocket.test.ts | 9 +++++++++ test/domwebsocketmock/DOMWebSocketMock.ts | 3 +++ test/promisedwebsocket/DefaultPromisedWebSocket.test.ts | 8 ++++++++ test/promisedwebsocketmock/PromisedWebSocketMock.ts | 4 ++++ .../DefaultScreenSharingSession.test.ts | 3 +++ 13 files changed, 43 insertions(+), 2 deletions(-) diff --git a/demos/browser/package.json b/demos/browser/package.json index 45e742f91b..942aeeb96c 100644 --- a/demos/browser/package.json +++ b/demos/browser/package.json @@ -31,7 +31,7 @@ }, "dependencies": { "amazon-chime-sdk-js": "file:../..", - "aws-sdk": "^2.591.0", + "aws-sdk": "^2.592.0", "bootstrap": "^4.3.1", "compression": "^1.7.4", "jquery": "^3.4.1", diff --git a/src/domwebsocket/DOMWebSocket.ts b/src/domwebsocket/DOMWebSocket.ts index ebb59a2155..649404f6a0 100644 --- a/src/domwebsocket/DOMWebSocket.ts +++ b/src/domwebsocket/DOMWebSocket.ts @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 export default interface DOMWebSocket extends EventTarget { + readonly url: string; onopen: EventListener | null; onerror: EventListener | null; onclose: EventListener | null; diff --git a/src/domwebsocket/DefaultDOMWebSocket.ts b/src/domwebsocket/DefaultDOMWebSocket.ts index c7f182b5ed..45ebcb0600 100644 --- a/src/domwebsocket/DefaultDOMWebSocket.ts +++ b/src/domwebsocket/DefaultDOMWebSocket.ts @@ -6,6 +6,10 @@ import DOMWebSocket from './DOMWebSocket'; export default class DefaultDOMWebSocket implements DOMWebSocket { constructor(private webSocket: WebSocket) {} + get url(): string { + return this.webSocket.url; + } + get onopen(): EventListener { return this.webSocket.onopen; } diff --git a/src/promisedwebsocket/DefaultPromisedWebSocket.ts b/src/promisedwebsocket/DefaultPromisedWebSocket.ts index 17f7c33f90..2eeb62a41b 100644 --- a/src/promisedwebsocket/DefaultPromisedWebSocket.ts +++ b/src/promisedwebsocket/DefaultPromisedWebSocket.ts @@ -11,6 +11,10 @@ export default class DefaultPromisedWebSocket implements PromisedWebSocket { constructor(private webSocket: DOMWebSocket) {} + get url(): string { + return this.webSocket.url; + } + open(timeoutMs: number): Promise { const promise = new Promise((resolve, reject) => { this.webSocket.onclose = (event: CloseEvent) => { diff --git a/src/promisedwebsocket/PromisedWebSocket.ts b/src/promisedwebsocket/PromisedWebSocket.ts index 843802bc59..cdb34325bd 100644 --- a/src/promisedwebsocket/PromisedWebSocket.ts +++ b/src/promisedwebsocket/PromisedWebSocket.ts @@ -2,6 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 export default interface PromisedWebSocket extends EventTarget { + readonly url: string; + /** * Opens the connection * @param {number} timeoutMs diff --git a/src/promisedwebsocket/ReconnectingPromisedWebSocket.ts b/src/promisedwebsocket/ReconnectingPromisedWebSocket.ts index 5d126be0a5..414e580ad3 100644 --- a/src/promisedwebsocket/ReconnectingPromisedWebSocket.ts +++ b/src/promisedwebsocket/ReconnectingPromisedWebSocket.ts @@ -18,7 +18,7 @@ export default class ReconnectingPromisedWebSocket implements PromisedWebSocket private webSocket: PromisedWebSocket | null = null; constructor( - private url: string, + readonly url: string, private protocols: string | string[], private binaryType: BinaryType, private webSocketFactory: PromisedWebSocketFactory, diff --git a/src/screensharingsession/DefaultScreenSharingSession.ts b/src/screensharingsession/DefaultScreenSharingSession.ts index 663afda8d1..bb4080c61b 100644 --- a/src/screensharingsession/DefaultScreenSharingSession.ts +++ b/src/screensharingsession/DefaultScreenSharingSession.ts @@ -53,6 +53,8 @@ export default class DefaultScreenSharingSession implements ScreenSharingSession }); }); + this.logger.info(`opening screen sharing connection to ${this.webSocket.url}`); + return this.webSocket.open(timeoutMs).then((event: Event) => { this.observerQueue.forEach((observer: ScreenSharingSessionObserver) => { Maybe.of(observer.didOpen).map(f => f.bind(observer)(event)); diff --git a/src/screenviewing/deltarenderer/DefaultScreenViewingDeltaRenderer.ts b/src/screenviewing/deltarenderer/DefaultScreenViewingDeltaRenderer.ts index 8aa0147c2b..8e9cf8a29a 100644 --- a/src/screenviewing/deltarenderer/DefaultScreenViewingDeltaRenderer.ts +++ b/src/screenviewing/deltarenderer/DefaultScreenViewingDeltaRenderer.ts @@ -131,6 +131,7 @@ export default class DefaultScreenViewingDeltaRenderer implements ScreenViewingD } context.putImageData(imageData, dx, dy); this.hasRendered[row][col] = true; + this.logger.debug(() => `rendered row=${row} col=${col}`); } } } diff --git a/test/domwebsocket/DefaultDOMWebSocket.test.ts b/test/domwebsocket/DefaultDOMWebSocket.test.ts index 3f48740d02..f352e06238 100644 --- a/test/domwebsocket/DefaultDOMWebSocket.test.ts +++ b/test/domwebsocket/DefaultDOMWebSocket.test.ts @@ -15,6 +15,15 @@ describe('DefaultDOMWebSocket', () => { chai.should(); }); + describe('url', () => { + it('is delegated', () => { + const url = 'ws://localhost'; + const webSocket = Substitute.for(); + webSocket.url.returns(url); + chai.expect(new DefaultDOMWebSocket(webSocket).url).to.eq(url); + }); + }); + describe('onopen', () => { const subject = new DefaultDOMWebSocket(Substitute.for()); diff --git a/test/domwebsocketmock/DOMWebSocketMock.ts b/test/domwebsocketmock/DOMWebSocketMock.ts index b5de37a64c..b965ac048e 100644 --- a/test/domwebsocketmock/DOMWebSocketMock.ts +++ b/test/domwebsocketmock/DOMWebSocketMock.ts @@ -5,6 +5,9 @@ import DOMWebSocket from '../../src/domwebsocket/DOMWebSocket'; import Maybe from '../../src/maybe/Maybe'; export default class DOMWebSocketMock implements DOMWebSocket { + get url(): string { + return 'ws://localhost'; + } onerror: EventListener | null = null; onopen: EventListener | null = null; onmessage: EventListener | null = null; diff --git a/test/promisedwebsocket/DefaultPromisedWebSocket.test.ts b/test/promisedwebsocket/DefaultPromisedWebSocket.test.ts index 24ccf0d3b2..c9750bdae1 100644 --- a/test/promisedwebsocket/DefaultPromisedWebSocket.test.ts +++ b/test/promisedwebsocket/DefaultPromisedWebSocket.test.ts @@ -17,6 +17,14 @@ describe('DefaultPromisedWebSocket', () => { chai.use(chaiAsPromised); }); + describe('url', () => { + it('is delegated', () => { + const webSocket = new DOMWebSocketMock(); + const subject = new DefaultPromisedWebSocket(webSocket); + chai.expect(subject.url).to.eq(webSocket.url); + }); + }); + describe('#open', () => { describe('without timeout', () => { it('is fulfilled', (done: Mocha.Done) => { diff --git a/test/promisedwebsocketmock/PromisedWebSocketMock.ts b/test/promisedwebsocketmock/PromisedWebSocketMock.ts index 9afaff6d5a..78a1fbfd2e 100644 --- a/test/promisedwebsocketmock/PromisedWebSocketMock.ts +++ b/test/promisedwebsocketmock/PromisedWebSocketMock.ts @@ -9,6 +9,10 @@ import PromisedWebSocket from '../../src/promisedwebsocket/PromisedWebSocket'; export default class PromisedWebSocketMock implements PromisedWebSocket { private callbacks = new Map>(); + get url(): string { + return 'ws://localhost'; + } + open(_timeoutMs: number): Promise { return Promise.resolve(Substitute.for()); } diff --git a/test/screensharingsession/DefaultScreenSharingSession.test.ts b/test/screensharingsession/DefaultScreenSharingSession.test.ts index 3c2cd47a72..ee9f8c5366 100644 --- a/test/screensharingsession/DefaultScreenSharingSession.test.ts +++ b/test/screensharingsession/DefaultScreenSharingSession.test.ts @@ -53,6 +53,7 @@ describe('DefaultScreenSharingSession', function() { const event = Substitute.for(); event.type.returns('open'); promisedWebSocket.open(Arg.any()).returns(Promise.resolve(event)); + promisedWebSocket.url.returns(''); subject.open(1000).should.eventually.be.fulfilled.and.notify(done); promisedWebSocket.dispatchEvent(event); }); @@ -78,6 +79,7 @@ describe('DefaultScreenSharingSession', function() { }, }; promisedWebSocket.open(Arg.any()).returns(Promise.resolve(event)); + promisedWebSocket.url.returns(''); subject.registerObserver(observer); subject.open(1000).should.eventually.be.fulfilled; }); @@ -98,6 +100,7 @@ describe('DefaultScreenSharingSession', function() { const event = Substitute.for(); event.type.returns('error'); promisedWebSocket.open(Arg.any()).returns(Promise.reject(event)); + promisedWebSocket.url.returns(''); subject.open(1000).should.eventually.be.rejected.and.notify(done); }); });