Add more debugging for why audio ring/ringback might not be playing (#9642)

* Add more debugging for why audio might not be playing

More debugging for https://github.com/vector-im/element-web/issues/20832

* Listen to events from <audio>

* Make it easier to spot event type

* Move to start/stop functions

* Fix some lints

* Protect from potentially undefined element

* Needs more mocked functions

* More code coverage

* Test formatting

* Add return types

See https://github.com/matrix-org/matrix-react-sdk/pull/9642#discussion_r1036274817

* Add comment on when magic comment is applicable

See https://github.com/matrix-org/matrix-react-sdk/pull/9642#discussion_r1036258757
This commit is contained in:
Eric Eastwood 2022-11-30 22:08:09 -06:00 committed by GitHub
parent 5583d07f25
commit ca58617cee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 116 additions and 3 deletions

View file

@ -28,7 +28,7 @@ import { mocked } from 'jest-mock';
import { CallEventHandlerEvent } from 'matrix-js-sdk/src/webrtc/callEventHandler';
import LegacyCallHandler, {
LegacyCallHandlerEvent, PROTOCOL_PSTN, PROTOCOL_PSTN_PREFIXED, PROTOCOL_SIP_NATIVE, PROTOCOL_SIP_VIRTUAL,
LegacyCallHandlerEvent, AudioID, PROTOCOL_PSTN, PROTOCOL_PSTN_PREFIXED, PROTOCOL_SIP_NATIVE, PROTOCOL_SIP_VIRTUAL,
} from '../src/LegacyCallHandler';
import { stubClient, mkStubRoom, untilDispatch } from './test-utils';
import { MatrixClientPeg } from '../src/MatrixClientPeg';
@ -445,6 +445,9 @@ describe('LegacyCallHandler without third party protocols', () => {
const mockAudioElement = {
play: jest.fn(),
pause: jest.fn(),
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
muted: false,
} as unknown as HTMLMediaElement;
beforeEach(() => {
jest.clearAllMocks();
@ -488,6 +491,19 @@ describe('LegacyCallHandler without third party protocols', () => {
});
});
it('should unmute <audio> before playing', () => {
// Test setup: set the audio element as muted
mockAudioElement.muted = true;
expect(mockAudioElement.muted).toStrictEqual(true);
callHandler.play(AudioID.Ring);
// Ensure audio is no longer muted
expect(mockAudioElement.muted).toStrictEqual(false);
// Ensure the audio was played
expect(mockAudioElement.play).toHaveBeenCalled();
});
it('listens for incoming call events when voip is enabled', () => {
const call = new MatrixCall({
client: MatrixClientPeg.get(),