Skip to content
Open
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
20 changes: 12 additions & 8 deletions src/comp/util/WebrtcProvider.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
try {
// Subscribe to a remote user.
await client.subscribe(user, mediaType)
} catch (_e) {
} catch {
return
}

Expand All @@ -118,7 +118,7 @@
}
try {
await client.unsubscribe(user, mediaType)
} catch (_e) {}
} catch {}
})

const rtcToken = await getAgoraToken(roomId)
Expand Down Expand Up @@ -154,7 +154,7 @@
$joining = false
try {
await client!.leave()
} catch (_e) {
} catch {
return false
}
return false
Expand Down Expand Up @@ -185,12 +185,16 @@
}
}
if ($outgoing) {
await client.unpublish([$outgoing])
$outgoing.stop()
$outgoing.close()
$outgoing = null
try {
await client.unpublish([$outgoing])
} catch {}
}
await client.leave()
$outgoing?.stop()
$outgoing?.close()
$outgoing = null
try {
await client.leave()
} catch {}
$joinedRoom = null
return unsubscribedFromAllRemoteUsers
}
Expand Down
8 changes: 4 additions & 4 deletions src/routes/_layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@
</script>

<LocaleProvider {segment}>
<WebrtcProvider>
<ChatProvider>
<ChatProvider>
<WebrtcProvider>
<div id="app" class:noscroll class:with-main-nav={showMainNav}>
{#if showMainNav}
<MainNav {segment} />
Expand All @@ -88,8 +88,8 @@
{/key}
</main>
</div>
</ChatProvider>
</WebrtcProvider>
</WebrtcProvider>
</ChatProvider>
</LocaleProvider>

<style>
Expand Down
6 changes: 4 additions & 2 deletions src/routes/chat.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@

if (fetchGroupMetadataInterval === null) {
const FETCH_GROUP_METADATA_INTERVAL_SECS = 30
fetchGroupMetadataInterval = setInterval(
fetchGroupMetadataInterval = window.setInterval(
() => fetchGroupMetadata({ groupUuid: $groupUuid }),
FETCH_GROUP_METADATA_INTERVAL_SECS * 1000
)
Expand Down Expand Up @@ -360,7 +360,9 @@

function handleBeforeunload(): void {
if ($joinedCallRoom) {
chat.emit("userLeaveCall", { groupUuid: $joinedCallRoom })
chat.emit("userLeaveCall", {
groupUuid: $joinedCallRoom,
})
}
chat.leaveRoom()
chat.disconnect()
Expand Down
2 changes: 2 additions & 0 deletions src/server/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ export async function authenticateUserInGroup(
.debug("Group doesn't exist or user is not part of group")
return false
}

return true
}
35 changes: 22 additions & 13 deletions src/server/socket/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function handleUserConnected(io: SocketIO, socket: EverglotChatSocket) {
.error("Failed to get group call user metadata")
return
}
if (!authenticateUserInGroup(userId, groupUuid)) {
if (!(await authenticateUserInGroup(userId, groupUuid))) {
chlog
.child({ userId, groupUuid })
.debug("User is not in group but tried to join call")
Expand All @@ -49,13 +49,15 @@ export function handleUserConnected(io: SocketIO, socket: EverglotChatSocket) {
.error("Failed to get group call user metadata")
return
}
if (!authenticateUserInGroup(userId, groupUuid)) {
chlog
.child({ userId, groupUuid, userMeta })
.debug("User is not in group but tried to leave call")
return
if (groupUuid !== null) {
if (!(await authenticateUserInGroup(userId, groupUuid))) {
chlog
.child({ userId, groupUuid, userMeta })
.debug("User is not in group but tried to leave call")
return
}
}
const userLeaving = userLeave(userMeta.uuid, groupUuid)
const userLeaving = userLeave(userMeta.uuid, groupUuid as string)
if (!userLeaving) {
chlog
.child({ userId, groupUuid, userMeta })
Expand Down Expand Up @@ -88,7 +90,7 @@ export function handleUserConnected(io: SocketIO, socket: EverglotChatSocket) {
return
}
const { uuid: userUuid } = userMeta
if (!authenticateUserInGroup(userId, groupUuid)) {
if (!(await authenticateUserInGroup(userId, groupUuid))) {
chlog
.child({ userId, userUuid, groupUuid })
.debug("User is not in group but tried to join call")
Expand Down Expand Up @@ -159,19 +161,26 @@ function userLeave(userUuid: string, groupUuid: string) {

if (!existingUser) {
chlog
.child({ userUuid, groupUuid })
.child({ userUuid, groupUuid, users })
.debug("User is not in group call, preventing leave")
return false
}
if (existingUser.groupUuid !== groupUuid) {
chlog
.child({ userUuid, groupUuid, existingUser })
.debug(
"User is leaving group call but for a different group than the one in whose call they are. " +
"We're letting them leave that call anyways."
groupUuid === null
? "User is leaving group call but they didn't say which group that call was in." +
"We're letting them leave that call anyways."
: "User is leaving group call but for a different group than the one in whose call they are. " +
"We're letting them leave that call anyways."
)
}
return users.splice(index, 1)[0]
const removedUser = users.splice(index, 1)[0]
chlog
.child({ userUuid, groupUuid, removedUser, users })
.debug("Successfully removed user from voice call")
return removedUser
}

function userUpdateMeta(
Expand All @@ -187,7 +196,7 @@ function userUpdateMeta(
if (index === -1) {
chlog
.child({ userUuid, groupUuid })
.debug("User is not in group call, preventing leave")
.debug("User is not in group call, preventing call meta update")
return false
} else {
users[index] = {
Expand Down
8 changes: 6 additions & 2 deletions src/server/socket/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,14 @@ export function start(server: Server, pool: Pool) {
const userId = session.user_id
const userMeta = await getChatUserByUserId(userId)
if (!userMeta) {
chlog.child({ userId }).warn("Failed to retrieve user meta")
return
}

if (!authenticateUserInGroup(userId, groupUuid)) {
if (!(await authenticateUserInGroup(userId, groupUuid))) {
chlog
.child({ userId, groupUuid })
.debug("User is not authorized to join this group")
return
}

Expand Down Expand Up @@ -111,7 +115,7 @@ export function start(server: Server, pool: Pool) {
}
const { uuid: userUuid } = userMeta

if (!authenticateUserInGroup(userId, groupUuid)) {
if (!(await authenticateUserInGroup(userId, groupUuid))) {
return
}

Expand Down