Skip to content

Commit

Permalink
Fixed setSinkId() throwing DOMException in Chromium browsers
Browse files Browse the repository at this point in the history
  • Loading branch information
RidipDe committed Jun 29, 2020
1 parent 457f6a2 commit fe44b3c
Show file tree
Hide file tree
Showing 9 changed files with 2,397 additions and 2,353 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix uuidv4 import
- Fix missing uuidv4 import in integration test
- Disable w3c check for Chrome Android webdriver integration tests
- Fix setSinkId() from throwing DOMException in Chromium browsers

## [1.10.0] - 2020-06-23

Expand Down
2 changes: 1 addition & 1 deletion demos/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
},
"dependencies": {
"amazon-chime-sdk-js": "file:../..",
"aws-sdk": "^2.704.0",
"aws-sdk": "^2.707.0",
"bootstrap": "^4.3.1",
"compression": "^1.7.4",
"jquery": "^3.4.1",
Expand Down
4,678 changes: 2,341 additions & 2,337 deletions docs/assets/js/search.js

Large diffs are not rendered by default.

30 changes: 22 additions & 8 deletions docs/classes/defaultaudiomixcontroller.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ <h3>Properties</h3>
<li class="tsd-kind-property tsd-parent-kind-class tsd-is-private"><a href="defaultaudiomixcontroller.html#audiodevice" class="tsd-kind-icon">audio<wbr>Device</a></li>
<li class="tsd-kind-property tsd-parent-kind-class tsd-is-private"><a href="defaultaudiomixcontroller.html#audioelement" class="tsd-kind-icon">audio<wbr>Element</a></li>
<li class="tsd-kind-property tsd-parent-kind-class tsd-is-private"><a href="defaultaudiomixcontroller.html#audiostream" class="tsd-kind-icon">audio<wbr>Stream</a></li>
<li class="tsd-kind-property tsd-parent-kind-class tsd-is-private"><a href="defaultaudiomixcontroller.html#browserbehavior" class="tsd-kind-icon">browser<wbr>Behavior</a></li>
</ul>
</section>
<section class="tsd-index-section ">
Expand All @@ -113,7 +114,7 @@ <h3><span class="tsd-flag ts-flagPrivate">Private</span> audio<wbr>Device</h3>
<div class="tsd-signature tsd-kind-icon">audio<wbr>Device<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">MediaDeviceInfo</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">null</span><span class="tsd-signature-symbol"> = null</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/aws/amazon-chime-sdk-js/blob/master/src/audiomixcontroller/DefaultAudioMixController.ts#L7">src/audiomixcontroller/DefaultAudioMixController.ts:7</a></li>
<li>Defined in <a href="https://github.com/aws/amazon-chime-sdk-js/blob/master/src/audiomixcontroller/DefaultAudioMixController.ts#L10">src/audiomixcontroller/DefaultAudioMixController.ts:10</a></li>
</ul>
</aside>
</section>
Expand All @@ -123,7 +124,7 @@ <h3><span class="tsd-flag ts-flagPrivate">Private</span> audio<wbr>Element</h3>
<div class="tsd-signature tsd-kind-icon">audio<wbr>Element<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">HTMLAudioElement</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">null</span><span class="tsd-signature-symbol"> = null</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/aws/amazon-chime-sdk-js/blob/master/src/audiomixcontroller/DefaultAudioMixController.ts#L8">src/audiomixcontroller/DefaultAudioMixController.ts:8</a></li>
<li>Defined in <a href="https://github.com/aws/amazon-chime-sdk-js/blob/master/src/audiomixcontroller/DefaultAudioMixController.ts#L11">src/audiomixcontroller/DefaultAudioMixController.ts:11</a></li>
</ul>
</aside>
</section>
Expand All @@ -133,7 +134,17 @@ <h3><span class="tsd-flag ts-flagPrivate">Private</span> audio<wbr>Stream</h3>
<div class="tsd-signature tsd-kind-icon">audio<wbr>Stream<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">MediaStream</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">null</span><span class="tsd-signature-symbol"> = null</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/aws/amazon-chime-sdk-js/blob/master/src/audiomixcontroller/DefaultAudioMixController.ts#L9">src/audiomixcontroller/DefaultAudioMixController.ts:9</a></li>
<li>Defined in <a href="https://github.com/aws/amazon-chime-sdk-js/blob/master/src/audiomixcontroller/DefaultAudioMixController.ts#L12">src/audiomixcontroller/DefaultAudioMixController.ts:12</a></li>
</ul>
</aside>
</section>
<section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-class tsd-is-private">
<a name="browserbehavior" class="tsd-anchor"></a>
<h3><span class="tsd-flag ts-flagPrivate">Private</span> browser<wbr>Behavior</h3>
<div class="tsd-signature tsd-kind-icon">browser<wbr>Behavior<span class="tsd-signature-symbol">:</span> <a href="../interfaces/browserbehavior.html" class="tsd-signature-type">BrowserBehavior</a><span class="tsd-signature-symbol"> = new DefaultBrowserBehavior()</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/aws/amazon-chime-sdk-js/blob/master/src/audiomixcontroller/DefaultAudioMixController.ts#L13">src/audiomixcontroller/DefaultAudioMixController.ts:13</a></li>
</ul>
</aside>
</section>
Expand All @@ -151,7 +162,7 @@ <h3>bind<wbr>Audio<wbr>Device</h3>
<aside class="tsd-sources">
<p>Implementation of <a href="../interfaces/audiomixcontroller.html">AudioMixController</a>.<a href="../interfaces/audiomixcontroller.html#bindaudiodevice">bindAudioDevice</a></p>
<ul>
<li>Defined in <a href="https://github.com/aws/amazon-chime-sdk-js/blob/master/src/audiomixcontroller/DefaultAudioMixController.ts#L35">src/audiomixcontroller/DefaultAudioMixController.ts:35</a></li>
<li>Defined in <a href="https://github.com/aws/amazon-chime-sdk-js/blob/master/src/audiomixcontroller/DefaultAudioMixController.ts#L39">src/audiomixcontroller/DefaultAudioMixController.ts:39</a></li>
</ul>
</aside>
<h4 class="tsd-parameters-title">Parameters</h4>
Expand All @@ -175,7 +186,7 @@ <h3>bind<wbr>Audio<wbr>Element</h3>
<aside class="tsd-sources">
<p>Implementation of <a href="../interfaces/audiomixcontroller.html">AudioMixController</a>.<a href="../interfaces/audiomixcontroller.html#bindaudioelement">bindAudioElement</a></p>
<ul>
<li>Defined in <a href="https://github.com/aws/amazon-chime-sdk-js/blob/master/src/audiomixcontroller/DefaultAudioMixController.ts#L11">src/audiomixcontroller/DefaultAudioMixController.ts:11</a></li>
<li>Defined in <a href="https://github.com/aws/amazon-chime-sdk-js/blob/master/src/audiomixcontroller/DefaultAudioMixController.ts#L15">src/audiomixcontroller/DefaultAudioMixController.ts:15</a></li>
</ul>
</aside>
<h4 class="tsd-parameters-title">Parameters</h4>
Expand All @@ -198,7 +209,7 @@ <h3><span class="tsd-flag ts-flagPrivate">Private</span> bind<wbr>Audio<wbr>Mix<
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/aws/amazon-chime-sdk-js/blob/master/src/audiomixcontroller/DefaultAudioMixController.ts#L43">src/audiomixcontroller/DefaultAudioMixController.ts:43</a></li>
<li>Defined in <a href="https://github.com/aws/amazon-chime-sdk-js/blob/master/src/audiomixcontroller/DefaultAudioMixController.ts#L47">src/audiomixcontroller/DefaultAudioMixController.ts:47</a></li>
</ul>
</aside>
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">boolean</span></h4>
Expand All @@ -216,7 +227,7 @@ <h3>bind<wbr>Audio<wbr>Stream</h3>
<aside class="tsd-sources">
<p>Implementation of <a href="../interfaces/audiomixcontroller.html">AudioMixController</a>.<a href="../interfaces/audiomixcontroller.html#bindaudiostream">bindAudioStream</a></p>
<ul>
<li>Defined in <a href="https://github.com/aws/amazon-chime-sdk-js/blob/master/src/audiomixcontroller/DefaultAudioMixController.ts#L27">src/audiomixcontroller/DefaultAudioMixController.ts:27</a></li>
<li>Defined in <a href="https://github.com/aws/amazon-chime-sdk-js/blob/master/src/audiomixcontroller/DefaultAudioMixController.ts#L31">src/audiomixcontroller/DefaultAudioMixController.ts:31</a></li>
</ul>
</aside>
<h4 class="tsd-parameters-title">Parameters</h4>
Expand All @@ -240,7 +251,7 @@ <h3>unbind<wbr>Audio<wbr>Element</h3>
<aside class="tsd-sources">
<p>Implementation of <a href="../interfaces/audiomixcontroller.html">AudioMixController</a>.<a href="../interfaces/audiomixcontroller.html#unbindaudioelement">unbindAudioElement</a></p>
<ul>
<li>Defined in <a href="https://github.com/aws/amazon-chime-sdk-js/blob/master/src/audiomixcontroller/DefaultAudioMixController.ts#L20">src/audiomixcontroller/DefaultAudioMixController.ts:20</a></li>
<li>Defined in <a href="https://github.com/aws/amazon-chime-sdk-js/blob/master/src/audiomixcontroller/DefaultAudioMixController.ts#L24">src/audiomixcontroller/DefaultAudioMixController.ts:24</a></li>
</ul>
</aside>
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">void</span></h4>
Expand Down Expand Up @@ -273,6 +284,9 @@ <h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">void</spa
<li class=" tsd-kind-property tsd-parent-kind-class tsd-is-private">
<a href="defaultaudiomixcontroller.html#audiostream" class="tsd-kind-icon">audio<wbr>Stream</a>
</li>
<li class=" tsd-kind-property tsd-parent-kind-class tsd-is-private">
<a href="defaultaudiomixcontroller.html#browserbehavior" class="tsd-kind-icon">browser<wbr>Behavior</a>
</li>
<li class=" tsd-kind-method tsd-parent-kind-class">
<a href="defaultaudiomixcontroller.html#bindaudiodevice" class="tsd-kind-icon">bind<wbr>Audio<wbr>Device</a>
</li>
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "amazon-chime-sdk-js",
"version": "1.10.8",
"version": "1.10.9",
"description": "Amazon Chime SDK for JavaScript",
"main": "build/index.js",
"types": "build/index.d.ts",
Expand Down
21 changes: 18 additions & 3 deletions src/audiomixcontroller/DefaultAudioMixController.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
// Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// Copyright 2019-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import BrowserBehavior from '../browserbehavior/BrowserBehavior';
import DefaultBrowserBehavior from '../browserbehavior/DefaultBrowserBehavior';
import AsyncScheduler from '../scheduler/AsyncScheduler';
import AudioMixController from './AudioMixController';

export default class DefaultAudioMixController implements AudioMixController {
private audioDevice: MediaDeviceInfo | null = null;
private audioElement: HTMLAudioElement | null = null;
private audioStream: MediaStream | null = null;
private browserBehavior: BrowserBehavior = new DefaultBrowserBehavior();

bindAudioElement(element: HTMLAudioElement): boolean {
if (element) {
Expand Down Expand Up @@ -51,8 +55,19 @@ export default class DefaultAudioMixController implements AudioMixController {
// @ts-ignore
const oldSinkId: string = this.audioElement.sinkId;
if (newSinkId !== oldSinkId) {
// @ts-ignore
this.audioElement.setSinkId(newSinkId);
if (this.browserBehavior.hasChromiumWebRTC()) {
new AsyncScheduler().start(async () => {
const existingStream = await this.audioElement.srcObject;
this.audioElement.srcObject = null;
// @ts-ignore
await this.audioElement.setSinkId(newSinkId);
this.audioElement.srcObject = existingStream;
this.audioStream = existingStream as MediaStream;
});
} else {
// @ts-ignore
this.audioElement.setSinkId(newSinkId);
}
}
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/versioning/Versioning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default class Versioning {
* Return string representation of SDK version
*/
static get sdkVersion(): string {
return '1.10.8';
return '1.10.9';
}

/**
Expand Down
12 changes: 11 additions & 1 deletion test/audiomixcontroller/DefaultAudioMixController.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// Copyright 2019-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import * as chai from 'chai';
Expand Down Expand Up @@ -46,6 +46,7 @@ describe('DefaultAudioMixController', () => {
it('can unbind an audio element when element does not exist', () => {
defaultAudioMixController.bindAudioDevice(device);
defaultAudioMixController.bindAudioStream(stream);
defaultAudioMixController.unbindAudioElement();
expect(defaultAudioMixController.bindAudioElement(element)).to.equal(true);
defaultAudioMixController.unbindAudioElement();
expect(defaultAudioMixController.bindAudioStream(stream)).to.equal(false);
Expand All @@ -71,6 +72,15 @@ describe('DefaultAudioMixController', () => {
expect(defaultAudioMixController.bindAudioStream(stream)).to.equal(true);
});

it('can successfully bind and sink an audio stream in chromium based browser', () => {
behavior.browserName = 'chrome';
domMockBuilder = new DOMMockBuilder(behavior);
defaultAudioMixController = new DefaultAudioMixController();
defaultAudioMixController.bindAudioDevice(device);
defaultAudioMixController.bindAudioElement(element);
expect(defaultAudioMixController.bindAudioStream(stream)).to.equal(true);
});

it('can bind an audio device, but not yet sink', () => {
expect(defaultAudioMixController.bindAudioDevice(device)).to.equal(false);
});
Expand Down

0 comments on commit fe44b3c

Please sign in to comment.