From 09dc6712161ba2efdb8c812e3077e38907cec94e Mon Sep 17 00:00:00 2001 From: kura Date: Fri, 3 Jan 2025 10:53:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=8B=E5=8A=A8=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/file/index.vue | 1 + src/pages/file/utils/peer.ts | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/pages/file/index.vue b/src/pages/file/index.vue index afa812e..23af141 100644 --- a/src/pages/file/index.vue +++ b/src/pages/file/index.vue @@ -188,6 +188,7 @@ const handleReceive = async () => { }; // 事件监听 onMounted(() => { + peer.init(); peer.on("open", ((event: CustomEvent) => { myId.value = event.detail; const sign = getUrlParam("sign"); diff --git a/src/pages/file/utils/peer.ts b/src/pages/file/utils/peer.ts index 4c211c2..8c6b484 100644 --- a/src/pages/file/utils/peer.ts +++ b/src/pages/file/utils/peer.ts @@ -21,7 +21,9 @@ class Peer extends EventTarget { constructor(sign: string) { super() this.sign = sign - this.peer = new PeerJs(sign2peerid(sign)) + } + public init() { + this.peer = new PeerJs(sign2peerid(this.sign)) this.peer.on('open', (id) => { console.log('peer open', id) this.id = id