Преглед изворни кода

jitsiMeet videoconf related to workspace

Guénaël Muller пре 6 година
родитељ
комит
0a3ca98786

+ 67 - 0
tracim/tracim/controllers/jitsi_meet.py Прегледај датотеку

@@ -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)

+ 0 - 38
tracim/tracim/controllers/root.py Прегледај датотеку

@@ -8,7 +8,6 @@ from tg import request
8 8
 from tg import require
9 9
 from tg import tmpl_context
10 10
 from tg import url
11
-from tg import abort
12 11
 from tg.i18n import ugettext as _
13 12
 
14 13
 from tracim.controllers import StandardController
@@ -33,9 +32,6 @@ from tracim.model.data import ContentType
33 32
 from tracim.model.serializers import Context
34 33
 from tracim.model.serializers import CTX
35 34
 from tracim.model.serializers import DictLikeClass
36
-from tracim.lib.jitsi_meet.jitsi_meet import JitsiMeetRoom
37
-from tracim.lib.jitsi_meet.jitsi_meet import JitsiTokenConfig
38
-from tracim.config.app_cfg import CFG
39 35
 
40 36
 class RootController(StandardController):
41 37
     """
@@ -181,37 +177,3 @@ class RootController(StandardController):
181 177
         search_results.keywords = keyword_list
182 178
 
183 179
         return DictLikeClass(fake_api=fake_api, search=search_results)
184
-
185
-    @require(predicates.not_anonymous())
186
-    @expose('tracim.templates.videoconf')
187
-    def videoconf(self):
188
-        cfg = CFG.get_instance()
189
-        if not cfg.JITSI_MEET_ACTIVATED:
190
-            abort(404)
191
-        user = tmpl_context.current_user
192
-        current_user_content = Context(CTX.CURRENT_USER).toDict(user)
193
-        fake_api = Context(CTX.CURRENT_USER).toDict(
194
-            {'current_user': current_user_content}
195
-        )
196
-
197
-        room = 'test'
198
-
199
-        token = None
200
-        if cfg.JITSI_MEET_USE_TOKEN:
201
-            if cfg.JITSI_MEET_TOKEN_GENERATOR == 'local':
202
-                token = JitsiTokenConfig(
203
-                    app_id=cfg.JITSI_MEET_TOKEN_GENERATOR_LOCAL_APP_ID,
204
-                    secret=cfg.JITSI_MEET_TOKEN_GENERATOR_LOCAL_SECRET,
205
-                    alg=cfg.JITSI_MEET_TOKEN_GENERATOR_LOCAL_ALG,
206
-                    duration=cfg.JITSI_MEET_TOKEN_GENERATOR_LOCAL_DURATION,
207
-                )
208
-            else:
209
-                abort(400)
210
-
211
-        jitsi_meet_room = JitsiMeetRoom(
212
-            room=room,
213
-            domain=cfg.JITSI_MEET_DOMAIN,
214
-            token_config=token)
215
-
216
-        return DictLikeClass(fake_api=fake_api,
217
-                             jitsi_meet_room=jitsi_meet_room)

+ 2 - 0
tracim/tracim/controllers/workspace.py Прегледај датотеку

@@ -9,6 +9,7 @@ from tracim.config.app_cfg import CFG
9 9
 
10 10
 from tracim.controllers import TIMRestController
11 11
 from tracim.controllers.content import UserWorkspaceFolderRestController
12
+from tracim.controllers.jitsi_meet import JitsiMeetController
12 13
 
13 14
 from tracim.lib.helpers import convert_id_into_instances
14 15
 from tracim.lib.content import ContentApi
@@ -28,6 +29,7 @@ class UserWorkspaceRestController(TIMRestController):
28 29
     allow_only = not_anonymous()
29 30
 
30 31
     folders = UserWorkspaceFolderRestController()
32
+    videoconf = JitsiMeetController()
31 33
 
32 34
     @property
33 35
     def _base_url(self):