Ver código fonte

Creates API module.

j8
hristoterezov 10 anos atrás
pai
commit
0508628871
9 arquivos alterados com 465 adições e 263 exclusões
  1. 0
    202
      api_connector.js
  2. 4
    4
      app.js
  3. 2
    2
      index.html
  4. 207
    0
      libs/modules/API.bundle.js
  5. 38
    28
      libs/modules/UI.bundle.js
  6. 204
    0
      modules/API/API.js
  7. 0
    6
      modules/UI/UI.js
  8. 4
    7
      modules/UI/videolayout/VideoLayout.js
  9. 6
    14
      muc.js

+ 0
- 202
api_connector.js Ver arquivo

1
-/**
2
- * Implements API class that communicates with external api class
3
- * and provides interface to access Jitsi Meet features by external
4
- * applications that embed Jitsi Meet
5
- */
6
-var APIConnector = (function () {
7
-
8
-    function APIConnector() { }
9
-
10
-    /**
11
-     * List of the available commands.
12
-     * @type {{
13
-     *              displayName: inputDisplayNameHandler,
14
-     *              muteAudio: toggleAudio,
15
-     *              muteVideo: toggleVideo,
16
-     *              filmStrip: toggleFilmStrip
17
-     *          }}
18
-     */
19
-    var commands =
20
-    {
21
-        displayName: UI.inputDisplayNameHandler,
22
-        muteAudio: toggleAudio,
23
-        muteVideo: toggleVideo,
24
-        toggleFilmStrip: UI.toggleFilmStrip,
25
-        toggleChat: UI.toggleChat,
26
-        toggleContactList: UI.toggleContactList
27
-    };
28
-
29
-
30
-    /**
31
-     * Maps the supported events and their status
32
-     * (true it the event is enabled and false if it is disabled)
33
-     * @type {{
34
-     *              incomingMessage: boolean,
35
-     *              outgoingMessage: boolean,
36
-     *              displayNameChange: boolean,
37
-     *              participantJoined: boolean,
38
-     *              participantLeft: boolean
39
-     *      }}
40
-     */
41
-    var events =
42
-    {
43
-        incomingMessage: false,
44
-        outgoingMessage:false,
45
-        displayNameChange: false,
46
-        participantJoined: false,
47
-        participantLeft: false
48
-    };
49
-
50
-    /**
51
-     * Check whether the API should be enabled or not.
52
-     * @returns {boolean}
53
-     */
54
-    APIConnector.isEnabled = function () {
55
-        var hash = location.hash;
56
-        if(hash && hash.indexOf("external") > -1 && window.postMessage)
57
-            return true;
58
-        return false;
59
-    };
60
-
61
-    /**
62
-     * Initializes the APIConnector. Setups message event listeners that will
63
-     * receive information from external applications that embed Jitsi Meet.
64
-     * It also sends a message to the external application that APIConnector
65
-     * is initialized.
66
-     */
67
-    APIConnector.init = function () {
68
-        if (window.addEventListener)
69
-        {
70
-            window.addEventListener('message',
71
-                APIConnector.processMessage, false);
72
-        }
73
-        else
74
-        {
75
-            window.attachEvent('onmessage', APIConnector.processMessage);
76
-        }
77
-        APIConnector.sendMessage({type: "system", loaded: true});
78
-    };
79
-
80
-    /**
81
-     * Sends message to the external application.
82
-     * @param object
83
-     */
84
-    APIConnector.sendMessage = function (object) {
85
-        window.parent.postMessage(JSON.stringify(object), "*");
86
-    };
87
-
88
-    /**
89
-     * Processes a message event from the external application
90
-     * @param event the message event
91
-     */
92
-    APIConnector.processMessage = function(event)
93
-    {
94
-        var message;
95
-        try {
96
-            message = JSON.parse(event.data);
97
-        } catch (e) {}
98
-
99
-        if(!message.type)
100
-            return;
101
-        switch (message.type)
102
-        {
103
-            case "command":
104
-                APIConnector.processCommand(message);
105
-                break;
106
-            case "event":
107
-                APIConnector.processEvent(message);
108
-                break;
109
-            default:
110
-                console.error("Unknown type of the message");
111
-                return;
112
-        }
113
-
114
-    };
115
-
116
-    /**
117
-     * Processes commands from external applicaiton.
118
-     * @param message the object with the command
119
-     */
120
-    APIConnector.processCommand = function (message)
121
-    {
122
-        if(message.action != "execute")
123
-        {
124
-            console.error("Unknown action of the message");
125
-            return;
126
-        }
127
-        for(var key in message)
128
-        {
129
-            if(commands[key])
130
-                commands[key].apply(null, message[key]);
131
-        }
132
-    };
133
-
134
-    /**
135
-     * Processes events objects from external applications
136
-     * @param event the event
137
-     */
138
-    APIConnector.processEvent = function (event) {
139
-        if(!event.action)
140
-        {
141
-            console.error("Event with no action is received.");
142
-            return;
143
-        }
144
-
145
-        switch(event.action)
146
-        {
147
-            case "add":
148
-                for(var i = 0; i < event.events.length; i++)
149
-                {
150
-                    events[event.events[i]] = true;
151
-                }
152
-                break;
153
-            case "remove":
154
-                for(var i = 0; i < event.events.length; i++)
155
-                {
156
-                    events[event.events[i]] = false;
157
-                }
158
-                break;
159
-            default:
160
-                console.error("Unknown action for event.");
161
-        }
162
-
163
-    };
164
-
165
-    /**
166
-     * Checks whether the event is enabled ot not.
167
-     * @param name the name of the event.
168
-     * @returns {*}
169
-     */
170
-    APIConnector.isEventEnabled = function (name) {
171
-        return events[name];
172
-    };
173
-
174
-    /**
175
-     * Sends event object to the external application that has been subscribed
176
-     * for that event.
177
-     * @param name the name event
178
-     * @param object data associated with the event
179
-     */
180
-    APIConnector.triggerEvent = function (name, object) {
181
-        APIConnector.sendMessage({
182
-            type: "event", action: "result", event: name, result: object});
183
-    };
184
-
185
-    /**
186
-     * Removes the listeners.
187
-     */
188
-    APIConnector.dispose = function () {
189
-        if(window.removeEventListener)
190
-        {
191
-            window.removeEventListener("message",
192
-                APIConnector.processMessage, false);
193
-        }
194
-        else
195
-        {
196
-            window.detachEvent('onmessage', APIConnector.processMessage);
197
-        }
198
-
199
-    };
200
-
201
-    return APIConnector;
202
-})();

