Skip to content

Commit

Permalink
refactor(player): mouse idle detect
Browse files Browse the repository at this point in the history
  • Loading branch information
WakelessSloth56 committed Aug 26, 2024
1 parent d0ae7ea commit 71a2f6c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
9 changes: 0 additions & 9 deletions src/core/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -493,14 +493,6 @@ const danmakuStage = new EDC('div', 'danmakuStage')

// ====================================================================== //

const mouseIdle = (P: Player) => {
clearTimeout(P.temp.mouseTimer);
P.setData('mouseIdle', false);
P.temp.mouseTimer = setTimeout(() => {
P.setData('mouseIdle', true);
}, 1e3);
};

const hotkeys = (P: Player, T: KeyboardEvent) => {
if (T.target === P.container) {
switch (T.keyCode) {
Expand Down Expand Up @@ -623,7 +615,6 @@ export const defaultPlayerMetadata = {
.children(subtitleStage, danmakuStage),
],
playerEvent: {
mousemove: mouseIdle,
keydown: hotkeys,
},
} as PlayerMetadata;
8 changes: 8 additions & 0 deletions src/core/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ export default class Player {
this.firePlayerEvent(fullscreen ? 'fullscreen' : 'fullscreenexit');
toggleClass(this.container, 'fullscreen', fullscreen);
});
this.onPlayerEvent('mousemove', () => {
clearTimeout(this.temp.mouseTimer);
this.setData('mouseIdle', false);
this.temp.mouseTimer = setTimeout(() => {
this.setData('mouseIdle', true);
this.firePlayerEvent('mouseidle');
}, 1 * 1000);
});
new ResizeObserver(() => {
this.video.dispatchEvent(
new CustomEvent('resize', {
Expand Down

0 comments on commit 71a2f6c

Please sign in to comment.