Skip to content

Commit 414a4f1

Browse files
DanielPhillip-SolvtiKDRdevjans23
committed
Livekit integration v18 (#256)
* refactored, simplified, more odoo * updated readme * imporved muting * null check * add UI check * add audio element to DOM * null check * updated manifest * added additional mute handling * added additional mute handling * added additional mute handling * improved clean up * nullcheck * address various possible errors * address various possible errors * address various possible errors * address various possible errors * address various possible errors * extended clean up * committed to livekit managing audio streams * tied voulme control to audio elements * trigger rebind on connect * changed rebind logic * move rebind to livekit service * Delete odoo.conf * Delete mail_livekit/streamIssue.md * Rename JS file to avoid liner errors * Rename JS file to avoid linter errors * Update author information in manifest * additional cleanup on disconnect * fix bad return on create, throw loud error for missing credentials * remove disconnect on page leave behaviour * Refactor track publishing logic into a separate method --------- Co-authored-by: Dmytro Kashuba @ Solvti <dmitry.kashuba.cv@gmail.com> Co-authored-by: jans23 <jans23@users.noreply.github.com>
1 parent 5235f28 commit 414a4f1

File tree

5 files changed

+29
-21
lines changed

5 files changed

+29
-21
lines changed

mail_livekit/models/mail_rtc_session.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from livekit.api import AccessToken, VideoGrants
22

3-
from odoo import api, fields, models
3+
from odoo import _, api, fields, models
4+
from odoo.exceptions import UserError
45
from odoo.tools.misc import str2bool
56

67
from odoo.addons.mail.tools.discuss import Store
@@ -20,7 +21,7 @@ def create(self, vals_list):
2021
result = super().create(vals_list)
2122

2223
if not livekit_params.get("valid"):
23-
return
24+
return result
2425

2526
for session in result:
2627
session._generate_livekit_token(livekit_params)
@@ -47,6 +48,14 @@ def _get_livekit_config_params(self):
4748
and api_secret.strip()
4849
)
4950