+ 4
- 4
app.js Ver arquivo

732
 
732
 
733
 $(document).ready(function () {
733
 $(document).ready(function () {
734
 
734
 
735
-    if(APIConnector.isEnabled())
736
-        APIConnector.init();
735
+    if(API.isEnabled())
736
+        API.init();
737
 
737
 
738
     UI.start();
738
     UI.start();
739
     statistics.start();
739
     statistics.start();
771
         });
771
         });
772
     }
772
     }
773
     disposeConference(true);
773
     disposeConference(true);
774
-    if(APIConnector.isEnabled())
775
-        APIConnector.dispose();
774
+    if(API.isEnabled())
775
+        API.dispose();
776
 });
776
 });
777
 
777
 
778
 function disposeConference(onUnload) {
778
 function disposeConference(onUnload) {

+ 2
- 2
index.html Ver arquivo

31
     <script src="service/RTC/StreamEventTypes.js?v=1"></script>
31
     <script src="service/RTC/StreamEventTypes.js?v=1"></script>
32
     <script src="service/RTC/MediaStreamTypes.js?v=1"></script>
32
     <script src="service/RTC/MediaStreamTypes.js?v=1"></script>
33
     <script src="libs/modules/connectionquality.bundle.js?v=1"></script>
33
     <script src="libs/modules/connectionquality.bundle.js?v=1"></script>
34
-    <script src="libs/modules/UI.bundle.js?v=1"></script>
34
+    <script src="libs/modules/UI.bundle.js?v=2"></script>
35
     <script src="libs/modules/statistics.bundle.js?v=1"></script>
35
     <script src="libs/modules/statistics.bundle.js?v=1"></script>
36
     <script src="libs/modules/RTC.bundle.js?v=1"></script>
36
     <script src="libs/modules/RTC.bundle.js?v=1"></script>
37
     <script src="muc.js?v=17"></script><!-- simple MUC library -->
37
     <script src="muc.js?v=17"></script><!-- simple MUC library -->
38
     <script src="estos_log.js?v=2"></script><!-- simple stanza logger -->
38
     <script src="estos_log.js?v=2"></script><!-- simple stanza logger -->
39
     <script src="desktopsharing.js?v=3"></script><!-- desktop sharing -->
39
     <script src="desktopsharing.js?v=3"></script><!-- desktop sharing -->
40
     <script src="app.js?v=24"></script><!-- application logic -->
40
     <script src="app.js?v=24"></script><!-- application logic -->
41
+    <script src="libs/modules/API.bundle.js?v=1"></script>
41
     <script src="util.js?v=7"></script><!-- utility functions -->
42
     <script src="util.js?v=7"></script><!-- utility functions -->
42
     <script src="moderatemuc.js?v=4"></script><!-- moderator plugin -->
43
     <script src="moderatemuc.js?v=4"></script><!-- moderator plugin -->
43
     <script src="analytics.js?v=1"></script><!-- google analytics plugin -->
44
     <script src="analytics.js?v=1"></script><!-- google analytics plugin -->
44
     <script src="moderator.js?v=2"></script><!-- media stream -->
45
     <script src="moderator.js?v=2"></script><!-- media stream -->
45
     <script src="tracking.js?v=1"></script><!-- tracking -->
46
     <script src="tracking.js?v=1"></script><!-- tracking -->
46
-    <script src="api_connector.js?v=2"></script>
47
     <script src="keyboard_shortcut.js?v=3"></script>
47
     <script src="keyboard_shortcut.js?v=3"></script>
48
     <link rel="stylesheet" href="css/font.css?v=6"/>
48
     <link rel="stylesheet" href="css/font.css?v=6"/>
49
     <link rel="stylesheet" href="css/toastr.css?v=1">
49
     <link rel="stylesheet" href="css/toastr.css?v=1">

+ 207
- 0
libs/modules/API.bundle.js Ver arquivo

1
+!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.API=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
2
+/**
3
+ * Implements API class that communicates with external api class
4
+ * and provides interface to access Jitsi Meet features by external
5
+ * applications that embed Jitsi Meet
6
+ */
7
+
8
+
9
+
10
+/**
11
+ * List of the available commands.
12
+ * @type {{
13
+ *              displayName: inputDisplayNameHandler,
14
+ *              muteAudio: toggleAudio,
15
+ *              muteVideo: toggleVideo,
16
+ *              filmStrip: toggleFilmStrip
17
+ *          }}
18
+ */
19
+var commands =
20
+{
21
+    displayName: UI.inputDisplayNameHandler,
22
+    muteAudio: toggleAudio,
23
+    muteVideo: toggleVideo,
24
+    toggleFilmStrip: UI.toggleFilmStrip,
25
+    toggleChat: UI.toggleChat,
26
+    toggleContactList: UI.toggleContactList
27
+};
28
+
29
+
30
+/**
31
+ * Maps the supported events and their status
32
+ * (true it the event is enabled and false if it is disabled)
33
+ * @type {{
34
+ *              incomingMessage: boolean,
35
+ *              outgoingMessage: boolean,
36
+ *              displayNameChange: boolean,
37
+ *              participantJoined: boolean,
38
+ *              participantLeft: boolean
39
+ *      }}
40
+ */
41
+var events =
42
+{
43
+    incomingMessage: false,
44
+    outgoingMessage:false,
45
+    displayNameChange: false,
46
+    participantJoined: false,
47
+    participantLeft: false
48
+};
49
+
50
+/**
51
+ * Processes commands from external applicaiton.
52
+ * @param message the object with the command
53
+ */
54
+function processCommand(message)
55
+{
56
+    if(message.action != "execute")
57
+    {
58
+        console.error("Unknown action of the message");
59
+        return;
60
+    }
61
+    for(var key in message)
62
+    {
63
+        if(commands[key])
64
+            commands[key].apply(null, message[key]);
65
+    }
66
+}
67
+
68
+/**
69
+ * Processes events objects from external applications
70
+ * @param event the event
71
+ */
72
+function processEvent(event) {
73
+    if(!event.action)
74
+    {
75
+        console.error("Event with no action is received.");
76
+        return;
77
+    }
78
+
79
+    var i = 0;
80
+    switch(event.action)
81
+    {
82
+        case "add":
83
+            for(; i < event.events.length; i++)
84
+            {
85
+                events[event.events[i]] = true;
86
+            }
87
+            break;
88
+        case "remove":
89
+            for(; i < event.events.length; i++)
90
+            {
91
+                events[event.events[i]] = false;
92
+            }
93
+            break;
94
+        default:
95
+            console.error("Unknown action for event.");
96
+    }
97
+
98
+}
99
+
100
+/**
101
+ * Sends message to the external application.
102
+ * @param object
103
+ */
104
+function sendMessage(object) {
105
+    window.parent.postMessage(JSON.stringify(object), "*");
106
+}
107
+
108
+/**
109
+ * Processes a message event from the external application
110
+ * @param event the message event
111
+ */
112
+function processMessage(event)
113
+{
114
+    var message;
115
+    try {
116
+        message = JSON.parse(event.data);
117
+    } catch (e) {}
118
+
119
+    if(!message.type)
120
+        return;
121
+    switch (message.type)
122
+    {
123
+        case "command":
124
+            processCommand(message);
125
+            break;
126
+        case "event":
127
+            processEvent(message);
128
+            break;
129
+        default:
130
+            console.error("Unknown type of the message");
131
+            return;
132
+    }
133
+
134
+}
135
+
136
+var API = {
137
+    /**
138
+     * Check whether the API should be enabled or not.
139
+     * @returns {boolean}
140
+     */
141
+    isEnabled: function () {
142
+        var hash = location.hash;
143
+        if(hash && hash.indexOf("external") > -1 && window.postMessage)
144
+            return true;
145
+        return false;
146
+    },
147
+    /**
148
+     * Initializes the APIConnector. Setups message event listeners that will
149
+     * receive information from external applications that embed Jitsi Meet.
150
+     * It also sends a message to the external application that APIConnector
151
+     * is initialized.
152
+     */
153
+    init: function () {
154
+        if (window.addEventListener)
155
+        {
156
+            window.addEventListener('message',
157
+                processMessage, false);
158
+        }
159
+        else
160
+        {
161
+            window.attachEvent('onmessage', processMessage);
162
+        }
163
+        sendMessage({type: "system", loaded: true});
164
+    },
165
+    /**
166
+     * Checks whether the event is enabled ot not.
167
+     * @param name the name of the event.
168
+     * @returns {*}
169
+     */
170
+    isEventEnabled: function (name) {
171
+        return events[name];
172
+    },
173
+
174
+    /**
175
+     * Sends event object to the external application that has been subscribed
176
+     * for that event.
177
+     * @param name the name event
178
+     * @param object data associated with the event
179
+     */
180
+    triggerEvent: function (name, object) {
181
+        if(this.isEnabled() && this.isEventEnabled(name))
182
+            sendMessage({
183
+                type: "event", action: "result", event: name, result: object});
184
+    },
185
+
186
+    /**
187
+     * Removes the listeners.
188
+     */
189
+    dispose: function () {
190
+        if(window.removeEventListener)
191
+        {
192
+            window.removeEventListener("message",
193
+                processMessage, false);
194
+        }
195
+        else
196
+        {
197
+            window.detachEvent('onmessage', processMessage);
198
+        }
199
+
200
+    }
201
+
202
+
203
+};
204
+
205
+module.exports = API;
206
+},{}]},{},[1])(1)
207
+});

