{ "version": 3, "sources": ["src/app/meetings/services/active-meeting.service.ts"], "sourcesContent": ["import { Injectable } from '@angular/core';\nimport { ChannelService } from '@app/chat/services/channel.service';\nimport { ContactService } from '@app/contacts/services/contact.service';\nimport { WebsocketInit } from '@app/core/models/connection-status';\nimport { AppTranslateService } from '@app/core/services/app-translate.service';\nimport { WsService } from '@app/core/services/ws.service';\nimport { ActiveMeeting, AttendeeEvent, MeetingEvent, MeetingStartedEvent } from '@app/meetings/models/chime.models';\nimport { NotificationKeyBackend } from '@app/preferences/models/settings.models';\nimport { NotificationService } from '@app/preferences/services/notification.service';\nimport { BehaviorSubject } from 'rxjs';\n\nimport { ChimeMeetingService } from './chime-meeting.service';\n\n/**\n * Service for vending information about currently active meetings. Provided observable is a single\n * object where each key-value pair is a channel id mapping to an ActiveMeeting object.\n */\n@Injectable({\n providedIn: 'root',\n})\nexport class ActiveMeetingService implements WebsocketInit {\n public readonly activeMeetingSubject = new BehaviorSubject>(new Map());\n public readonly activeMeeting$ = this.activeMeetingSubject.asObservable();\n\n constructor(\n private webSocketService: WsService,\n private channelService: ChannelService,\n private contactService: ContactService,\n private notificationService: NotificationService,\n private chimeMeetingService: ChimeMeetingService,\n private appTranslateService: AppTranslateService\n ) {}\n\n bindSocketEvents() {\n this.webSocketService.socket.on('ActiveMeetings', (channelIds: string[]) => {\n // When the active meetings event occurs, merge with what we have in memory\n const currentActiveMeetings = this.activeMeetingSubject.getValue();\n const meetings = channelIds.map((channelId) => {\n return currentActiveMeetings.get(channelId) || ({ channelId, memberIds: new Set() } as ActiveMeeting);\n });\n\n const meetingMap = new Map();\n for (const meeting of meetings) {\n meetingMap.set(meeting.channelId, meeting);\n }\n this.activeMeetingSubject.next(meetingMap);\n });\n\n this.webSocketService.socket.on(\n 'UsersInMeeting',\n ({ channelId, userIds }: { channelId: string; userIds: string[] }) => {\n const meetingMap = this.activeMeetingSubject.getValue();\n const meeting = meetingMap.get(channelId);\n if (meeting) {\n meetingMap.set(channelId, { ...meeting, memberIds: new Set(userIds) });\n this.activeMeetingSubject.next(meetingMap);\n }\n }\n );\n\n this.webSocketService.socket.on('MeetingStarted', ({ channelId, createdBy }: MeetingStartedEvent) => {\n const meetingMap = this.activeMeetingSubject.getValue();\n if (!meetingMap.get(channelId)) {\n meetingMap.set(channelId, { channelId, memberIds: new Set() });\n this.activeMeetingSubject.next(meetingMap);\n\n // Play sound effect if the meeting was started by a different user and\n // the channelId is for a conversation we have stored.\n const userStartedMeeting = createdBy === this.contactService.currentUser?.id;\n if (!userStartedMeeting && this.channelService.getCachedChannelWithId(channelId)) {\n const contact = this.contactService.contactById(createdBy);\n const title = this.appTranslateService.instant('MEETINGS.INVITATION_NOTIFICATION', {\n inviterName: contact?.fullName ? ` by ${contact.fullName}` : '',\n });\n this.notificationService.showNotification(\n { title: title, body: 'Meeting Started' },\n NotificationKeyBackend['Group Chat Meeting Started'],\n false,\n () => {\n // Open the meeting if the user clicks on the notification\n const channelArn = this.channelService\n .getData()\n .find((channel) => channel.channelArn.includes(channelId))?.channelArn;\n if (channelArn) {\n this.chimeMeetingService.startMeeting(channelArn).then();\n }\n }\n );\n }\n }\n });\n\n this.webSocketService.socket.on('AttendeeJoined', ({ channelId, userId }: AttendeeEvent) => {\n const meetingMap = this.activeMeetingSubject.getValue();\n const meeting = meetingMap.get(channelId);\n if (meeting) {\n meeting.memberIds.add(userId);\n } else {\n meetingMap.set(channelId, { channelId, memberIds: new Set([userId]) });\n }\n const userJoinedMeeting = userId === this.contactService.currentUser?.id;\n if (!userJoinedMeeting && this.channelService.getCachedChannelWithId(channelId)) {\n const contact = this.contactService.contactById(userId);\n const title = this.appTranslateService.instant('MEETINGS.JOINED_NOTIFICATION', {\n joinedName: contact ? contact.fullName : this.appTranslateService.instant('MEETINGS.SOMEONE'),\n });\n this.notificationService.showNotification(\n { title: title, body: 'Meeting Joined' },\n NotificationKeyBackend['Someone Joins a Group Chat Meeting'],\n false,\n () => {\n const channelArn = this.channelService\n .getData()\n .find((channel) => channel.channelArn.includes(channelId))?.channelArn;\n if (channelArn) {\n this.chimeMeetingService.startMeeting(channelArn).then();\n }\n }\n );\n }\n this.activeMeetingSubject.next(meetingMap);\n });\n\n this.webSocketService.socket.on('AttendeeLeft', ({ channelId, userId }: AttendeeEvent) => {\n const meetingMap = this.activeMeetingSubject.getValue();\n const meeting = meetingMap.get(channelId);\n if (meeting) {\n meeting.memberIds.delete(userId);\n if (meeting.memberIds.size === 0) {\n meetingMap.delete(channelId);\n }\n this.activeMeetingSubject.next(meetingMap);\n }\n });\n\n this.webSocketService.socket.on('MeetingEnded', ({ channelId }: MeetingEvent) => {\n const meetingMap = this.activeMeetingSubject.getValue();\n const meeting = meetingMap.get(channelId);\n if (meeting) {\n meetingMap.delete(channelId);\n this.activeMeetingSubject.next(meetingMap);\n }\n });\n }\n\n public activeMeetingForChannelArn(channelArn: string): ActiveMeeting | undefined {\n const channelId = channelArn.split('/').pop();\n return channelId ? this.activeMeetingSubject.getValue().get(channelId) : undefined;\n }\n}\n"], "mappings": "4NAoBA,IAAaA,GAAoB,IAAA,CAA3B,MAAOA,CAAoB,CAI/BC,YACUC,EACAC,EACAC,EACAC,EACAC,EACAC,EAAwC,CALxC,KAAAL,iBAAAA,EACA,KAAAC,eAAAA,EACA,KAAAC,eAAAA,EACA,KAAAC,oBAAAA,EACA,KAAAC,oBAAAA,EACA,KAAAC,oBAAAA,EATM,KAAAC,qBAAuB,IAAIC,EAA4C,IAAIC,GAAK,EAChF,KAAAC,eAAiB,KAAKH,qBAAqBI,aAAY,CASpE,CAEHC,kBAAgB,CACd,KAAKX,iBAAiBY,OAAOC,GAAG,iBAAmBC,GAAwB,CAEzE,IAAMC,EAAwB,KAAKT,qBAAqBU,SAAQ,EAC1DC,EAAWH,EAAWI,IAAKC,GACxBJ,EAAsBK,IAAID,CAAS,GAAM,CAAEA,UAAAA,EAAWE,UAAW,IAAIC,GAAK,CAClF,EAEKC,EAAa,IAAIf,IACvB,QAAWgB,KAAWP,EACpBM,EAA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8B,OAAOlC,CAAS,EAE7B,KAAKb,qBAAqBoB,KAAKH,CAAU,EAE7C,CAAC,EAED,KAAKvB,iBAAiBY,OAAOC,GAAG,eAAgB,CAAC,CAAEM,UAAAA,CAAS,IAAoB,CAC9E,IAAMI,EAAa,KAAKjB,qBAAqBU,SAAQ,EACrCO,EAAWH,IAAID,CAAS,IAEtCI,EAAW8B,OAAOlC,CAAS,EAC3B,KAAKb,qBAAqBoB,KAAKH,CAAU,EAE7C,CAAC,CACH,CAEOgC,2BAA2BZ,EAAkB,CAClD,IAAMxB,EAAYwB,EAAWa,MAAM,GAAG,EAAEC,IAAG,EAC3C,OAAOtC,EAAY,KAAKb,qBAAqBU,SAAQ,EAAGI,IAAID,CAAS,EAAIuC,MAC3E,iDAhIW5D,GAAoB6D,EAAAC,CAAA,EAAAD,EAAAE,CAAA,EAAAF,EAAAG,CAAA,EAAAH,EAAAI,CAAA,EAAAJ,EAAAK,CAAA,EAAAL,EAAAM,CAAA,CAAA,CAAA,CAAA,iCAApBnE,EAAoBoE,QAApBpE,EAAoBqE,UAAAC,WAFnB,MAAM,CAAA,CAAA,SAEPtE,CAAoB,GAAA", "names": ["ActiveMeetingService", "constructor", "webSocketService", "channelService", "contactService", "notificationService", "chimeMeetingService", "appTranslateService", "activeMeetingSubject", "BehaviorSubject", "Map", "activeMeeting$", "asObservable", "bindSocketEvents", "socket", "on", "channelIds", "currentActiveMeetings", "getValue", "meetings", "map", "channelId", "get", "memberIds", "Set", "meetingMap", "meeting", "set", "next", "userIds", "__spreadProps", "__spreadValues", "createdBy", "currentUser", "id", "getCachedChannelWithId", "contact", "contactById", "title", "instant", "inviterName", "fullName", "showNotification", "body", "NotificationKeyBackend", "channelArn", "getData", "find", "channel", "includes", "startMeeting", "then", "userId", "add", "joinedName", "delete", "size", "activeMeetingForChannelArn", "split", "pop", "undefined", "\u0275\u0275inject", "WsService", "ChannelService", "ContactService", "NotificationService", "ChimeMeetingService", "AppTranslateService", "factory", "\u0275fac", "providedIn"] }