51+
if livekit_enabled and not valid:
52+
raise UserError(
53+
_(
54+
"LiveKit integration is enabled but not properly configured."
55+
" Please check the LiveKit settings."
56+
)
57+
)
58+
5059
return {
5160
"valid": valid,
5261
"enabled": livekit_enabled,

mail_livekit/static/src/discuss/call_participant_video_patch.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ patch(CallParticipantVideo.prototype, {
2929
// Subscribe to track rebind events
3030
useExternalListener(this.env.bus, "LIVEKIT:TRACK:REBIND", (event) => {
3131
const {sessionId, identity, type} = event.detail;
32-
if (this.props.identity === identity && this.props.type === type) {
33-
console.log(
32+
if (this.props.identity == identity && this.props.type === type) {
33+
console.debug(
3434
`LIVEKIT:TRACK:REBIND for identity ${identity}, type ${type}`
3535
);
3636
if (sessionId && this.props.session.id !== sessionId) {
@@ -64,7 +64,7 @@ patch(CallParticipantVideo.prototype, {
6464
const livekitTrack = rtcSession.livekitTracks?.get(type);
6565

6666
if (livekitTrack) {
67-
console.log(
67+
console.debug(
6868
`Attaching LiveKit track for session ${rtcSession.id}, type ${type}`
6969
);
7070

mail_livekit/static/src/discuss/livekit_adapter.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export class LiveKitAdapter {
6262
}
6363

6464
handleTrackMuted(participantId, source, track, muted) {
65-
console.log("Track muted event:", participantId, source, track, muted);
65+
console.debug("Track muted event:", participantId, source, track, muted);
6666
const type =
6767
source === Source.MICROPHONE
6868
? "audio"
@@ -82,13 +82,13 @@ export class LiveKitAdapter {
8282

8383
addLivekitListeners() {
8484
livekitService.subscribeToInfoChange("adapter", (info) => {
85-
console.log("received Info change event:", info);
85+
console.debug("received Info change event:", info);
8686
this._emit("info_change", info);
8787
});
8888
livekitService.subscribeToTrackSubscribed(
8989
"adapter",
9090
(participantId, source, track) => {
91-
console.log(
91+
console.debug(
9292
"received Track subscribed event:",
9393
participantId,
9494
source,
@@ -100,7 +100,7 @@ export class LiveKitAdapter {
100100
livekitService.subscribeToTrackMuted(
101101
"adapter",
102102
(participantId, source, track, muted) => {
103-
console.log(
103+
console.debug(
104104
"received Track muted event:",
105105
participantId,
106106
source,

mail_livekit/static/src/discuss/livekit_service.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ const Source = {
88
SCREEN: window.LivekitClient.Track.Source.ScreenShare,
99
};
1010

11-
console.log("Livekit Source constants:", Source);
12-
1311
Object.freeze(Source);
1412

1513
let debug = false;
@@ -79,7 +77,7 @@ class LivekitService {
7977

8078
let audioElement = null;
8179

82-
if (track.kind === "audio") {
80+
if (track.kind == "audio") {
8381
const audioElementId = this._formAudioElementId(participant.identity);
8482
audioElement = document.getElementById(audioElementId);
8583
audioElement?.remove();
@@ -217,6 +215,7 @@ class LivekitService {
217215
videoCaptureDefaults: {
218216
resolution: VideoPresets.h720.resolution,
219217
},
218+
disconnectOnPageLeave: false,
220219
});
221220

222221
await this.room.prepareConnection(url, token);

mail_livekit/static/src/discuss/rtc_livekit_patch.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ patch(RtcSession.prototype, {
2222

2323
patch(PeerToPeer.prototype, {
2424
async handleNotification() {
25-
console.log("message intercepted");
25+
console.debug("message intercepted");
2626
},
2727

2828
_dataChannelupdateInBroadcast() {
29-
console.log("message intercepted");
29+
console.debug("message intercepted");
3030
},
3131
});
3232

@@ -75,7 +75,7 @@ patch(Rtc.prototype, {
7575
);
7676
}
7777
if (
78-
eventdata.detail.name === "info_change" &&
78+
eventdata.detail.name == "info_change" &&
7979
Object.keys(eventdata.detail.payload)[0].includes(":")
8080
) {
8181
const fixedIdentity = this.identityToSessionId(
@@ -89,7 +89,7 @@ patch(Rtc.prototype, {
8989
},
9090

9191
async _handleNetworkUpdates(eventdata) {
92-
console.log("LIVEKIT: Network update received", eventdata);
92+
console.debug("LIVEKIT: Network update received", eventdata);
9393
this.fixEventIds(eventdata);
9494
return super._handleNetworkUpdates(eventdata);
9595
},
@@ -107,7 +107,7 @@ patch(Rtc.prototype, {
107107
},
108108

109109
async handleSetAudioVolume(eventdata) {
110-
console.log("LIVEKIT: Set audio volume event received", eventdata);
110+
console.debug("LIVEKIT: Set audio volume event received", eventdata);
111111
this.fixEventIds(eventdata);
112112
return this.setAudioVolume(
113113
eventdata.detail.payload.sessionId,
@@ -116,13 +116,13 @@ patch(Rtc.prototype, {
116116
},
117117

118118
async handleTrackSubscribed(eventdata) {
119-
console.log("LIVEKIT: Track subscribed event received", eventdata);
119+
console.debug("LIVEKIT: Track subscribed event received", eventdata);
120120
this.fixEventIds(eventdata);
121121
if (eventdata.detail.name === "trackSubscribed") {
122122
const {identity, type, track} = eventdata.detail.payload;
123123
const sessionId = this.identityToSessionId(identity);
124124

125-
console.log(
125+
console.debug(
126126
`Track subscribed for session ${sessionId}, type ${type}. Triggering rebind.`
127127
);
128128

@@ -164,7 +164,7 @@ patch(Rtc.prototype, {
164164
},
165165

166166
async updateUpload() {
167-
console.log("Updating uploads for tracks...");
167+
console.debug("Updating uploads for tracks...");
168168
await this.network?.updateUpload(Source.MICROPHONE, this.state.audioTrack);
169169
await this.network?.updateUpload(
170170
Source.CAMERA,
@@ -189,7 +189,7 @@ patch(Rtc.prototype, {
189189
return;
190190
}
191191
try {
192-
console.log("Connecting to LiveKit server...");
192+
console.debug("Connecting to LiveKit server...");
193193
await this.network.connect(
194194
this.selfSession.livekit_url,
195195
this.selfSession.livekit_token

0 commit comments

Comments
 (0)