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

This commit is contained in:
Lyubomir Marinov 2015-09-22 18:51:24 -05:00
parent 506d0722bd
commit c992222c70
2 changed files with 59 additions and 35 deletions

View File

@ -8,7 +8,6 @@ var RTCEvents = require("../../service/RTC/RTCEvents");
var _dataChannels = [];
var eventEmitter = null;
var DataChannels = {
/**
* Callback triggered by PeerConnection when new data channel is opened
@ -99,6 +98,11 @@ var DataChannels = {
}
else {
console.debug("Data channel JSON-formatted message: ", obj);
// The received message appears to be appropriately
// formatted (i.e. is a JSON object which assigns a value to
// the mandatory property colibriClass) so don't just
// swallow it, expose it to public consumption.
eventEmitter.emit("rtc.datachannel." + colibriClass, obj);
}
}
};
@ -146,45 +150,61 @@ var DataChannels = {
console.info("Got My Data Channel Message:", msgData, dataChannel);
};*/
},
handleSelectedEndpointEvent: onSelectedEndpointChanged,
handlePinnedEndpointEvent: onPinnedEndpointChanged
handleSelectedEndpointEvent: function (userResource) {
onXXXEndpointChanged("selected", userResource);
},
handlePinnedEndpointEvent: function (userResource) {
onXXXEndpointChanged("pinned", userResource);
},
some: function (callback, thisArg) {
if (_dataChannels && _dataChannels.length !== 0) {
if (thisArg)
return _dataChannels.some(callback, thisArg);
else
return _dataChannels.some(callback);
} else {
return false;
}
}
};
function onSelectedEndpointChanged(userResource) {
console.log('selected endpoint changed: ', userResource);
if (_dataChannels && _dataChannels.length !== 0) {
_dataChannels.some(function (dataChannel) {
if (dataChannel.readyState == 'open') {
console.log('sending selected endpoint changed ' +
'notification to the bridge: ', userResource);
dataChannel.send(JSON.stringify({
'colibriClass': 'SelectedEndpointChangedEvent',
'selectedEndpoint':
(!userResource || userResource === null)?
null : userResource
}));
/**
* Notifies Videobridge about a change in the value of a specific
* endpoint-related property such as selected endpoint and pinnned endpoint.
*
* @param xxx the name of the endpoint-related property whose value changed
* @param userResource the new value of the endpoint-related property after the
* change
*/
function onXXXEndpointChanged(xxx, userResource) {
// Derive the correct words from xxx such as selected and Selected, pinned
// and Pinned.
var head = xxx.charAt(0);
var tail = xxx.substring(1);
var lower = head.toLowerCase() + tail;
var upper = head.toUpperCase() + tail;
return true;
}
});
}
}
// Notify Videobridge about the specified endpoint change.
console.log(lower + ' endpoint changed: ', userResource);
DataChannels.some(function (dataChannel) {
if (dataChannel.readyState == 'open') {
console.log(
'sending ' + lower
+ ' endpoint changed notification to the bridge: ',
userResource);
function onPinnedEndpointChanged(userResource) {
console.log('pinned endpoint changed: ', userResource);
if (_dataChannels && _dataChannels.length !== 0) {
_dataChannels.some(function (dataChannel) {
if (dataChannel.readyState == 'open') {
dataChannel.send(JSON.stringify({
'colibriClass': 'PinnedEndpointChangedEvent',
'pinnedEndpoint':
userResource ? userResource : null
}));
var jsonObject = {};
return true;
}
});
}
jsonObject.colibriClass = (upper + 'EndpointChangedEvent');
jsonObject[lower + "Endpoint"]
= (userResource ? userResource : null);
dataChannel.send(JSON.stringify(jsonObject));
return true;
}
});
}
module.exports = DataChannels;

View File

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