-
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
11 changed files
with
426 additions
and
139 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
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,24 @@ | ||
<template> | ||
<div> | ||
<h2>Receiver Component {{ peerid }}</h2> | ||
<p v-if="fileReceived">{{ fileReceived.name }} received successfully!</p> | ||
<b v-if="messageReceived">{{ messageReceived }}</b> | ||
</div> | ||
</template> | ||
<script setup> | ||
import { ref, onMounted } from "vue"; | ||
const fileReceived = ref(null); | ||
const messageReceived = ref(""); | ||
const peer = useNuxtApp().$peer; | ||
const peerid = useNuxtApp().$peerid; | ||
onMounted(() => { | ||
peer.on("connection", (conn) => { | ||
conn.on("data", (data) => { | ||
messageReceived.value = data; | ||
}); | ||
}); | ||
}); | ||
</script> |
This file was deleted.
Oops, something went wrong.
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,48 @@ | ||
<template> | ||
<div> | ||
<h2>Simple Peer Messenger</h2> | ||
<p v-if="messageReceived">{{ messageReceived }}</p> | ||
|
||
<input v-model="messageToSend" /> | ||
<button @click="sendMessage">Send Message</button> | ||
</div> | ||
</template> | ||
|
||
<script setup> | ||
import { ref, onMounted } from "vue"; | ||
import SimplePeer from "simple-peer"; | ||
const messageReceived = ref(null); | ||
const messageToSend = ref(""); | ||
let peer; | ||
onMounted(() => { | ||
peer = new SimplePeer({ initiator: true, trickle: false }); | ||
peer.on("data", (data) => { | ||
// Handle received data | ||
if (typeof data === "string") { | ||
messageReceived.value = data; | ||
} else { | ||
// Handle other types of data if needed | ||
} | ||
}); | ||
}); | ||
const sendMessage = () => { | ||
if (peer) { | ||
peer.send(messageToSend.value); | ||
} else { | ||
// Create a new peer if it doesn't exist | ||
peer = new SimplePeer({ trickle: false }); | ||
peer.on("data", (data) => { | ||
// Handle received data | ||
if (typeof data === "string") { | ||
messageReceived.value = data; | ||
} else { | ||
// Handle other types of data if needed | ||
} | ||
}); | ||
} | ||
}; | ||
</script> |
This file was deleted.
Oops, something went wrong.
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,16 @@ | ||
import Peer from "peerjs"; | ||
import { | ||
uniqueNamesGenerator, | ||
starWars, | ||
adjectives, | ||
} from "unique-names-generator"; | ||
|
||
export default defineNuxtPlugin((nuxtApp) => { | ||
const peerid = uniqueNamesGenerator({ | ||
dictionaries: [adjectives, starWars], | ||
}).replace(/\s/g, ""); | ||
const peer = new Peer(peerid, {}); | ||
console.log(peer, peerid); | ||
nuxtApp.provide("peer", peer); | ||
nuxtApp.provide("peerid", peerid); | ||
}); |
Oops, something went wrong.