RATIONALE Events are sometimes held online, gathering a community. In this merge we improve Event application to better support full-online events with improved tracks, wishlists, chat rooms, ... PURPOSE Build a mixin to create and manage jitsi-based chat rooms on website. SPECIFICATIONS: CHAT.ROOM Add a new model `chat.room` which contains all the configuration of the Jitsi room. A mixin `chat.room.mixin` adds a many2one to any model inheriting from it. That way behavior is optional without adding all fields on the model. We just need to inherit from the mixin and to use the chat room widget to build chat room on website for any model that needs it. SPECIFICATIONS: WIDGET Allow to give a default username when logging to jitsi if customers are logged. That way they gain a step and can directly participate to chat rooms. SPECIFICATIONS: PARTICIPANT COUNT Jitsi do not provide a REST API (or a similar API) to get the number of participant in a room (without hosting our own instance of Jitsi). The only way to get the number of participant is to be in the room and to use the Javascript API. That's why the participant send in RPC the number of participant in the room, to update the counter on the server side. We can not ask the user who is leaving to update the counter, because he can close the tab on his browser (and so the event will not be triggered), so, the first participant in the room send the update in RPC. Update of participant is done using SQL in non blocking mode so that concurrent accesses are not an issue. Even if participant count is not really accurate this is not an issue as managers will monitor rooms. LINKS Task ID-2252655 (Main Online Event task) Task ID-2283742 (Community gathering on chat rooms) Co-Authored-By: Aurélien Warnon <awa@odoo.com> Co-Authored-By: David Beguin <dbe@odoo.com> Co-Authored-By: Stéphane Debauche <std@odoo.com> Co-Authored-By: Thibault Delavallée <tde@odoo.com>
60 lines
2.1 KiB
Python
60 lines
2.1 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from werkzeug.exceptions import NotFound
|
|
|
|
from odoo import http
|
|
from odoo.http import request
|
|
|
|
|
|
class WebsiteJitsiController(http.Controller):
|
|
|
|
@http.route(["/jitsi/update_status"], type="json", auth="public")
|
|
def jitsi_update_status(self, room_name, participant_count, joined):
|
|
""" Update room status: participant count, max reached
|
|
|
|
Use the SQL keywords "FOR UPDATE SKIP LOCKED" in order to skip if the row
|
|
is locked (instead of raising an exception, wait for a moment and retry).
|
|
This endpoint may be called multiple times and we don't care having small
|
|
errors in participant count compared to performance issues.
|
|
|
|
:raise ValueError: wrong participant count
|
|
:raise NotFound: wrong room name
|
|
"""
|
|
if participant_count < 0:
|
|
raise ValueError()
|
|
|
|
chat_room = self._chat_room_exists(room_name)
|
|
if not chat_room:
|
|
raise NotFound()
|
|
|
|
request.env.cr.execute(
|
|
"""
|
|
WITH req AS (
|
|
SELECT id
|
|
FROM chat_room
|
|
-- Can not update the chat room if we do not have its name
|
|
WHERE name = %s
|
|
FOR UPDATE SKIP LOCKED
|
|
)
|
|
UPDATE chat_room AS wcr
|
|
SET participant_count = %s,
|
|
last_activity = NOW(),
|
|
max_participant_reached = GREATEST(max_participant_reached, %s)
|
|
FROM req
|
|
WHERE wcr.id = req.id;
|
|
""",
|
|
[room_name, participant_count, participant_count]
|
|
)
|
|
|
|
@http.route(["/jitsi/is_full"], type="json", auth="public")
|
|
def jitsi_is_full(self, room_name):
|
|
return self._chat_room_exists(room_name).is_full
|
|
|
|
# ------------------------------------------------------------
|
|
# TOOLS
|
|
# ------------------------------------------------------------
|
|
|
|
def _chat_room_exists(self, room_name):
|
|
return request.env["chat.room"].sudo().search([("name", "=", room_name)], limit=1)
|