Browse Source

Jitsi-meet template integration prototype

Guénaël Muller 6 years ago
parent
commit
4e9f30f740

+ 9 - 0
tracim/tracim/controllers/root.py View File

@@ -178,3 +178,12 @@ class RootController(StandardController):
178 178
         search_results.keywords = keyword_list
179 179
 
180 180
         return DictLikeClass(fake_api=fake_api, search=search_results)
181
+
182
+    @require(predicates.not_anonymous())
183
+    @expose('tracim.templates.videoconf')
184
+    def videoconf(self):
185
+        user = tmpl_context.current_user
186
+        current_user_content = Context(CTX.CURRENT_USER).toDict(user)
187
+        fake_api = Context(CTX.CURRENT_USER).toDict({'current_user': current_user_content})
188
+
189
+        return DictLikeClass(fake_api=fake_api)

+ 53 - 0
tracim/tracim/lib/jitsi_meet.py View File

@@ -0,0 +1,53 @@
1
+import jwt
2
+import json
3
+import datetime
4
+import time
5
+
6
+JITSI_URL="https://prosody"
7
+JWT_APP_ID="test"
8
+JWT_SECRET="secret"
9
+JWT_ALG='HS256'
10
+JWT_DURATION=60*1 # duration in second
11
+JITSI_USE_TOKEN=True
12
+
13
+
14
+
15
+def _generate_token(room:str)->str:
16
+    '''
17
+    Create jwt token according to room name and config
18
+    :param room: room name
19
+    :return: jwt encoded token as string
20
+    '''
21
+    now = datetime.datetime.utcnow()
22
+    exp = now+datetime.timedelta(seconds=JWT_DURATION)
23
+    data = {
24
+        "iss":JWT_APP_ID, #Issuer
25
+        "room": room, # Custom-param for jitsi-meet
26
+        "aud": "*", # TODO: Understood this param
27
+        "exp": exp, # Expiration date
28
+        "nbf": now, # NotBefore
29
+        "iat": now  # IssuedAt
30
+    }
31
+    jwttoken=jwt.encode(data,
32
+                        JWT_SECRET,
33
+                        algorithm=JWT_ALG)
34
+    return jwttoken.decode("utf-8")
35
+
36
+def _generate_url(room:str)->str:
37
+    '''
38
+    Generate url with or without token
39
+    :param room: room name
40
+    :return: url as string
41
+    '''
42
+    if JITSI_USE_TOKEN:
43
+        token=_generate_token(room)
44
+        url="{}/{}?jwt={}".format(JITSI_URL,
45
+                              room
46
+                              ,token)
47
+    else:
48
+        url="{}/{}".format(JITSI_URL,
49
+                           room)
50
+    return url
51
+
52
+
53
+print(_generate_url("test"))

+ 100 - 0
tracim/tracim/templates/videoconf.mak View File

