From 1955d1d17663afba4564e71445a92eeebd49a4d6 Mon Sep 17 00:00:00 2001 From: Dario Blanco Date: Wed, 19 Sep 2018 18:29:27 +0200 Subject: [PATCH] Add _attachments to Audio and Video Track for Safari support --- types/twilio-video/index.d.ts | 8 ++++++++ types/twilio-video/twilio-video-tests.ts | 6 +++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/types/twilio-video/index.d.ts b/types/twilio-video/index.d.ts index 1ec8c0c60a..a5bb8521ae 100644 --- a/types/twilio-video/index.d.ts +++ b/types/twilio-video/index.d.ts @@ -39,6 +39,10 @@ export class AudioTrack extends Track { kind: 'audio'; mediaStreamTrack: MediaStreamTrack; + // Required for Safari if you want to detach without errors + // See: https://github.com/twilio/twilio-video.js/issues/294#issuecomment-389708981 + _attachments?: HTMLMediaElement[]; + attach(element?: HTMLMediaElement | string): HTMLMediaElement; detach(element?: HTMLMediaElement | string): HTMLMediaElement[]; } @@ -433,6 +437,10 @@ export class VideoTrack extends Track { kind: 'video'; mediaStreamTrack: MediaStreamTrack; + // Required for Safari if you want to detach without errors + // See: https://github.com/twilio/twilio-video.js/issues/294#issuecomment-389708981 + _attachments?: HTMLMediaElement[]; + attach(element?: HTMLMediaElement | string): HTMLVideoElement; detach(element?: HTMLMediaElement | string): HTMLMediaElement[]; } diff --git a/types/twilio-video/twilio-video-tests.ts b/types/twilio-video/twilio-video-tests.ts index b06bf9b168..12291e9555 100644 --- a/types/twilio-video/twilio-video-tests.ts +++ b/types/twilio-video/twilio-video-tests.ts @@ -63,10 +63,14 @@ function trackSubscribed(track: Video.VideoTrack | Video.AudioTrack) { function trackUnsubscribed(track: Video.VideoTrack | Video.AudioTrack) { track.detach().forEach(element => element.remove()); + // Alternative if Safari crashes when detaching tracks + track._attachments!.forEach((detachedElement) => detachedElement.remove()); } -function insertDomElement(element: any) { +function insertDomElement(element: HTMLMediaElement) { // Do something with the dom element + document.createElement('div'); + element.appendChild(element); } initRoom();