|
@@ -0,0 +1,67 @@
|
|
1
|
+import tg
|
|
2
|
+from tg import abort
|
|
3
|
+from tg import expose
|
|
4
|
+from tg import tmpl_context
|
|
5
|
+from tg.predicates import not_anonymous
|
|
6
|
+from tracim.lib.predicates import current_user_is_reader
|
|
7
|
+from sqlalchemy.orm.exc import NoResultFound
|
|
8
|
+
|
|
9
|
+from unidecode import unidecode
|
|
10
|
+from tracim.lib.jitsi_meet.jitsi_meet import JitsiMeetRoom
|
|
11
|
+from tracim.lib.jitsi_meet.jitsi_meet import JitsiTokenConfig
|
|
12
|
+from tracim.config.app_cfg import CFG
|
|
13
|
+
|
|
14
|
+from tracim.model.serializers import Context, CTX, DictLikeClass
|
|
15
|
+from tracim.controllers import TIMRestController, TIMRestPathContextSetup
|
|
16
|
+
|
|
17
|
+class JitsiMeetController(TIMRestController):
|
|
18
|
+
|
|
19
|
+ allow_only = not_anonymous()
|
|
20
|
+
|
|
21
|
+ def _before(self, *args, **kw):
|
|
22
|
+ TIMRestPathContextSetup.current_user()
|
|
23
|
+ try:
|
|
24
|
+ TIMRestPathContextSetup.current_workspace()
|
|
25
|
+ except NoResultFound:
|
|
26
|
+ abort(404)
|
|
27
|
+
|
|
28
|
+ @tg.require(current_user_is_reader())
|
|
29
|
+ @expose('tracim.templates.videoconf')
|
|
30
|
+ def get(self):
|
|
31
|
+ cfg = CFG.get_instance()
|
|
32
|
+ if not cfg.JITSI_MEET_ACTIVATED:
|
|
33
|
+ abort(404)
|
|
34
|
+ user = tmpl_context.current_user
|
|
35
|
+ workspace = tmpl_context.workspace
|
|
36
|
+ current_user_content = Context(CTX.CURRENT_USER).toDict(user)
|
|
37
|
+ fake_api = Context(CTX.CURRENT_USER).toDict(
|
|
38
|
+ {'current_user': current_user_content,
|
|
39
|
+ 'workspace': workspace,
|
|
40
|
+ }
|
|
41
|
+ )
|
|
42
|
+ label = unidecode(workspace.label)
|
|
43
|
+ parsed_label = ''.join(e for e in label if e.isalnum())
|
|
44
|
+ # TODO - G.M - 18-01-2017 -
|
|
45
|
+ # allow to set specific room name from workspace object ?
|
|
46
|
+ room = "{id}{label}".format(id=workspace.workspace_id,
|
|
47
|
+ label=parsed_label)
|
|
48
|
+
|
|
49
|
+ token = None
|
|
50
|
+ if cfg.JITSI_MEET_USE_TOKEN:
|
|
51
|
+ if cfg.JITSI_MEET_TOKEN_GENERATOR == 'local':
|
|
52
|
+ token = JitsiTokenConfig(
|
|
53
|
+ app_id=cfg.JITSI_MEET_TOKEN_GENERATOR_LOCAL_APP_ID,
|
|
54
|
+ secret=cfg.JITSI_MEET_TOKEN_GENERATOR_LOCAL_SECRET,
|
|
55
|
+ alg=cfg.JITSI_MEET_TOKEN_GENERATOR_LOCAL_ALG,
|
|
56
|
+ duration=cfg.JITSI_MEET_TOKEN_GENERATOR_LOCAL_DURATION,
|
|
57
|
+ )
|
|
58
|
+ else:
|
|
59
|
+ abort(400)
|
|
60
|
+
|
|
61
|
+ jitsi_meet_room = JitsiMeetRoom(
|
|
62
|
+ room=room,
|
|
63
|
+ domain=cfg.JITSI_MEET_DOMAIN,
|
|
64
|
+ token_config=token)
|
|
65
|
+
|
|
66
|
+ return DictLikeClass(fake_api=fake_api,
|
|
67
|
+ jitsi_meet_room=jitsi_meet_room)
|