Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VIH-8233 Mic Visualiser bar crashing on device change when only one mic available #2130

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ describe('ForcePlayVideoDirective', () => {
let onPlayingCallback: (event: any) => void = null;
let onPauseCallback: (event: any) => void = null;
let onErrorCallback: (event: any) => void = null;
let onLoadedMetadaCallback: (event: any) => void = null;

beforeEach(() => {
elementRefSpy = jasmine.createSpyObj<ElementRef>([], ['nativeElement']);
nativeElementSpy = jasmine.createSpyObj<HTMLVideoElement>(['play', 'pause'], ['oncanplay', 'onerror', 'onplaying', 'onpause']);
nativeElementSpy = jasmine.createSpyObj<HTMLVideoElement>(
['play', 'pause'],
['oncanplay', 'onerror', 'onplaying', 'onpause', 'onloadedmetadata']
);
nativeElementSpy.play.and.callFake(() => Promise.resolve());
getSpiedPropertyGetter(elementRefSpy, 'nativeElement').and.returnValue(nativeElementSpy);
getSpiedPropertySetter(nativeElementSpy, 'oncanplay').and.callFake((callback: (event: any) => void) => {
Expand All @@ -39,6 +43,10 @@ describe('ForcePlayVideoDirective', () => {
onErrorCallback = callback;
});

getSpiedPropertySetter(nativeElementSpy, 'onloadedmetadata').and.callFake((callback: (event: any) => void) => {
onLoadedMetadaCallback = callback;
});

renderer2FactorySpy = jasmine.createSpyObj<RendererFactory2>(['createRenderer']);
renderer2Spy = jasmine.createSpyObj<Renderer2>(['setAttribute', 'listen']);

Expand Down Expand Up @@ -135,6 +143,7 @@ describe('ForcePlayVideoDirective', () => {

// Act
onCanPlayCallback(null);
onLoadedMetadaCallback(null);

// Assert
expect(nativeElementSpy.play).toHaveBeenCalledTimes(1);
Expand All @@ -160,6 +169,7 @@ describe('ForcePlayVideoDirective', () => {

// Act
onCanPlayCallback(null);
onLoadedMetadaCallback(null);
tick();

// Assert
Expand Down Expand Up @@ -213,6 +223,7 @@ describe('ForcePlayVideoDirective', () => {

// Act
mouseDownCallback(null);
onLoadedMetadaCallback(null);

// Assert
expect(nativeElementSpy.play).toHaveBeenCalledTimes(1);
Expand Down Expand Up @@ -291,6 +302,7 @@ describe('ForcePlayVideoDirective', () => {

// Act
mouseDownCallback(null);
onLoadedMetadaCallback(null);
tick();

// Assert
Expand Down Expand Up @@ -332,6 +344,7 @@ describe('ForcePlayVideoDirective', () => {

// Act
touchStartCallback(null);
onLoadedMetadaCallback(null);

// Assert
expect(nativeElementSpy.play).toHaveBeenCalledTimes(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,11 @@ export class ForcePlayVideoDirective implements OnInit, OnDestroy {
if (isPlayingElem) {
return;
}
this.videoElement.play().catch(error => {
this.logger.error(`${this.loggerPrefix} - error playing video.`, error);
});
this.videoElement.onloadedmetadata = () => {
this.videoElement.play().catch(error => {
this.logger.error(`${this.loggerPrefix} - error playing video.`, error);
});
};
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class SelectMediaDevicesComponent implements OnInit, OnDestroy, AfterView

ngAfterViewInit() {
ModalTrapFocus.trap(this.SELECT_MEDIA_DEVICES_MODAL);
this.availableMicsList.nativeElement.focus();
this.availableMicsList?.nativeElement.focus();
}

ngOnInit() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ <h1 class="govuk-heading-xl mb-2">
<div class="self-view-container">
<div>
<video
appForcePlayVideo
#selfViewVideo
[muted]="true"
*ngIf="streamsActive"
id="outgoingStream"
[srcObject]="this.outgoingStream"
width="100%"
Expand All @@ -35,15 +34,15 @@ <h1 class="govuk-heading-xl mb-2">
<app-mic-visualiser
*ngIf="displayFeed && streamsActive && preferredMicrophoneStream"
[stream]="preferredMicrophoneStream"
[incomingStream]="incomingStream"
[incomingStream]="preferredMicrophoneStream"
></app-mic-visualiser>
</div>
</div>
</div>

<div class="govuk-grid-row">
<div *ngIf="showChangeDevices" class="govuk-grid-column-full govuk-!-margin-bottom-6">
<a id="change-device-link" href="javascript:void(0);" role="button" (click)="changeDevices()" class="govuk-link">{{
<a id="change-device-link" href="javascript:void(0);" (click)="changeDevices()" class="govuk-link">{{
'self-test.change-camera-mic' | translate
}}</a>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { mockMicStream } from 'src/app/waiting-space/waiting-room-shared/tests/w
import { getSpiedPropertyGetter } from '../jasmine-helpers/property-helpers';
import { UserMediaDevice } from '../models/user-media-device';
import { SelfTestComponent } from './self-test.component';
import { ElementRef } from '@angular/core';

describe('SelfTestComponent', () => {
let component: SelfTestComponent;
Expand All @@ -36,6 +37,7 @@ describe('SelfTestComponent', () => {
let userMediaServiceSpy: jasmine.SpyObj<UserMediaService>;
let connectedDevicesSubject: Subject<UserMediaDevice[]>;
let activateMicrophoneSubject: Subject<MediaStream>;
let activeCameraStreamSubject: Subject<MediaStream>;

let userMediaStreamServiceSpy: jasmine.SpyObj<UserMediaStreamService>;
let videoCallServiceSpy: jasmine.SpyObj<VideoCallService>;
Expand Down Expand Up @@ -65,12 +67,14 @@ describe('SelfTestComponent', () => {

connectedDevicesSubject = new Subject<UserMediaDevice[]>();
activateMicrophoneSubject = new Subject<MediaStream>();
activeCameraStreamSubject = new Subject<MediaStream>();
getSpiedPropertyGetter(userMediaServiceSpy, 'connectedDevices$').and.returnValue(connectedDevicesSubject.asObservable());

userMediaStreamServiceSpy = jasmine.createSpyObj<UserMediaStreamService>([], ['activeMicrophoneStream$']);
userMediaStreamServiceSpy = jasmine.createSpyObj<UserMediaStreamService>([], ['activeMicrophoneStream$', 'activeCameraStream$']);
getSpiedPropertyGetter(userMediaStreamServiceSpy, 'activeMicrophoneStream$').and.returnValue(
activateMicrophoneSubject.asObservable()
);
getSpiedPropertyGetter(userMediaStreamServiceSpy, 'activeCameraStream$').and.returnValue(activeCameraStreamSubject.asObservable());

videoCallServiceSpy = jasmine.createSpyObj<VideoCallService>([
'onCallConnected',
Expand Down Expand Up @@ -726,6 +730,15 @@ describe('SelfTestComponent', () => {
});

describe('on handleCallSetup', () => {
let videoElementRefMock: ElementRef;

beforeEach(() => {
videoElementRefMock = {
nativeElement: document.createElement('video')
};

component.videoElement = videoElementRefMock;
});
it('should set the stream and connect the call', () => {
// Arrange
const expectedPin = '0000';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, EventEmitter, HostListener, Input, OnDestroy, OnInit, Output } from '@angular/core';
import { Component, ElementRef, EventEmitter, HostListener, Input, OnDestroy, OnInit, Output, ViewChild } from '@angular/core';
import { Guid } from 'guid-typescript';
import { Subject, Subscription } from 'rxjs';
import { take, takeUntil } from 'rxjs/operators';
Expand Down Expand Up @@ -35,6 +35,8 @@ export class SelfTestComponent implements OnInit, OnDestroy {
@Output() testStarted = new EventEmitter();
@Output() testCompleted = new EventEmitter<TestCallScoreResponse>();

@ViewChild('selfViewVideo') videoElement: ElementRef;

token: TokenResponse;
incomingStream: MediaStream | URL;
outgoingStream: MediaStream | URL;
Expand Down Expand Up @@ -177,6 +179,10 @@ export class SelfTestComponent implements OnInit, OnDestroy {
.pipe(takeUntil(this.destroyedSubject))
.subscribe(micStream => (this.preferredMicrophoneStream = micStream));

this.userMediaStreamService.activeCameraStream$
.pipe(takeUntil(this.destroyedSubject))
.subscribe(cameraStream => (this.outgoingStream = cameraStream));

this.userMediaService
.hasMultipleDevices()
.pipe(takeUntil(this.destroyedSubject))
Expand Down Expand Up @@ -209,6 +215,10 @@ export class SelfTestComponent implements OnInit, OnDestroy {
participant: this.selfTestParticipantId
});
this.outgoingStream = callSetup.stream;
this.videoElement.nativeElement.srcObject = this.outgoingStream;
this.videoElement.nativeElement.addEventListener('loadedmetadata', () => {
this.videoElement.nativeElement.play().catch(error => this.logger.error(`${this.loggerPrefix} - Error playing video:`, error));
});
this.videoCallService.connect('0000', null);
}

Expand Down
5 changes: 4 additions & 1 deletion VideoWeb/VideoWeb/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
// this is a workaround to set HSTS in a docker
// reference from https://github.com/dotnet/dotnet-docker/issues/2268#issuecomment-714613811
app.Use(async (context, next) => {
context.Response.Headers.Add("Strict-Transport-Security", "max-age=31536000");
if (!context.Response.Headers.ContainsKey("Strict-Transport-Security"))
{
context.Response.Headers.Add("Strict-Transport-Security", "max-age=31536000");
}
await next.Invoke();
});

Expand Down
Loading