Skip to content

Commit

Permalink
Improve logging
Browse files Browse the repository at this point in the history
  • Loading branch information
agowatch committed Dec 18, 2019
1 parent f506602 commit 52fa248
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 2 deletions.
2 changes: 1 addition & 1 deletion demos/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/domwebsocket/DOMWebSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/domwebsocket/DefaultDOMWebSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 4 additions & 0 deletions src/promisedwebsocket/DefaultPromisedWebSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Event> {
const promise = new Promise<Event>((resolve, reject) => {
this.webSocket.onclose = (event: CloseEvent) => {
Expand Down
2 changes: 2 additions & 0 deletions src/promisedwebsocket/PromisedWebSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/promisedwebsocket/ReconnectingPromisedWebSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/screensharingsession/DefaultScreenSharingSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions test/domwebsocket/DefaultDOMWebSocket.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ describe('DefaultDOMWebSocket', () => {
chai.should();
});

describe('url', () => {
it('is delegated', () => {
const url = 'ws://localhost';
const webSocket = Substitute.for<WebSocket>();
webSocket.url.returns(url);
chai.expect(new DefaultDOMWebSocket(webSocket).url).to.eq(url);
});
});

describe('onopen', () => {
const subject = new DefaultDOMWebSocket(Substitute.for<WebSocket>());

Expand Down
3 changes: 3 additions & 0 deletions test/domwebsocketmock/DOMWebSocketMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions test/promisedwebsocket/DefaultPromisedWebSocket.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
4 changes: 4 additions & 0 deletions test/promisedwebsocketmock/PromisedWebSocketMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import PromisedWebSocket from '../../src/promisedwebsocket/PromisedWebSocket';
export default class PromisedWebSocketMock implements PromisedWebSocket {
private callbacks = new Map<string, Set<EventListener>>();

get url(): string {
return 'ws://localhost';
}

open(_timeoutMs: number): Promise<Event> {
return Promise.resolve(Substitute.for<Event>());
}
Expand Down
3 changes: 3 additions & 0 deletions test/screensharingsession/DefaultScreenSharingSession.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ describe('DefaultScreenSharingSession', function() {
const event = Substitute.for<Event>();
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);
});
Expand All @@ -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;
});
Expand All @@ -98,6 +100,7 @@ describe('DefaultScreenSharingSession', function() {
const event = Substitute.for<Event>();
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);
});
});
Expand Down

0 comments on commit 52fa248

Please sign in to comment.