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