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();