|
@@ -15,20 +15,27 @@
|
|
|
<div class="trail-videos">
|
|
|
<video-obj
|
|
|
v-for="item in videoList"
|
|
|
- :key="item.id"
|
|
|
- :stream="ws"
|
|
|
+ :key="item.key"
|
|
|
+ :stream="item.video.liveStream"
|
|
|
:lastTime="0"
|
|
|
/>
|
|
|
</div>
|
|
|
</div>
|
|
|
+ <socket-message
|
|
|
+ v-if="this.fingerprint.visitorId"
|
|
|
+ :onMessage="onMessage"
|
|
|
+ :ws="`/pkb/uwb/trail?client=${this.fingerprint.visitorId}&deviceId=${deviceId}`"
|
|
|
+ />
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
import VideoObj from "@/components/Video/index.vue";
|
|
|
+import SocketMessage from "@/components/WebsocketMessage/index.vue";
|
|
|
+import FingerprintJS from "@fingerprintjs/fingerprintjs";
|
|
|
|
|
|
export default {
|
|
|
- components: {VideoObj},
|
|
|
+ components: {SocketMessage, VideoObj},
|
|
|
name: "video-trail",
|
|
|
props: {
|
|
|
ws: {
|
|
@@ -43,14 +50,22 @@ export default {
|
|
|
},
|
|
|
data() {
|
|
|
return {
|
|
|
- videoList: []
|
|
|
+ videoList: [],
|
|
|
+ fingerprint: "",
|
|
|
+ deviceId: "845D3",
|
|
|
+ timer: null // 新增定时器变量
|
|
|
};
|
|
|
},
|
|
|
// 组件卸载前清空图层信息
|
|
|
beforeDestroy() {
|
|
|
+ if (this.timer) {
|
|
|
+ clearInterval(this.timer); // 清除定时器
|
|
|
+ }
|
|
|
},
|
|
|
created() {
|
|
|
-
|
|
|
+ this.getBrowserFingerprint();
|
|
|
+ this.removeOldVideos(); // 添加调用
|
|
|
+ this.timer = setInterval(this.removeOldVideos, 60000); // 每分钟调用一次,并将定时器赋值给timer变量
|
|
|
},
|
|
|
mounted() {
|
|
|
this.init();
|
|
@@ -59,21 +74,29 @@ export default {
|
|
|
init() {
|
|
|
|
|
|
},
|
|
|
- updateVideoList(newVideo) {
|
|
|
- const videoIndex = this.videoList.findIndex(video => video.id === newVideo.id);
|
|
|
+ onMessage(newVideo) {
|
|
|
+ const {msg: video} = newVideo
|
|
|
+ video.srcTimestamp = Date.now();
|
|
|
+ video.key = `${video.key}_${video.fenceId}`;
|
|
|
+ const videoIndex = this.videoList.findIndex(item => item.key === video.key);
|
|
|
if (videoIndex !== -1) {
|
|
|
this.videoList.splice(videoIndex, 1);
|
|
|
}
|
|
|
- this.videoList.unshift(newVideo);
|
|
|
-
|
|
|
- // 删除超过20分钟的视频
|
|
|
+ this.videoList.unshift(video);
|
|
|
+ },
|
|
|
+ removeOldVideos() {
|
|
|
const currentTime = Date.now();
|
|
|
- while (this.videoList.length > 0 && (currentTime - this.videoList[this.videoList.length - 1].timestamp) > 20 * 60 * 1000) {
|
|
|
+ while (this.videoList.length > 0 && (currentTime - this.videoList[this.videoList.length - 1].srcTimestamp) > 20 * 60 * 1000) {
|
|
|
this.videoList.pop();
|
|
|
}
|
|
|
},
|
|
|
- onMessage() {
|
|
|
-
|
|
|
+ async getBrowserFingerprint() {
|
|
|
+ try {
|
|
|
+ const fp = await FingerprintJS.load();
|
|
|
+ this.fingerprint = await fp.get();
|
|
|
+ } catch (error) {
|
|
|
+ console.error('Error loading fingerprint generator:', error);
|
|
|
+ }
|
|
|
},
|
|
|
},
|
|
|
};
|