socket
socket copied to clipboard
P2P not working in vue app
Vue js app with P2P not working..
i have build application with v0.3.3 with vue.js it is loading fine in both Desktop (ubuntu) and mobile but communication not happening between two devices.
I have uploaded my code for your review, https://github.com/gowram/sscvue
@heapwolf please, let me know what is missing here....
@gowram please point to a repo or a gist. No one will open a zip file.
- @heapwolf create git repo... https://github.com/gowram/sscvue
team, any update on this? I would like to know what is missing from my setup...
<script setup>
import { Peer } from 'socket:peer'
import { ref, onMounted } from 'vue'
onMounted(async () => {
const pair = await Peer.createKeys()
const clusterId = await Peer.createClusterId()
peer = new Peer({ ...pair, clusterId })
peer.join()
peer.on('greeting', (data, ppr, address, port) => {
clr.value = "color = " + data.color;
if (peer.peer.address !== ppr) {
console.log('remote on...')
}
setColor(data.color)
})
})
defineProps({
msg: String,
})
const count = ref(0)
let peer = ref("")
let ip = ref("loading....")
let clr = ref("black")
const setColor = c => document.body.style.backgroundColor = `#${c}`
function setBgColor() {
const color = Math.floor(Math.random() * 16777215).toString(16)
peer.emit('greeting', {
'color': color,
'timestamp': Date.now()
})
setColor(color);
ip.value = peer?.peer?.address
}
</script>
<template>
<h1>{{ msg }}</h1>
<h2>{{ ip }}</h2>
<h3>{{ clr }}</h3>
<div class="card">
<button type="button" @click="setBgColor">Change Color</button>
</div>
</template>
<style scoped>
.read-the-docs {
color: #888;
}
</style>`
Try using the same clusterId and key pair between devices that you want to connect.
@RGBboy I tried with same clusterId and keypair between devices, Still it's not working..
peer.on itself not getting listened, if i use same clusterId and keypair.
is there any documentation available?
Just to add to this, also trying to set up a demo. Not using vue but in vanilla js I'm not seeing theawait peer.join()
function ever return. I'm using a shared clusterId. I'm not sure why I would use the same keypair on the two clients. Testing between a Mac and iPhone on the same network.
Source code is at https://github.com/sheldonth/perchd/blob/main/src/index.js if anyone can help. Much appreciated.
today's merge will add the fix to main branch
@heapwolf is there any update on this issue?
Was this fixed?
Was this fixed?
not yet