@@ -0,0 +1,100 @@
1
+<%inherit file="local:templates.master_authenticated_left_treeview_right_toolbar"/>
2
+<%namespace name="TIM" file="tracim.templates.pod"/>
3
+<%namespace name="ROW" file="tracim.templates.widgets.row"/>
4
+<%namespace name="TABLE_ROW" file="tracim.templates.widgets.table_row"/>
5
+<%namespace name="LEFT_MENU" file="tracim.templates.widgets.left_menu"/>
6
+<%namespace name="P" file="tracim.templates.widgets.paragraph"/>
7
+<%namespace name="TOOLBAR" file="tracim.templates.user_toolbars"/>
8
+
9
+<%def name="title()">
10
+    ${_('VideoConf')}
11
+</%def>
12
+
13
+<%def name="TITLE_ROW()">
14
+    ##<div class="content__title">
15
+    ##    ${ROW.TITLE_ROW(_('My Dashboard'), 'fa-home', 'content__title__subtitle-home-hidden-xs', 't-user-color', _('Welcome to your home, {username}.').format(username=fake_api.current_user.name))}
16
+    ##</div>
17
+</%def>
18
+
19
+<%def name="SIDEBAR_RIGHT_CONTENT()">
20
+   ## ${TOOLBAR.USER_ME(fake_api.current_user)}
21
+</%def>
22
+
23
+
24
+<%def name="SIDEBAR_LEFT_CONTENT()">
25
+    ## This is the default left sidebar implementation
26
+    ##${LEFT_MENU.TREEVIEW('sidebar-left-menu', '__')}
27
+</%def>
28
+
29
+<%def name="REQUIRED_DIALOGS()">
30
+    ${TIM.MODAL_DIALOG('user-edit-modal-dialog')}
31
+    ${TIM.MODAL_DIALOG('user-edit-password-modal-dialog')}
32
+</%def>
33
+
34
+<div class="content__home">
35
+    <div id="jitsi">
36
+    </div>
37
+    // This example use jitsi-external API. Using lib-jitsi-meet is also a possibility.
38
+    // It support alls jitsi-meet features.
39
+    /* About support for "private (1-to-1) text message into room", check this :
40
+       https://github.com/jitsi/lib-jitsi-meet/pull/616
41
+    */
42
+    <script src="https://prosody/libs/external_api.min.js"></script>
43
+    <script>
44
+        var domain = "prosody";
45
+        var options = {
46
+	    // jitsi-meet support now(10-2017) only one way to auto-auth, token,
47
+	    // which is anonymous BOSH auth with specific url (with token value in params of the url).
48
+	    jwt:"INSERTTOKENHERE",
49
+            roomName : "test",
50
+            parentNode: document.querySelector('#jitsi'),
51
+	    // has external API use iframe, height is a problem
52
+            height: 800,
53
+            no_SSL: true,
54
+            configOverwrite: {
55
+                 enableWelcomePage: false,
56
+                 enableUserRolesBasedOnToken: true,
57
+		 /*
58
+		  Example of how it can be possible to use others auths.
59
+		  This solution has some security issue.
60
+		  see this rejected PR : https://github.com/jitsi/jitsi-meet/pull/2109
61
+		  roomPassword: "plop",
62
+                  userJid: "john@auth.prosody",
63
+                  userPassword: "j",
64
+		 */
65
+            },
66
+            interfaceConfigOverwrite: {
67
+                ##DEFAULT_BACKGROUND: '#FFFFFF',
68
+                SHOW_JITSI_WATERMARK: false,
69
+                SHOW_POWERED_BY: false,
70
+                SHOW_WATERMARK_FOR_GUESTS: false,
71
+                LANG_DETECTION: true,
72
+                USE_ID_AS_DEFAULT_DISPLAY_NAME: true,
73
+                TOOLBAR_BUTTONS: [
74
+                    //main toolbar
75
+                    'microphone', 'camera', 'desktop', 'fullscreen', 'fodeviceselection', // jshint ignore:line
76
+                    //extended toolbar
77
+                    'contacts', 'settings', 'raisehand', 'videoquality','hangup','chat'], // jshint ignore:line
78
+                MAIN_TOOLBAR_BUTTONS: ['microphone', 'camera', 'desktop', 'fullscreen', 'fodeviceselection',
79
+                    'contacts', 'info', 'settings', 'raisehand', 'videoquality','hangup'] // jshint ignore:line
80
+            }
81
+
82
+        };
83
+        var api = new JitsiMeetExternalAPI(domain, options);
84
+        // Display name in jitsi-meet use XEP-0172 for MUC, which is discouraged,
85
+        // when others clients use resource part of the Jabber id to do it.
86
+        // That's why displayName compat with others XMPP client is not optimal.
87
+        // check this : https://github.com/jitsi/jitsi-meet/pull/2068
88
+        api.executeCommand('displayName', 'Bidule');
89
+        // We can override also avatar.
90
+        api.executeCommand('avatarUrl', 'https://avatars0.githubusercontent.com/u/3671647');
91
+    </script>
92
+   /*  Candy chat iframe, just for some test
93
+       https://github.com/candy-chat/candy
94
+       <iframe src="/assets/candy/index.html"
95
+        width=100%
96
+        height=300px>
97
+      </iframe> 
98
+  */
99
+</div>
100
+