Skip to content

Commit

Permalink
Fixing the ability to choose default input in browsers when default c…
Browse files Browse the repository at this point in the history
…hanges
  • Loading branch information
RidipDe committed Jun 18, 2020
1 parent 5edcc57 commit 08bb70b
Show file tree
Hide file tree
Showing 10 changed files with 2,768 additions and 2,621 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed
- Updated cloudwatch log stream ID to have attendee_id
- Fixing the ability to choose default input in browsers when default changes

## [1.9.0] - 2020-06-12

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.698.0",
"aws-sdk": "^2.699.0",
"bootstrap": "^4.3.1",
"compression": "^1.7.4",
"jquery": "^3.4.1",
Expand Down
5,138 changes: 2,581 additions & 2,557 deletions docs/assets/js/search.js

Large diffs are not rendered by default.

181 changes: 129 additions & 52 deletions docs/classes/defaultdevicecontroller.html

Large diffs are not rendered by default.

16 changes: 15 additions & 1 deletion docs/classes/deviceselection.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ <h2>Index</h2>
<h3>Properties</h3>
<ul class="tsd-index-list">
<li class="tsd-kind-property tsd-parent-kind-class"><a href="deviceselection.html#constraints" class="tsd-kind-icon">constraints</a></li>
<li class="tsd-kind-property tsd-parent-kind-class"><a href="deviceselection.html#groupid" class="tsd-kind-icon">group<wbr>Id</a></li>
<li class="tsd-kind-property tsd-parent-kind-class"><a href="deviceselection.html#stream" class="tsd-kind-icon">stream</a></li>
</ul>
</section>
Expand All @@ -106,6 +107,16 @@ <h3>constraints</h3>
</ul>
</aside>
</section>
<section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-class">
<a name="groupid" class="tsd-anchor"></a>
<h3>group<wbr>Id</h3>
<div class="tsd-signature tsd-kind-icon">group<wbr>Id<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> = &quot;&quot;</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/aws/amazon-chime-sdk-js/blob/master/src/devicecontroller/DeviceSelection.ts#L7">src/devicecontroller/DeviceSelection.ts:7</a></li>
</ul>
</aside>
</section>
<section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-class">
<a name="stream" class="tsd-anchor"></a>
<h3>stream</h3>
Expand All @@ -129,7 +140,7 @@ <h3>matches<wbr>Constraints</h3>
<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/devicecontroller/DeviceSelection.ts#L8">src/devicecontroller/DeviceSelection.ts:8</a></li>
<li>Defined in <a href="https://github.com/aws/amazon-chime-sdk-js/blob/master/src/devicecontroller/DeviceSelection.ts#L9">src/devicecontroller/DeviceSelection.ts:9</a></li>
</ul>
</aside>
<h4 class="tsd-parameters-title">Parameters</h4>
Expand Down Expand Up @@ -162,6 +173,9 @@ <h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">boolean</
<li class=" tsd-kind-property tsd-parent-kind-class">
<a href="deviceselection.html#constraints" class="tsd-kind-icon">constraints</a>
</li>
<li class=" tsd-kind-property tsd-parent-kind-class">
<a href="deviceselection.html#groupid" class="tsd-kind-icon">group<wbr>Id</a>
</li>
<li class=" tsd-kind-property tsd-parent-kind-class">
<a href="deviceselection.html#stream" class="tsd-kind-icon">stream</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.9.8",
"version": "1.9.9",
"description": "Amazon Chime SDK for JavaScript",
"main": "build/index.js",
"types": "build/index.d.ts",
Expand Down
42 changes: 36 additions & 6 deletions src/devicecontroller/DefaultDeviceController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ export default class DefaultDeviceController implements DeviceControllerBasedMed
private videoMaxBandwidthKbps: number = DefaultDeviceController.defaultVideoMaxBandwidthKbps;

private useWebAudio: boolean = false;
private deviceIdGroupIdMap: { [mediaDeviceKind: string]: Map<Device, string> } = {
audioinput: new Map(),
audiooutput: new Map(),
videoinput: new Map(),
};