+ 38
- 28
libs/modules/UI.bundle.js Ver arquivo

461
 
461
 
462
     // Add Peer's container
462
     // Add Peer's container
463
     VideoLayout.ensurePeerContainerExists(jid,id);
463
     VideoLayout.ensurePeerContainerExists(jid,id);
464
-
465
-    if(APIConnector.isEnabled() &&
466
-        APIConnector.isEventEnabled("participantJoined"))
467
-    {
468
-        APIConnector.triggerEvent("participantJoined",{jid: jid});
469
-    }
470
 };
464
 };
471
 
465
 
472
 UI.onMucPresenceStatus = function ( jid, info) {
466
 UI.onMucPresenceStatus = function ( jid, info) {
552
 UI.connectionIndicatorShowMore = function(id)
546
 UI.connectionIndicatorShowMore = function(id)
553
 {
547
 {
554
     return VideoLayout.connectionIndicators[id].showMore();
548
     return VideoLayout.connectionIndicators[id].showMore();
555
-}
549
+};
556
 
550
 
557
 UI.showToolbar = function () {
551
 UI.showToolbar = function () {
558
     return ToolbarToggler.showToolbar();
552
     return ToolbarToggler.showToolbar();
559
-}
553
+};
560
 
554
 
561
 UI.dockToolbar = function (isDock) {
555
 UI.dockToolbar = function (isDock) {
562
     return ToolbarToggler.dockToolbar(isDock);
556
     return ToolbarToggler.dockToolbar(isDock);
563
-}
557
+};
564
 
558
 
565
 
559
 
560
+function dump(elem, filename) {
561
+    elem = elem.parentNode;
562
+    elem.download = filename || 'meetlog.json';
563
+    elem.href = 'data:application/json;charset=utf-8,\n';
564
+    var data = {};
565
+    if (connection.jingle) {
566
+        data = connection.jingle.populateData();
567
+    }
568
+    var metadata = {};
569
+    metadata.time = new Date();
570
+    metadata.url = window.location.href;
571
+    metadata.ua = navigator.userAgent;
572
+    if (connection.logger) {
573
+        metadata.xmpp = connection.logger.log;
574
+    }
575
+    data.metadata = metadata;
576
+    elem.href += encodeURIComponent(JSON.stringify(data, null, '  '));
577
+    return false;
578
+}
579
+
566
 module.exports = UI;
580
 module.exports = UI;
567
 
581
 
568
 
582
 
1683
         var videospaceWidth = window.innerWidth - panelSize[0];
1697
         var videospaceWidth = window.innerWidth - panelSize[0];
1684
         var videospaceHeight = window.innerHeight;
1698
         var videospaceHeight = window.innerHeight;
1685
         var videoSize
1699
         var videoSize
1686
-            = getVideoSize(null, null, videospaceWidth, videospaceHeight);
1700
+            = VideoLayout.getVideoSize(null, null, videospaceWidth, videospaceHeight);
1687
         var videoWidth = videoSize[0];
1701
         var videoWidth = videoSize[0];
1688
         var videoHeight = videoSize[1];
1702
         var videoHeight = videoSize[1];
1689
-        var videoPosition = getVideoPosition(videoWidth,
1703
+        var videoPosition = VideoLayout.getVideoPosition(videoWidth,
1690
             videoHeight,
1704
             videoHeight,
1691
             videospaceWidth,
1705
             videospaceWidth,
1692
             videospaceHeight);
1706
             videospaceHeight);
1908
 
1922
 
1909
 module.exports = PanelToggler;
1923
 module.exports = PanelToggler;
1910
 },{"../toolbars/ToolbarToggler":16,"../videolayout/VideoLayout":23,"./chat/Chat":8,"./contactlist/ContactList":12,"./settings/Settings":13,"./settings/SettingsMenu":14}],8:[function(require,module,exports){
1924
 },{"../toolbars/ToolbarToggler":16,"../videolayout/VideoLayout":23,"./chat/Chat":8,"./contactlist/ContactList":12,"./settings/Settings":13,"./settings/SettingsMenu":14}],8:[function(require,module,exports){
1911
-/* global $, Util, connection, nickname:true, getVideoSize,
1912
-getVideoPosition, showToolbar */
1925
+/* global $, Util, connection, nickname:true, showToolbar */
1913
 var Replacement = require("./Replacement");
1926
 var Replacement = require("./Replacement");
1914
 var CommandsProcessor = require("./Commands");
1927
 var CommandsProcessor = require("./Commands");
1915
 var ToolbarToggler = require("../../toolbars/ToolbarToggler");
1928
 var ToolbarToggler = require("../../toolbars/ToolbarToggler");
4180
     newSrc: ''
4193
     newSrc: ''
4181
 };
4194
 };
