More logical syncronisation

This commit is contained in:
2021-12-31 00:55:07 +03:00
parent 2a348d1d21
commit 74793bb2d6
2 changed files with 4 additions and 5 deletions

View File

@@ -7,4 +7,5 @@ export interface Room {
downloaded?: boolean; downloaded?: boolean;
downloadedAt?: Date; downloadedAt?: Date;
position: number; position: number;
syncedAt: Date;
} }

View File

@@ -71,9 +71,8 @@ export default defineComponent({
this.positionInterval = setInterval(async () => { this.positionInterval = setInterval(async () => {
if (this.playing) { if (this.playing) {
const serverPosition = await getPosition(this.id); const serverPosition = await getPosition(this.id);
// this.room.position = element.currentTime; // console.log(`L: ${element.currentTime}; S: ${serverPosition}`);
if (Math.abs(this.room.position - serverPosition) > 2) { if (Math.abs(element.currentTime - serverPosition) > 2) {
this.room.position = serverPosition;
element.currentTime = serverPosition; element.currentTime = serverPosition;
console.log('Synced'); console.log('Synced');
} }
@@ -83,8 +82,7 @@ export default defineComponent({
}, },
seeked() { seeked() {
const element = this.$refs.video as HTMLVideoElement; const element = this.$refs.video as HTMLVideoElement;
const position = element.currentTime; setPosition(this.id, element.currentTime);
setPosition(this.id, position);
}, },
}, },
}); });