Skip to content

Commit

Permalink
Opt: sync plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
zijiren233 committed Dec 10, 2023
1 parent 1b4c36f commit 632b5f3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 27 deletions.
17 changes: 1 addition & 16 deletions src/components/Player.vue
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,6 @@ console.log(Props.options);
const father = ref<HTMLDivElement>();
const euqalRecord = <T extends Record<string, unknown>>(a: T, b: T) => {
return Object.keys(a).every((key) => {
return a[key] === b[key];
});
};
const mountPlayer = () => {
const newDiv = document.createElement("div");
newDiv.setAttribute("class", "artplayer-app");
Expand All @@ -222,20 +216,11 @@ const mountPlayer = () => {
onMounted(() => {
mountPlayer();
const needDestroy = (oldOption: options, newOption: options) => {
return (
oldOption.isLive !== newOption.isLive ||
oldOption.type !== newOption.type ||
oldOption.url !== newOption.url ||
!euqalRecord(oldOption.headers, newOption.headers)
);
};
watchers.push(
watch(
() => Props.options,
(old, current) => {
if (!needDestroy(old, current)) return;
() => {
console.log("destroy");
if (art) art.destroy();
mountPlayer();
Expand Down
11 changes: 0 additions & 11 deletions src/plugins/sync.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { roomStore } from "@/stores/room";
import { debounces } from "@/utils";
import { useDebounceFn } from "@vueuse/core";
import { ElNotification } from "element-plus";
import { ElementMessage, ElementMessageType } from "@/proto/message";
const room = roomStore();

interface callback {
publishStatus: (msg: ElementMessage) => boolean;
Expand Down Expand Up @@ -146,15 +144,6 @@ export const sync = (cbk: callback): resould => {
const intervals: number[] = [];

art.once("ready", () => {
console.log(room.currentMovieStatus.seek);
setAndNoPublishSeek(room.currentMovieStatus.seek);
console.log("seek同步成功:", art.currentTime);

setAndNoPublishRate(room.currentMovieStatus.rate);
console.log("rate同步成功:", art.playbackRate);
room.currentMovieStatus.playing ? setAndNoPublishPlay() : setAndNoPublishPause();
cbk["sendDanmuku"]("PLAYER:视频已就绪");

intervals.push(setInterval(checkSeek, 5000));
});

Expand Down
7 changes: 7 additions & 0 deletions src/views/Cinema.vue
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,13 @@ const chatArea = ref();
function getPlayerInstance(art: Artplayer) {
player = art;
player.once("ready", () => {
syncPlugin.setAndNoPublishSeek(room.currentMovieStatus.seek);
syncPlugin.setAndNoPublishRate(room.currentMovieStatus.rate);
room.currentMovieStatus.playing
? syncPlugin.setAndNoPublishPlay()
: syncPlugin.setAndNoPublishPause();
});
}
// 设置聊天框高度
Expand Down

0 comments on commit 632b5f3

Please sign in to comment.