Skip to content

Commit ee5c1c7

Browse files
committed
Switching to notifications
1 parent 39c9ca0 commit ee5c1c7

File tree

3 files changed

+27
-14
lines changed

3 files changed

+27
-14
lines changed

injected/src/features/duckplayer-native/duckplayer-native.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@ export async function initDuckPlayerNative(messages) {
2727
/**
2828
* Set up subscription listeners
2929
*/
30-
messages.onGetCurrentTimestamp(() => {
31-
console.log('GET CURRENT TIMESTAMP');
32-
getCurrentTimestamp();
33-
});
30+
// messages.onGetCurrentTimestamp(() => {
31+
// console.log('GET CURRENT TIMESTAMP');
32+
// getCurrentTimestamp();
33+
// });
3434

3535
messages.onMediaControl(() => {
3636
console.log('MEDIA CONTROL');
3737
mediaControl();
3838
});
3939

40-
messages.onMuteAudio((mute) => {
40+
messages.onMuteAudio(({ mute }) => {
4141
console.log('MUTE AUDIO', mute);
4242
muteAudio(mute);
4343
});
@@ -52,6 +52,14 @@ export async function initDuckPlayerNative(messages) {
5252
const destroy = errorDetection.observe();
5353
if (destroy) sideEffects.push(destroy);
5454

55+
/* Start timestamp polling */
56+
const timestampPolling = setInterval(() => {
57+
messages.onGetCurrentTimestamp(getCurrentTimestamp());
58+
});
59+
sideEffects.push(() => {
60+
clearInterval(timestampPolling);
61+
});
62+
5563
return async () => {
5664
return await Promise.all(sideEffects.map((destroy) => destroy()));
5765
};
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
2-
// @ts-nocheck - Typing will be fixed in the future
3-
1+
/**
2+
* @returns {number}
3+
*/
44
export function getCurrentTimestamp() {
55
const video = document.querySelector('video');
6-
return video ? video.currentTime : 0;
6+
return video?.currentTime || 0;
77
}

injected/src/features/duckplayer-native/native-messages.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import * as constants from './constants.js';
22

3+
/**
4+
* @typedef {object} muteSettings - Settings passing to the onMute callback
5+
* @property {boolean} mute - Set to true to mute the video, false to unmute
6+
*/
7+
38
/**
49
* @typedef {import("@duckduckgo/messaging").Messaging} Messaging
510
*
@@ -38,11 +43,11 @@ export class DuckPlayerNativeMessages {
3843
}
3944

4045
/**
41-
* Subscribe to get current timestamp events
42-
* @param {() => void} callback
46+
* Notifies with current timestamp
47+
* @param {number} timestamp
4348
*/
44-
onGetCurrentTimestamp(callback) {
45-
return this.messaging.subscribe('onGetCurrentTimestamp', callback);
49+
onGetCurrentTimestamp(timestamp) {
50+
return this.messaging.notify('onGetCurrentTimestamp', { timestamp });
4651
}
4752

4853
/**
@@ -55,7 +60,7 @@ export class DuckPlayerNativeMessages {
5560

5661
/**
5762
* Subscribe to mute audio events
58-
* @param {(mute: boolean) => void} callback
63+
* @param {(muteSettings: muteSettings) => void} callback
5964
*/
6065
onMuteAudio(callback) {
6166
return this.messaging.subscribe('onMuteAudio', callback);

0 commit comments

Comments
 (0)