Skip to content

Commit 54f7793

Browse files
feat: player disable tracking and cookies reactive (muxinc#1214)
Resolves [1193](muxinc#1193) by adding two new cases in the `attributeChangedCallback` of the base of the player: 1. **DISABLE_TRACKING**: Reloads the player when this attribute changes, since tracking must be disabled on initialization (keeping the currentTime and playbackState). 2. **DISABLE_COOKIES**: Deletes the tracking cookie if the attribute is changed after initialization. These changes allow the user disable this tracking props on the run without breaking he experience of playing the video.
1 parent 78f7154 commit 54f7793

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

packages/mux-video/src/base.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,35 @@ export class MuxVideoBaseElement extends CustomVideoElement implements IMuxVideo
857857
this.updateLogo();
858858
}
859859
break;
860+
case Attributes.DISABLE_TRACKING: {
861+
if (newValue == null || newValue !== oldValue) {
862+
const currentTime = this.currentTime;
863+
const paused = this.paused;
864+
this.unload();
865+
this.#requestLoad().then(() => {
866+
this.currentTime = currentTime;
867+
if (!paused) {
868+
this.play();
869+
}
870+
});
871+
}
872+
break;
873+
}
874+
case Attributes.DISABLE_COOKIES: {
875+
if (newValue == null || newValue !== oldValue) {
876+
const disabled = this.disableCookies;
877+
if (disabled) {
878+
document.cookie.split(';').forEach((c) => {
879+
if (c.trim().startsWith('muxData')) {
880+
document.cookie = c
881+
.replace(/^ +/, '')
882+
.replace(/=.*/, '=;expires=' + new Date().toUTCString() + ';path=/');
883+
}
884+
});
885+
}
886+
}
887+
break;
888+
}
860889
}
861890
}
862891

0 commit comments

Comments
 (0)