private isAndroid: boolean = false;
private isPixel3: boolean = false;
Expand Down Expand Up @@ -394,6 +399,7 @@ export default class DefaultDeviceController implements DeviceControllerBasedMed
hasDeviceLabels = false;
break;
}
this.deviceIdGroupIdMap[device.kind].set(device.deviceId, device.groupId || '');
}
if (!hasDeviceLabels) {
try {
Expand Down Expand Up @@ -475,6 +481,15 @@ export default class DefaultDeviceController implements DeviceControllerBasedMed
return device && device.id ? device : null;
}

private isGroudpIdSame(groupId: string, kind: string, device: Device): boolean {
if (device === null) return false;
if (typeof device !== 'string')
device = JSON.parse(JSON.stringify(device)).deviceId
? JSON.parse(JSON.stringify(device)).deviceId.exact
: JSON.parse(JSON.stringify(device)).streamId;
return groupId === this.deviceIdGroupIdMap[kind + 'input'].get(device);
}

private async chooseInputDevice(
kind: string,
device: Device,
Expand All @@ -492,21 +507,24 @@ export default class DefaultDeviceController implements DeviceControllerBasedMed
return DevicePermission.PermissionGrantedByBrowser;
}

const proposedConstraints: MediaStreamConstraints | null = this.calculateMediaStreamConstraints(
let proposedConstraints: MediaStreamConstraints | null = this.calculateMediaStreamConstraints(
kind,
device
);

if (
this.activeDevices[kind] &&
this.activeDevices[kind].matchesConstraints(proposedConstraints) &&
this.activeDevices[kind].stream.active
this.activeDevices[kind].stream.active &&
this.activeDevices[kind].groupId !== null &&
this.isGroudpIdSame(this.activeDevices[kind].groupId, kind, device)
) {
this.logger.info(`reusing existing ${kind} device`);
return DevicePermission.PermissionGrantedPreviously;
}

const startTimeMs = Date.now();
const newDevice: DeviceSelection = new DeviceSelection();
const startTimeMs = Date.now();
try {
this.logger.info(
`requesting new ${kind} device with constraint ${JSON.stringify(proposedConstraints)}`
Expand All @@ -520,9 +538,16 @@ export default class DefaultDeviceController implements DeviceControllerBasedMed
newDevice.stream = stream;
newDevice.constraints = proposedConstraints;
} else {
//Check can be removed after we confirm that getUserMedia bug has been fixed by chromium
if (
kind === 'audio' &&
this.activeDevices[kind] &&
JSON.parse(JSON.stringify(proposedConstraints)).audio.deviceId.exact === 'default'
) {
this.activeDevices[kind].stream.getAudioTracks()[0].stop();
}
newDevice.stream = await navigator.mediaDevices.getUserMedia(proposedConstraints);
newDevice.constraints = proposedConstraints;

if (kind === 'video' && this.lastNoVideoInputDeviceCount > callCount) {
this.logger.warn(
`ignored to get video device for constraints ${JSON.stringify(
Expand Down Expand Up @@ -550,6 +575,13 @@ export default class DefaultDeviceController implements DeviceControllerBasedMed
}
});
}

let groupId = this.deviceIdGroupIdMap[kind + 'input'].get(device);
if (groupId === null) {
groupId = '';
this.deviceIdGroupIdMap[kind + 'input'].set(device, groupId);
}
newDevice.groupId = groupId;
} catch (error) {
this.logger.error(
`failed to get ${kind} device for constraints ${JSON.stringify(proposedConstraints)}: ${
Expand Down Expand Up @@ -641,8 +673,6 @@ export default class DefaultDeviceController implements DeviceControllerBasedMed
trackConstraints.width = trackConstraints.width || this.videoWidth;
trackConstraints.height = trackConstraints.height || this.videoHeight;
trackConstraints.frameRate = trackConstraints.frameRate || this.videoFrameRate;
// TODO: try to replace hard-code value related to videos into quality-level presets
// The following configs relaxes CPU overuse detection threshold to offer better encoding quality
// @ts-ignore
trackConstraints.googCpuOveruseDetection = true;
// @ts-ignore
Expand Down
3 changes: 2 additions & 1 deletion src/devicecontroller/DeviceSelection.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// 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

export default class DeviceSelection {
constraints: MediaStreamConstraints;
stream: MediaStream;
groupId: string = '';

matchesConstraints(constraints: MediaStreamConstraints): boolean {
return JSON.stringify(this.constraints) === JSON.stringify(constraints);
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.9.8';
return '1.9.9';
}

/**
Expand Down

0 comments on commit 08bb70b

Please sign in to comment.