Skip to content

Commit

Permalink
fix invite-api for async rpc methods
Browse files Browse the repository at this point in the history
  • Loading branch information
gmaclennan committed Oct 25, 2023
1 parent 1c292f5 commit 7ec98af
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
18 changes: 9 additions & 9 deletions src/invite-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export class InviteApi extends TypedEmitter {

if (isAlreadyMember) {
for (const peerId of peersToRespondTo) {
this.#sendAlreadyResponse({ peerId, projectId })
await this.#sendAlreadyResponse({ peerId, projectId })
}
return
}
Expand All @@ -123,7 +123,7 @@ export class InviteApi extends TypedEmitter {
}

try {
this.#sendAcceptResponse({
await this.#sendAcceptResponse({
peerId: pendingInvite.fromPeerId,
projectId,
})
Expand Down Expand Up @@ -162,7 +162,7 @@ export class InviteApi extends TypedEmitter {
)
}
for (const peerId of this.#peersToRespondTo.get(projectId)) {
this.#sendRejectResponse({ peerId, projectId })
await this.#sendRejectResponse({ peerId, projectId })
}
}

Expand All @@ -171,9 +171,9 @@ export class InviteApi extends TypedEmitter {
*
* @param {{ peerId: string, projectId: string }} opts
*/
#sendAcceptResponse({ peerId, projectId }) {
async #sendAcceptResponse({ peerId, projectId }) {
const projectKey = Buffer.from(projectId, 'hex')
this.rpc.inviteResponse(peerId, {
await this.rpc.inviteResponse(peerId, {
projectKey,
decision: InviteResponse_Decision.ACCEPT,
})
Expand All @@ -184,10 +184,10 @@ export class InviteApi extends TypedEmitter {
*
* @param {{ peerId: string, projectId: string }} opts
*/
#sendAlreadyResponse({ peerId, projectId }) {
async #sendAlreadyResponse({ peerId, projectId }) {
const projectKey = Buffer.from(projectId, 'hex')
try {
this.rpc.inviteResponse(peerId, {
await this.rpc.inviteResponse(peerId, {
projectKey,
decision: InviteResponse_Decision.ALREADY,
})
Expand All @@ -202,10 +202,10 @@ export class InviteApi extends TypedEmitter {
*
* @param {{ peerId: string, projectId: string }} opts
*/
#sendRejectResponse({ peerId, projectId }) {
async #sendRejectResponse({ peerId, projectId }) {
const projectKey = Buffer.from(projectId, 'hex')
try {
this.rpc.inviteResponse(peerId, {
await this.rpc.inviteResponse(peerId, {
projectKey,
decision: InviteResponse_Decision.REJECT,
})
Expand Down
1 change: 0 additions & 1 deletion tests/invite-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,6 @@ test('invitor disconnecting results in accept throwing', async (t) => {

r1.on('peers', async (peers) => {
if (peers.length !== 1 || peers[0].status === 'disconnected') return

await t.exception(() => {
return r1.invite(peers[0].id, {
projectKey,
Expand Down

0 comments on commit 7ec98af

Please sign in to comment.