diff --git a/mail_livekit/models/mail_rtc_session.py b/mail_livekit/models/mail_rtc_session.py index fdd553fd..3cda2704 100644 --- a/mail_livekit/models/mail_rtc_session.py +++ b/mail_livekit/models/mail_rtc_session.py @@ -1,6 +1,7 @@ from livekit.api import AccessToken, VideoGrants -from odoo import api, fields, models +from odoo import _, api, fields, models +from odoo.exceptions import UserError from odoo.tools.misc import str2bool from odoo.addons.mail.tools.discuss import Store @@ -20,7 +21,7 @@ def create(self, vals_list): result = super().create(vals_list) if not livekit_params.get("valid"): - return + return result for session in result: session._generate_livekit_token(livekit_params) @@ -47,6 +48,14 @@ def _get_livekit_config_params(self): and api_secret.strip() ) + if livekit_enabled and not valid: + raise UserError( + _( + "LiveKit integration is enabled but not properly configured." + " Please check the LiveKit settings." + ) + ) + return { "valid": valid, "enabled": livekit_enabled, diff --git a/mail_livekit/static/src/discuss/call_participant_video_patch.js b/mail_livekit/static/src/discuss/call_participant_video_patch.js index e9d44fda..50890275 100644 --- a/mail_livekit/static/src/discuss/call_participant_video_patch.js +++ b/mail_livekit/static/src/discuss/call_participant_video_patch.js @@ -29,8 +29,8 @@ patch(CallParticipantVideo.prototype, { // Subscribe to track rebind events useExternalListener(this.env.bus, "LIVEKIT:TRACK:REBIND", (event) => { const {sessionId, identity, type} = event.detail; - if (this.props.identity === identity && this.props.type === type) { - console.log( + if (this.props.identity == identity && this.props.type === type) { + console.debug( `LIVEKIT:TRACK:REBIND for identity ${identity}, type ${type}` ); if (sessionId && this.props.session.id !== sessionId) { @@ -64,7 +64,7 @@ patch(CallParticipantVideo.prototype, { const livekitTrack = rtcSession.livekitTracks?.get(type); if (livekitTrack) { - console.log( + console.debug( `Attaching LiveKit track for session ${rtcSession.id}, type ${type}` ); diff --git a/mail_livekit/static/src/discuss/livekit_adapter.js b/mail_livekit/static/src/discuss/livekit_adapter.js index 490f3287..f0d5575b 100644 --- a/mail_livekit/static/src/discuss/livekit_adapter.js +++ b/mail_livekit/static/src/discuss/livekit_adapter.js @@ -62,7 +62,7 @@ export class LiveKitAdapter { } handleTrackMuted(participantId, source, track, muted) { - console.log("Track muted event:", participantId, source, track, muted); + console.debug("Track muted event:", participantId, source, track, muted); const type = source === Source.MICROPHONE ? "audio" @@ -82,13 +82,13 @@ export class LiveKitAdapter { addLivekitListeners() { livekitService.subscribeToInfoChange("adapter", (info) => { - console.log("received Info change event:", info); + console.debug("received Info change event:", info); this._emit("info_change", info); }); livekitService.subscribeToTrackSubscribed( "adapter", (participantId, source, track) => { - console.log( + console.debug( "received Track subscribed event:", participantId, source, @@ -100,7 +100,7 @@ export class LiveKitAdapter { livekitService.subscribeToTrackMuted( "adapter", (participantId, source, track, muted) => { - console.log( + console.debug( "received Track muted event:", participantId, source, diff --git a/mail_livekit/static/src/discuss/livekit_service.js b/mail_livekit/static/src/discuss/livekit_service.js index e99ad6ad..243cb2dc 100644 --- a/mail_livekit/static/src/discuss/livekit_service.js +++ b/mail_livekit/static/src/discuss/livekit_service.js @@ -8,8 +8,6 @@ const Source = { SCREEN: window.LivekitClient.Track.Source.ScreenShare, }; -console.log("Livekit Source constants:", Source); - Object.freeze(Source); let debug = false; @@ -79,7 +77,7 @@ class LivekitService { let audioElement = null; - if (track.kind === "audio") { + if (track.kind == "audio") { const audioElementId = this._formAudioElementId(participant.identity); audioElement = document.getElementById(audioElementId); audioElement?.remove(); @@ -217,6 +215,7 @@ class LivekitService { videoCaptureDefaults: { resolution: VideoPresets.h720.resolution, }, + disconnectOnPageLeave: false, }); await this.room.prepareConnection(url, token); diff --git a/mail_livekit/static/src/discuss/rtc_livekit_patch.js b/mail_livekit/static/src/discuss/rtc_livekit_patch.js index 6fdfa5c0..317f8731 100644 --- a/mail_livekit/static/src/discuss/rtc_livekit_patch.js +++ b/mail_livekit/static/src/discuss/rtc_livekit_patch.js @@ -22,11 +22,11 @@ patch(RtcSession.prototype, { patch(PeerToPeer.prototype, { async handleNotification() { - console.log("message intercepted"); + console.debug("message intercepted"); }, _dataChannelupdateInBroadcast() { - console.log("message intercepted"); + console.debug("message intercepted"); }, }); @@ -75,7 +75,7 @@ patch(Rtc.prototype, { ); } if ( - eventdata.detail.name === "info_change" && + eventdata.detail.name == "info_change" && Object.keys(eventdata.detail.payload)[0].includes(":") ) { const fixedIdentity = this.identityToSessionId( @@ -89,7 +89,7 @@ patch(Rtc.prototype, { }, async _handleNetworkUpdates(eventdata) { - console.log("LIVEKIT: Network update received", eventdata); + console.debug("LIVEKIT: Network update received", eventdata); this.fixEventIds(eventdata); return super._handleNetworkUpdates(eventdata); }, @@ -107,7 +107,7 @@ patch(Rtc.prototype, { }, async handleSetAudioVolume(eventdata) { - console.log("LIVEKIT: Set audio volume event received", eventdata); + console.debug("LIVEKIT: Set audio volume event received", eventdata); this.fixEventIds(eventdata); return this.setAudioVolume( eventdata.detail.payload.sessionId, @@ -116,13 +116,13 @@ patch(Rtc.prototype, { }, async handleTrackSubscribed(eventdata) { - console.log("LIVEKIT: Track subscribed event received", eventdata); + console.debug("LIVEKIT: Track subscribed event received", eventdata); this.fixEventIds(eventdata); if (eventdata.detail.name === "trackSubscribed") { const {identity, type, track} = eventdata.detail.payload; const sessionId = this.identityToSessionId(identity); - console.log( + console.debug( `Track subscribed for session ${sessionId}, type ${type}. Triggering rebind.` ); @@ -164,7 +164,7 @@ patch(Rtc.prototype, { }, async updateUpload() { - console.log("Updating uploads for tracks..."); + console.debug("Updating uploads for tracks..."); await this.network?.updateUpload(Source.MICROPHONE, this.state.audioTrack); await this.network?.updateUpload( Source.CAMERA, @@ -189,7 +189,7 @@ patch(Rtc.prototype, { return; } try { - console.log("Connecting to LiveKit server..."); + console.debug("Connecting to LiveKit server..."); await this.network.connect( this.selfSession.livekit_url, this.selfSession.livekit_token