1
0
mirror of https://gitlab.com/animath/si/plateforme.git synced 2024-12-25 17:02:28 +00:00

Integrate BigBlueButton and whiteboard in pool rooms

This commit is contained in:
Yohann D'ANELLO 2021-01-21 17:44:18 +01:00
parent 97761e07a9
commit 56ad352e64
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
2 changed files with 52 additions and 0 deletions

View File

@ -5,6 +5,7 @@ import os
from asgiref.sync import async_to_sync from asgiref.sync import async_to_sync
from django.core.management import BaseCommand from django.core.management import BaseCommand
from django.utils.http import urlencode
from django.utils.translation import activate from django.utils.translation import activate
from participation.models import Team, Tournament from participation.models import Team, Tournament
from registration.models import AdminRegistration, Registration, VolunteerRegistration from registration.models import AdminRegistration, Registration, VolunteerRegistration
@ -320,6 +321,17 @@ class Command(BaseCommand):
Matrix.set_room_avatar(f"#poule-{slug}-{pool.id}:tfjm.org", avatar_uri) Matrix.set_room_avatar(f"#poule-{slug}-{pool.id}:tfjm.org", avatar_uri)
Matrix.set_room_avatar(f"#poule-{slug}-{pool.id}-jurys:tfjm.org", avatar_uri) Matrix.set_room_avatar(f"#poule-{slug}-{pool.id}-jurys:tfjm.org", avatar_uri)
url_params = urlencode(dict(url="https://visio.animath.live/b/XXX-XXX-XXX",
isAudioConf='false', displayName='$matrix_display_name',
avatarUrl='$matrix_avatar_url', userId='$matrix_user_id')) \
.replace("%24", "$")
Matrix.add_integration(f"#poule-{slug}-{pool.id}:tfjm.org",
f"https://scalar.vector.im/api/widgets/bigbluebutton.html?{url_params}",
f"bbb-{slug}-{pool.id}", "bigbluebutton", "BigBlueButton", str(pool))
Matrix.add_integration(f"#poule-{slug}-{pool.id}:tfjm.org",
f"https://board.tfjm.org/boards/{slug}-{pool.id}", f"board-{slug}-{pool.id}",
"customwidget", "Tableau", str(pool))
# Invite admins and give permissions # Invite admins and give permissions
for admin in AdminRegistration.objects.all(): for admin in AdminRegistration.objects.all():
Matrix.invite(f"#poule-{slug}-{pool.id}:tfjm.org", f"@{admin.matrix_username}:tfjm.org") Matrix.invite(f"#poule-{slug}-{pool.id}:tfjm.org", f"@{admin.matrix_username}:tfjm.org")

View File

@ -263,6 +263,46 @@ class Matrix:
content=content, content=content,
) )
@classmethod
@async_to_sync
async def add_integration(cls, room_id: str, widget_url: str, state_key: str,
widget_type: str = "customwidget", widget_name: str = "Custom widget",
widget_title: str = ""):
client = await cls._get_client()
if room_id.startswith("#"):
room_id = await cls.resolve_room_alias(room_id)
content = {
"type": widget_type,
"url": widget_url,
"name": widget_name,
"data": {
"curl": widget_url,
"title": widget_title,
},
"creatorUserId": client.user,
"roomId": room_id,
"id": state_key,
}
return await client.room_put_state(
room_id=room_id,
event_type="im.vector.modular.widgets",
content=content,
state_key=state_key,
)
@classmethod
@async_to_sync
async def remove_integration(cls, room_id: str, state_key: str):
client = await cls._get_client()
if room_id.startswith("#"):
room_id = await cls.resolve_room_alias(room_id)
return await client.room_put_state(
room_id=room_id,
event_type="im.vector.modular.widgets",
content={},
state_key=state_key,
)
@classmethod @classmethod
@async_to_sync @async_to_sync
async def kick(cls, room_id: str, user_id: str, reason: str = None): async def kick(cls, room_id: str, user_id: str, reason: str = None):