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 double meeting initialisation #7256

Merged
merged 1 commit into from
Dec 3, 2024
Merged
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
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
Loading