4182
 
4195
 
4183
-// By default we use camera
4184
-var getVideoSize = getCameraVideoSize;
4185
-var getVideoPosition = getCameraVideoPosition;
4186
-
4187
 var defaultLocalDisplayName = "Me";
4196
 var defaultLocalDisplayName = "Me";
4188
 
4197
 
4189
 /**
4198
 /**
4571
 var VideoLayout = (function (my) {
4580
 var VideoLayout = (function (my) {
4572
     my.connectionIndicators = {};
4581
     my.connectionIndicators = {};
4573
 
4582
 
4583
+    // By default we use camera
4584
+    my.getVideoSize = getCameraVideoSize;
4585
+    my.getVideoPosition = getCameraVideoPosition;
4586
+
4574
     my.isInLastN = function(resource) {
4587
     my.isInLastN = function(resource) {
4575
         return lastNCount < 0 // lastN is disabled, return true
4588
         return lastNCount < 0 // lastN is disabled, return true
4576
             || (lastNCount > 0 && lastNEndpointsCache.length == 0) // lastNEndpoints cache not built yet, return true
4589
             || (lastNCount > 0 && lastNEndpointsCache.length == 0) // lastNEndpoints cache not built yet, return true
4856
 
4869
 
4857
                     // Change the way we'll be measuring and positioning large video
4870
                     // Change the way we'll be measuring and positioning large video
4858
 
4871
 
4859
-                    getVideoSize = largeVideoState.isDesktop
4872
+                    VideoLayout.getVideoSize = largeVideoState.isDesktop
4860
                         ? getDesktopVideoSize
4873
                         ? getDesktopVideoSize
4861
                         : getCameraVideoSize;
4874
                         : getCameraVideoSize;
4862
-                    getVideoPosition = largeVideoState.isDesktop
4875
+                    VideoLayout.getVideoPosition = largeVideoState.isDesktop
4863
                         ? getDesktopVideoPosition
4876
                         ? getDesktopVideoPosition
4864
                         : getCameraVideoPosition;
4877
                         : getCameraVideoPosition;
4865
 
4878
 
4993
         var videoSpaceWidth = $('#videospace').width();
5006
         var videoSpaceWidth = $('#videospace').width();
4994
         var videoSpaceHeight = window.innerHeight;
5007
         var videoSpaceHeight = window.innerHeight;
4995
 
5008
 
4996
-        var videoSize = getVideoSize(videoWidth,
5009
+        var videoSize = VideoLayout.getVideoSize(videoWidth,
4997
                                      videoHeight,
5010
                                      videoHeight,
4998
                                      videoSpaceWidth,
5011
                                      videoSpaceWidth,
4999
                                      videoSpaceHeight);
5012
                                      videoSpaceHeight);
5001
         var largeVideoWidth = videoSize[0];
5014
         var largeVideoWidth = videoSize[0];
5002
         var largeVideoHeight = videoSize[1];
5015
         var largeVideoHeight = videoSize[1];
5003
 
5016
 
5004
-        var videoPosition = getVideoPosition(largeVideoWidth,
5017
+        var videoPosition = VideoLayout.getVideoPosition(largeVideoWidth,
5005
                                              largeVideoHeight,
5018
                                              largeVideoHeight,
5006
                                              videoSpaceWidth,
5019
                                              videoSpaceWidth,
5007
                                              videoSpaceHeight);
5020
                                              videoSpaceHeight);
5842
                 status);
5855
                 status);
5843
         }
5856
         }
5844
 
5857
 
5845
-        if(APIConnector.isEnabled() && APIConnector.isEventEnabled("displayNameChange"))
5846
-        {
5847
-            if(jid === 'localVideoContainer')
5848
-                jid = connection.emuc.myroomjid;
5849
-            if(!name || name != displayName)
5850
-                APIConnector.triggerEvent("displayNameChange",{jid: jid, displayname: displayName});
5851
-        }
5858
+        if(jid === 'localVideoContainer')
5859
+            jid = connection.emuc.myroomjid;
5860
+        if(!name || name != displayName)
5861
+            API.triggerEvent("displayNameChange",{jid: jid, displayname: displayName});
5852
     });
5862
     });
5853
 
5863
 
5854
     /**
5864
     /**

+ 204
- 0
modules/API/API.js Ver arquivo

1
+/**
2
+ * Implements API class that communicates with external api class
3
+ * and provides interface to access Jitsi Meet features by external
4
+ * applications that embed Jitsi Meet
5
+ */
6
+
7
+
8
+
9
+/**
10
+ * List of the available commands.
11
+ * @type {{
12
+ *              displayName: inputDisplayNameHandler,
13
+ *              muteAudio: toggleAudio,
14
+ *              muteVideo: toggleVideo,
15
+ *              filmStrip: toggleFilmStrip
16
+ *          }}
17
+ */
18
+var commands =
19
+{
20
+    displayName: UI.inputDisplayNameHandler,
21
+    muteAudio: toggleAudio,
22
+    muteVideo: toggleVideo,
23
+    toggleFilmStrip: UI.toggleFilmStrip,
24
+    toggleChat: UI.toggleChat,
25
+    toggleContactList: UI.toggleContactList
26
+};
27
+
28
+
29
+/**
30
+ * Maps the supported events and their status
31
+ * (true it the event is enabled and false if it is disabled)
32
+ * @type {{
33
+ *              incomingMessage: boolean,
34
+ *              outgoingMessage: boolean,
35
+ *              displayNameChange: boolean,
36
+ *              participantJoined: boolean,
37
+ *              participantLeft: boolean
38
+ *      }}
39
+ */
40
+var events =
41
+{
42
+    incomingMessage: false,
43
+    outgoingMessage:false,
44
+    displayNameChange: false,
45
+    participantJoined: false,
46
+    participantLeft: false
47
+};
48
+
49
+/**
50
+ * Processes commands from external applicaiton.
51
+ * @param message the object with the command
52
+ */
53
+function processCommand(message)
54
+{
55
+    if(message.action != "execute")
56
+    {
57
+        console.error("Unknown action of the message");
58
+        return;
59
+    }
60
+    for(var key in message)
61
+    {
62
+        if(commands[key])
63
+            commands[key].apply(null, message[key]);
64
+    }
65
+}
66
+
67
+/**
68
+ * Processes events objects from external applications
69
+ * @param event the event
70
+ */
71
+function processEvent(event) {
72
+    if(!event.action)
73
+    {
74
+        console.error("Event with no action is received.");
75
+        return;
76
+    }
77
+
78
+    var i = 0;
79
+    switch(event.action)
80
+    {
81
+        case "add":
82
+            for(; i < event.events.length; i++)
83
+            {
84
+                events[event.events[i]] = true;
85
+            }
86
+            break;
87
+        case "remove":
88
+            for(; i < event.events.length; i++)
89
+            {
90
+                events[event.events[i]] = false;
91
+            }
92
+            break;
93
+        default:
94
+            console.error("Unknown action for event.");
95
+    }
96
+
97
+}
98
+
99
+/**
100
+ * Sends message to the external application.
101
+ * @param object
102
+ */
103
+function sendMessage(object) {
104
+    window.parent.postMessage(JSON.stringify(object), "*");
105
+}
106
+
107
+/**
108
+ * Processes a message event from the external application
109
+ * @param event the message event
110
+ */
111
+function processMessage(event)
112
+{
113
+    var message;
114
+    try {
115
+        message = JSON.parse(event.data);
116
+    } catch (e) {}
117
+
118
+    if(!message.type)
119
+        return;
120
+    switch (message.type)
121
+    {
122
+        case "command":
123
+            processCommand(message);
124
+            break;
125
+        case "event":
126
+            processEvent(message);
127
+            break;
128
+        default:
129
+            console.error("Unknown type of the message");
130
+            return;
131
+    }
132
+
133
+}
134
+
135
+var API = {
136
+    /**
137
+     * Check whether the API should be enabled or not.
138
+     * @returns {boolean}
139
+     */
140
+    isEnabled: function () {
141
+        var hash = location.hash;
142
+        if(hash && hash.indexOf("external") > -1 && window.postMessage)
143
+            return true;
144
+        return false;
145
+    },
146
+    /**
147
+     * Initializes the APIConnector. Setups message event listeners that will
148
+     * receive information from external applications that embed Jitsi Meet.
149
+     * It also sends a message to the external application that APIConnector
150
+     * is initialized.
151
+     */
152
+    init: function () {
153
+        if (window.addEventListener)
154
+        {
155
+            window.addEventListener('message',
156
+                processMessage, false);
157
+        }
158
+        else
159
+        {
160
+            window.attachEvent('onmessage', processMessage);
161
+        }
162
+        sendMessage({type: "system", loaded: true});
163
+    },
164
+    /**
165
+     * Checks whether the event is enabled ot not.
166
+     * @param name the name of the event.
167
+     * @returns {*}
168
+     */
169
+    isEventEnabled: function (name) {
170
+        return events[name];
171
+    },
172
+
173
+    /**
174
+     * Sends event object to the external application that has been subscribed
175
+     * for that event.
176
+     * @param name the name event
177
+     * @param object data associated with the event
178
+     */
179
+    triggerEvent: function (name, object) {
180
+        if(this.isEnabled() && this.isEventEnabled(name))
181
+            sendMessage({
182
+                type: "event", action: "result", event: name, result: object});
183
+    },
184
+
185
+    /**
186
+     * Removes the listeners.
187
+     */
188
+    dispose: function () {
189
+        if(window.removeEventListener)
190
+        {
191
+            window.removeEventListener("message",
192
+                processMessage, false);
193
+        }
194
+        else
195
+        {
196
+            window.detachEvent('onmessage', processMessage);
197
+        }
198
+
199
+    }
200
+
201
+
202
+};
203
+
204
+module.exports = API;

