Skip to content

Commit

Permalink
Fix double meeting initialization (#7256)
Browse files Browse the repository at this point in the history
Signed-off-by: Kristina Fefelova <[email protected]>
  • Loading branch information
kristina-fefelova authored Dec 3, 2024
1 parent 6af28c9 commit 6d31873
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 29 deletions.
10 changes: 8 additions & 2 deletions plugins/love-resources/src/components/EditRoom.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,13 @@
connectLabel = love.string.StartMeeting
}
function showConnectionButton (object: Room, isConnected: boolean, myOffice?: Room, currentRoom?: Room): boolean {
function showConnectionButton (
object: Room,
connecting: boolean,
isConnected: boolean,
myOffice?: Room,
currentRoom?: Room
): boolean {
// Do not show connect button in my office
if (object._id === myOffice?._id) return false
// Show during connecting with spinner
Expand All @@ -98,7 +104,7 @@
focusIndex={1}
/>
</div>
{#if showConnectionButton(object, $isConnected, $myOffice, $currentRoom)}
{#if showConnectionButton(object, connecting, $isConnected, $myOffice, $currentRoom)}
<ModernButton label={connectLabel} size="large" kind={'primary'} on:click={connect} loading={connecting} />
{/if}
</div>
Expand Down
52 changes: 25 additions & 27 deletions plugins/love-resources/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,16 +374,12 @@ lk.on(RoomEvent.RecordingStatusChanged, (evt) => {
isRecording.set(evt)
})
lk.on(RoomEvent.RoomMetadataChanged, (metadata) => {
try {
const data = JSON.parse(metadata) as RoomMetadata
if (data.recording !== undefined) {
isRecording.set(data.recording)
}
if (data.transcription !== undefined) {
isTranscription.set(data.transcription === TranscriptionStatus.InProgress)
}
} catch (err: any) {
Analytics.handleError(err)
const data = parseMetadata(metadata)
if (data.recording !== undefined) {
isRecording.set(data.recording)
}
if (data.transcription !== undefined) {
isTranscription.set(data.transcription === TranscriptionStatus.InProgress)
}
})

Expand All @@ -392,7 +388,7 @@ lk.on(RoomEvent.Connected, () => {
sendMessage({ type: 'connect', value: true })
isCurrentInstanceConnected.set(true)
isRecording.set(lk.isRecording)
void initRoomMetadata(lk.metadata)
void initRoom()
Analytics.handleEvent(LoveEvents.ConnectedToRoom)
})
lk.on(RoomEvent.Disconnected, () => {
Expand All @@ -402,25 +398,19 @@ lk.on(RoomEvent.Disconnected, () => {
Analytics.handleEvent(LoveEvents.DisconnectedFromRoom)
})

async function initRoomMetadata (metadata: string | undefined): Promise<void> {
let data: RoomMetadata
try {
data = metadata == null || metadata === '' ? {} : JSON.parse(metadata)
} catch (err: any) {
data = {}
Analytics.handleError(err)
async function initRoom (): Promise<void> {
const room = get(currentRoom)
if (room !== undefined) {
await initMeetingMinutes(room)
}
await initRoomMetadata(lk.metadata)
}

isTranscription.set(data.transcription === TranscriptionStatus.InProgress)

async function initRoomMetadata (metadata: string | undefined): Promise<void> {
const room = get(currentRoom)
const meetingMinutes = get(currentMeetingMinutes)
const isValidMeeting =
meetingMinutes != null && meetingMinutes.attachedTo === room?._id && meetingMinutes.status === MeetingStatus.Active
const data: RoomMetadata = parseMetadata(metadata)

if (room != null && !isValidMeeting) {
await initMeetingMinutes(room)
}
isTranscription.set(data.transcription === TranscriptionStatus.InProgress)

if (
(data.transcription == null || data.transcription === TranscriptionStatus.Idle) &&
Expand All @@ -434,6 +424,15 @@ async function initRoomMetadata (metadata: string | undefined): Promise<void> {
}
}

function parseMetadata (metadata: string | undefined): RoomMetadata {
try {
return metadata == null || metadata === '' ? {} : JSON.parse(metadata)
} catch (err: any) {
Analytics.handleError(err)
return {}
}
}

async function withRetries (fn: () => Promise<void>, retries: number, delay: number): Promise<void> {
for (let attempt = 0; attempt < retries; attempt++) {
try {
Expand Down Expand Up @@ -738,7 +737,6 @@ export async function connectRoom (
3,
1000
)
await initMeetingMinutes(room)
} catch (err) {
console.error(err)
await leaveRoom(currentInfo, get(myOffice))
Expand Down

0 comments on commit 6d31873

Please sign in to comment.