Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: no remove peers #16

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions src/p2pcf.js
Original file line number Diff line number Diff line change
Expand Up @@ -765,15 +765,6 @@ export default class P2PCF extends EventEmitter {
}
}
}

const remoteSessionIds = remotePeerDatas.map(p => p[0])

// Remove all peers no longer in the peer list.
// TODO deal with simple peer
for (const [sessionId, peer] of peers.entries()) {
if (remoteSessionIds.includes(sessionId)) continue
this._removePeer(peer, true)
}
}

/**
Expand Down
9 changes: 5 additions & 4 deletions src/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ async function handleGet (request, env) {
const hasStore = !!getStore(env)

return new Response(
`<html><body style="font-size: 24px; padding: 18px; font-family: Arial, sans-serif"">Hello from P2PCF<br/><div style=\"line-height: 28px; margin-top: 8px; font-size: 0.8em\">${
`<html><body style="font-size: 24px; padding: 18px; font-family: Arial, sans-serif"">Hello from P2PCF<br/><div style="line-height: 28px; margin-top: 8px; font-size: 0.8em">${
hasStore
? '&#128077; R2 bucket is configured properly, ready to serve.'
: '&#10060; Couldn\'t find a configured R2 bucket.<br/>Make sure you <a href="https://github.com/gfodor/p2pcf/blob/master/INSTALL.md#set-up-the-r2-bucket" target="_blank">created a bucket</a> and <a href="https://github.com/gfodor/p2pcf/blob/master/INSTALL.md#bind-the-worker-to-r2" target="_blank">connected the worker to it</a>.'
Expand Down Expand Up @@ -492,7 +492,7 @@ async function handlePost (request, env, context) {
) {
// Add a random delay and re-check to avoid stampede.
context.waitUntil(
new Promise(res => {
new Promise(resolve => {
setTimeout(async () => {
const now = new Date().getTime()
const nextVacuumEntry = await store.get(`rooms/${roomId}/next_vacuum`)
Expand Down Expand Up @@ -537,7 +537,7 @@ async function handlePost (request, env, context) {
)
}

res()
resolve()
}, Math.floor(Math.random() * 10 * 1000))
})
)
Expand Down Expand Up @@ -610,10 +610,11 @@ export default {
return handleOptions(request, env, context)
}

if (request.headers.get('content-type') !== 'application/json')
if (request.headers.get('content-type') !== 'application/json') {
return new Response('Expected content-type application/json', {
status: 400
})
}

if (
request.headers.get('x-worker-method') === 'DELETE' ||
Expand Down