+ 0
- 6
modules/UI/UI.js Ver arquivo

460
 
460
 
461
     // Add Peer's container
461
     // Add Peer's container
462
     VideoLayout.ensurePeerContainerExists(jid,id);
462
     VideoLayout.ensurePeerContainerExists(jid,id);
463
-
464
-    if(APIConnector.isEnabled() &&
465
-        APIConnector.isEventEnabled("participantJoined"))
466
-    {
467
-        APIConnector.triggerEvent("participantJoined",{jid: jid});
468
-    }
469
 };
463
 };
470
 
464
 
471
 UI.onMucPresenceStatus = function ( jid, info) {
465
 UI.onMucPresenceStatus = function ( jid, info) {

+ 4
- 7
modules/UI/videolayout/VideoLayout.js Ver arquivo

1678
                 status);
1678
                 status);
1679
         }
1679
         }
1680
 
1680
 
1681
-        if(APIConnector.isEnabled() && APIConnector.isEventEnabled("displayNameChange"))
1682
-        {
1683
-            if(jid === 'localVideoContainer')
1684
-                jid = connection.emuc.myroomjid;
1685
-            if(!name || name != displayName)
1686
-                APIConnector.triggerEvent("displayNameChange",{jid: jid, displayname: displayName});
1687
-        }
1681
+        if(jid === 'localVideoContainer')
1682
+            jid = connection.emuc.myroomjid;
1683
+        if(!name || name != displayName)
1684
+            API.triggerEvent("displayNameChange",{jid: jid, displayname: displayName});
1688
     });
