Skip to content

Commit

Permalink
fix : fix bug room members is mixed
Browse files Browse the repository at this point in the history
  • Loading branch information
nuzulul committed Jun 24, 2024
1 parent 330d45e commit 521db2c
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 170 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "webpeerjs",
"version": "0.1.0",
"version": "0.1.1",
"description": "Simple peer-to-peer with IPFS",
"main": "./dist/umd/webpeerjs.js",
"module": "./src/webpeerjs.js",
Expand Down
21 changes: 13 additions & 8 deletions src/webpeerjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,13 +327,18 @@ class webpeerjs{
}

if(rooms){
for(const room of Object.keys(this.#rooms)){
//update room members
if(!this.#rooms[room].members.includes(id)){
if(this.#connectedPeers.has(id)){
this.#rooms[room].members.push(id)
this.#rooms[room].onMembers(this.#rooms[room].members)
for(const room of rooms){

if(this.#rooms[room]){

//update room members
if(!this.#rooms[room].members.includes(id)){
if(this.#connectedPeers.has(id)){
this.#rooms[room].members.push(id)
this.#rooms[room].onMembers(this.#rooms[room].members)
}
}

}
}
}
Expand Down Expand Up @@ -1072,7 +1077,7 @@ class webpeerjs{
//announce and ping via pupsub peer discovery
async #announce(){
const topics = config.CONFIG_PUPSUB_PEER_DATA
const data = JSON.stringify({prefix:config.CONFIG_PREFIX,signal:'announce',id:this.#libp2p.peerId.toString(),address:this.address,rooms:this.#rooms})
const data = JSON.stringify({prefix:config.CONFIG_PREFIX,signal:'announce',id:this.#libp2p.peerId.toString(),address:this.address,rooms:Object.keys(this.#rooms)})
const peer = {
publicKey: this.#libp2p.peerId.publicKey,
addrs: [uint8ArrayFromString(data)],
Expand All @@ -1084,7 +1089,7 @@ class webpeerjs{
}
async #ping(){
const topics = config.CONFIG_PUPSUB_PEER_DATA
const data = JSON.stringify({prefix:config.CONFIG_PREFIX,signal:'ping',id:this.#libp2p.peerId.toString(),address:this.address,rooms:this.#rooms})
const data = JSON.stringify({prefix:config.CONFIG_PREFIX,signal:'ping',id:this.#libp2p.peerId.toString(),address:this.address,rooms:Object.keys(this.#rooms)})
const peer = {
publicKey: this.#libp2p.peerId.publicKey,
addrs: [uint8ArrayFromString(data)],
Expand Down
24 changes: 0 additions & 24 deletions test/project/.gitignore

This file was deleted.

9 changes: 0 additions & 9 deletions test/project/counter.js

This file was deleted.

44 changes: 39 additions & 5 deletions test/project/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,46 @@
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite App</title>
<title>WebpeerJS</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/main.js"></script>
<h3>Basic Connection Demo of <a href="https://github.com/nuzulul/webpeerjs">WebpeerJS</a></h3>
<div id="app"><ul id="myList"></ul></div>

<script type="module">

import { webpeerjs } from 'webpeerjs'

void async function main() {

function write(input){
const node = document.createElement("li")
const textnode = document.createTextNode(input)
node.appendChild(textnode)
document.getElementById("myList").appendChild(node)
}

const node = await webpeerjs.createWebpeer()

write(`My node id : ${node.id}`)

const room = 'myroom'

write(`joinRoom : ${room}`)

const [broadcast,listen,members] = node.joinRoom(room)

listen((message,id) => {
write(`Message from ${id} : ${message}`)
})

members((data) => {
write(`Members update : ${data}`)
broadcast('hello')
})

}()
</script>
</body>
</html>
</html>
1 change: 0 additions & 1 deletion test/project/javascript.svg

This file was deleted.

25 changes: 0 additions & 25 deletions test/project/main.js

This file was deleted.

1 change: 0 additions & 1 deletion test/project/public/vite.svg

This file was deleted.

96 changes: 0 additions & 96 deletions test/project/style.css

This file was deleted.

0 comments on commit 521db2c

Please sign in to comment.