-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
312 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<template> | ||
<div> | ||
<h1>Peer Chat</h1> | ||
<button @click="initPeer">Start Chat</button> | ||
<div v-if="peerId">Your Peer ID: {{ peerId }}</div> | ||
<div v-if="message">Received Message: {{ message }}</div> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import SimplePeer from "simple-peer"; | ||
export default { | ||
data () { | ||
return { | ||
peerId: null, | ||
message: null, | ||
peer: null, | ||
}; | ||
}, | ||
methods: { | ||
initPeer () { | ||
this.peer = new SimplePeer({ initiator: location.hash === "#init" }); | ||
this.peer.on("signal", (data) => { | ||
console.log("My signal:", data); | ||
// Share this signal with the other peer using your signaling mechanism | ||
// (e.g., local storage, database) | ||
}); | ||
this.peer.on("data", (data) => { | ||
this.message = data.toString(); | ||
}); | ||
// Listen for incoming signals from the other peer | ||
// (This would typically happen in another component/page) | ||
window.addEventListener("peerSignal", (event) => { | ||
this.peer.signal(event.detail); | ||
}); | ||
this.peerId = this.peer.id; | ||
}, | ||
}, | ||
}; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.