1685
     });
1689
 
1686
 
1690
     /**
1687
     /**

+ 6
- 14
muc.js Ver arquivo

199
                     id = email.text();
199
                     id = email.text();
200
                 }
200
                 }
201
                 UI.onMucEntered(from, id, member.displayName);
201
                 UI.onMucEntered(from, id, member.displayName);
202
+                API.triggerEvent("participantJoined",{jid: from});
202
             }
203
             }
203
         } else {
204
         } else {
204
             // Presence update for existing participant
205
             // Presence update for existing participant
278
             msg.c('nick', {xmlns: 'http://jabber.org/protocol/nick'}).t(nickname).up().up();
279
             msg.c('nick', {xmlns: 'http://jabber.org/protocol/nick'}).t(nickname).up().up();
279
         }
280
         }
280
         this.connection.send(msg);
281
         this.connection.send(msg);
281
-        if(APIConnector.isEnabled() && APIConnector.isEventEnabled("outgoingMessage"))
282
-        {
283
-            APIConnector.triggerEvent("outgoingMessage", {"message": body});
284
-        }
282
+        API.triggerEvent("outgoingMessage", {"message": body});
285
     },
283
     },
286
     setSubject: function (subject){
284
     setSubject: function (subject){
287
         var msg = $msg({to: this.roomjid, type: 'groupchat'});
285
         var msg = $msg({to: this.roomjid, type: 'groupchat'});
316
         if (txt) {
314
         if (txt) {
317
             console.log('chat', nick, txt);
315
             console.log('chat', nick, txt);
318
             UI.updateChatConversation(from, nick, txt);
316
             UI.updateChatConversation(from, nick, txt);
319
-            if(APIConnector.isEnabled() && APIConnector.isEventEnabled("incomingMessage"))
320
-            {
321
-                if(from != this.myroomjid)
322
-                    APIConnector.triggerEvent("incomingMessage",
323
-                        {"from": from, "nick": nick, "message": txt});
324
-            }
317
+            if(from != this.myroomjid)
318
+                API.triggerEvent("incomingMessage",
319
+                    {"from": from, "nick": nick, "message": txt});
325
         }
320
         }
326
         return true;
321
         return true;
327
     },
322
     },
537
     onParticipantLeft: function (jid) {
532
     onParticipantLeft: function (jid) {
538
         UI.onMucLeft(jid);
533
         UI.onMucLeft(jid);
539
 
534
 
540
-        if(APIConnector.isEnabled() && APIConnector.isEventEnabled("participantLeft"))
541
-        {
542
-            APIConnector.triggerEvent("participantLeft",{jid: jid});
543
-        }
535
+        API.triggerEvent("participantLeft",{jid: jid});
544
 
536
 
545
         delete jid2Ssrc[jid];
537
         delete jid2Ssrc[jid];
546
 
538
 

Carregando…
Cancelar
Salvar