Browse Source

Removes duplication. Allows automated functional testing to access the WebRTC data channels.

master
Lyubomir Marinov 9 years ago
parent
commit
c992222c70
2 changed files with 61 additions and 37 deletions
  1. 57
    37
      modules/RTC/DataChannels.js
  2. 4
    0
      modules/RTC/RTC.js

+ 57
- 37
modules/RTC/DataChannels.js View File

@@ -8,7 +8,6 @@ var RTCEvents = require("../../service/RTC/RTCEvents");
8 8
 var _dataChannels = [];
9 9
 var eventEmitter = null;
10 10
 
11
-
12 11
 var DataChannels = {
13 12
     /**
14 13
      * Callback triggered by PeerConnection when new data channel is opened
@@ -99,6 +98,11 @@ var DataChannels = {
99 98
                 }
100 99
                 else {
101 100
                     console.debug("Data channel JSON-formatted message: ", obj);
101
+                    // The received message appears to be appropriately
102
+                    // formatted (i.e. is a JSON object which assigns a value to
103
+                    // the mandatory property colibriClass) so don't just
104
+                    // swallow it, expose it to public consumption.
105
+                    eventEmitter.emit("rtc.datachannel." + colibriClass, obj);
102 106
                 }
103 107
             }
104 108
         };
@@ -146,45 +150,61 @@ var DataChannels = {
146 150
          console.info("Got My Data Channel Message:", msgData, dataChannel);
147 151
          };*/
148 152
     },
149
-    handleSelectedEndpointEvent: onSelectedEndpointChanged,
150
-    handlePinnedEndpointEvent: onPinnedEndpointChanged
151
-};
152 153
 
153
-function onSelectedEndpointChanged(userResource) {
154
-    console.log('selected endpoint changed: ', userResource);
155
-    if (_dataChannels && _dataChannels.length !== 0) {
156
-        _dataChannels.some(function (dataChannel) {
157
-            if (dataChannel.readyState == 'open') {
158
-                console.log('sending selected endpoint changed ' +
159
-                    'notification to the bridge: ', userResource);
160
-                dataChannel.send(JSON.stringify({
161
-                    'colibriClass': 'SelectedEndpointChangedEvent',
162
-                    'selectedEndpoint':
163
-                        (!userResource || userResource === null)?
164
-                            null : userResource
165
-                }));
166
-
167
-                return true;
168
-            }
169
-        });
170
-    }
171
-}
154
+    handleSelectedEndpointEvent: function (userResource) {
155
+        onXXXEndpointChanged("selected", userResource);
156
+    },
157
+    handlePinnedEndpointEvent: function (userResource) {
158
+        onXXXEndpointChanged("pinned", userResource);
159
+    },
172 160
 
173
-function onPinnedEndpointChanged(userResource) {
174
-    console.log('pinned endpoint changed: ', userResource);
175
-    if (_dataChannels && _dataChannels.length !== 0) {
176
-        _dataChannels.some(function (dataChannel) {
177
-            if (dataChannel.readyState == 'open') {
178
-                dataChannel.send(JSON.stringify({
179
-                    'colibriClass': 'PinnedEndpointChangedEvent',
180
-                    'pinnedEndpoint':
181
-                        userResource ? userResource : null
182
-                }));
183
-
184
-                return true;
185
-            }
186
-        });
161
+    some: function (callback, thisArg) {
162
+        if (_dataChannels && _dataChannels.length !== 0) {
163
+            if (thisArg)
164
+                return _dataChannels.some(callback, thisArg);
165
+            else
166
+                return _dataChannels.some(callback);
167
+        } else {
168
+            return false;
169
+        }
187 170
     }
171
+};
172
+
173
+/**
174
+ * Notifies Videobridge about a change in the value of a specific
175
+ * endpoint-related property such as selected endpoint and pinnned endpoint.
176
+ *
177
+ * @param xxx the name of the endpoint-related property whose value changed
178
+ * @param userResource the new value of the endpoint-related property after the
179
+ * change
180
+ */
181
+function onXXXEndpointChanged(xxx, userResource) {
182
+    // Derive the correct words from xxx such as selected and Selected, pinned
183
+    // and Pinned.
184
+    var head = xxx.charAt(0);
185
+    var tail = xxx.substring(1);
186
+    var lower = head.toLowerCase() + tail;
187
+    var upper = head.toUpperCase() + tail;
188
+
189
+    // Notify Videobridge about the specified endpoint change.
190
+    console.log(lower + ' endpoint changed: ', userResource);
191
+    DataChannels.some(function (dataChannel) {
192
+        if (dataChannel.readyState == 'open') {
193
+            console.log(
194
+                    'sending ' + lower
195
+                        + ' endpoint changed notification to the bridge: ',
196
+                    userResource);
197
+
198
+            var jsonObject = {};
199
+
200
+            jsonObject.colibriClass = (upper + 'EndpointChangedEvent');
201
+            jsonObject[lower + "Endpoint"]
202
+                = (userResource ? userResource : null);
203
+            dataChannel.send(JSON.stringify(jsonObject));
204
+
205
+            return true;
206
+        }
207
+    });
188 208
 }
189 209
 
190 210
 module.exports = DataChannels;

+ 4
- 0
modules/RTC/RTC.js View File

@@ -44,6 +44,10 @@ function getMediaStreamUsage()
44 44
 }
45 45
 
46 46
 var RTC = {
47
+    // Exposes DataChannels to public consumption (e.g. jitsi-meet-torture)
48
+    // without the necessity to require the module.
49
+    "DataChannels": DataChannels,
50
+
47 51
     rtcUtils: null,
48 52
     devices: {
49 53
         audio: true,

Loading…
Cancel
Save