Skip to content

Commit

Permalink
Fix Firefox keyframing
Browse files Browse the repository at this point in the history
- Firefox does not expect us to stop the underlying MediaStreamTrack,
  but Chrome does
  • Loading branch information
agowatch committed Dec 20, 2019
1 parent ed3a657 commit eff5994
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 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.592.0",
"aws-sdk": "^2.594.0",
"bootstrap": "^4.3.1",
"compression": "^1.7.4",
"jquery": "^3.4.1",
Expand Down
16 changes: 11 additions & 5 deletions src/mediarecording/WebMMediaRecording.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
// Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import DefaultBrowserBehavior from '../browserbehavior/DefaultBrowserBehavior';
import Maybe from '../maybe/Maybe';
import MediaRecording from './MediaRecording';
import MediaRecordingEvent from './MediaRecordingEvent';
import MediaRecordingOptions from './MediaRecordingOptions';

export default class WebMMediaRecording implements MediaRecording {
static readonly options: MediaRecorderOptions = {
private static readonly browser = new DefaultBrowserBehavior();
private static readonly options: MediaRecorderOptions = {
mimeType: 'video/webm; codecs=vp8',
};

private delegate: MediaRecorder | null = null;
readonly options: MediaRecorderOptions;
readonly mediaStream: MediaStream;
private timeSliceMs: number;
private listeners = new Map<string, Set<EventListener>>();

constructor(mediaStream: MediaStream, options: MediaRecordingOptions = {}) {
constructor(
private mediaStream: MediaStream,
options: MediaRecordingOptions = {},
private browser: DefaultBrowserBehavior = WebMMediaRecording.browser
) {
this.options = { ...options, ...WebMMediaRecording.options };
this.mediaStream = mediaStream;
}

key(): void {
Expand All @@ -41,7 +45,9 @@ export default class WebMMediaRecording implements MediaRecording {
});
});
if (delegate !== null) {
delegate.stream.getTracks().forEach(stream => stream.stop());
if (this.browser.isChrome()) {
delegate.stream.getTracks().forEach(stream => stream.stop());
}
delegate.stop();
}
this.delegate.start(this.timeSliceMs);
Expand Down
20 changes: 19 additions & 1 deletion test/mediarecording/WebMMediaRecording.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Substitute from '@fluffy-spoon/substitute';
import * as chai from 'chai';
import * as chaiAsPromised from 'chai-as-promised';

import DefaultBrowserBehavior from '../../src/browserbehavior/DefaultBrowserBehavior';
import MediaRecordingOptions from '../../src/mediarecording/MediaRecordingOptions';
import WebMMediaRecording from '../../src/mediarecording/WebMMediaRecording';
import CustomEventMock from '../customeventmock/CustomEventMock';
Expand All @@ -29,7 +30,8 @@ describe('WebMMediaRecording', () => {
describe('with start', () => {
it('is keyed', () => {
const mediaStream = Substitute.for<MediaStream>();
mediaStream.getTracks().returns(Array.of(Substitute.for<MediaStreamTrack>()));
const mediaTrack = Substitute.for<MediaStreamTrack>();
mediaStream.getTracks().returns(Array.of(mediaTrack));
mediaStream.clone().returns(mediaStream);
const subject = new WebMMediaRecording(mediaStream);
subject.start(1000);
Expand All @@ -42,6 +44,22 @@ describe('WebMMediaRecording', () => {
new WebMMediaRecording(Substitute.for<MediaStream>()).key();
});
});

describe('with Chrome', () => {
it('is keyed', () => {
const browser = Substitute.for<DefaultBrowserBehavior>();
const mediaStream = Substitute.for<MediaStream>();
const mediaTrack = Substitute.for<MediaStreamTrack>();
mediaTrack.stop().returns();
mediaStream.getTracks().returns(Array.of(mediaTrack));
mediaStream.clone().returns(mediaStream);
browser.isChrome().returns(true);
const subject = new WebMMediaRecording(mediaStream, {}, browser);
subject.key();
subject.key();
mediaTrack.received().stop();
});
});
});

describe('with MediaRecordingOptions', () => {
Expand Down

0 comments on commit eff5994

Please sign in to comment.