(function(OCA, OC) {
'use strict';
OCA.SpreedMe = OCA.SpreedMe || {};
function SignalingBase(settings) {
this.settings = settings;
this.sessionId = '';
this.currentCallToken = null;
this.handlers = {};
this.features = {};
}
SignalingBase.prototype.on = function(ev, handler) {
if (!this.handlers.hasOwnProperty(ev)) {
this.handlers[ev] = [handler];
} else {
this.handlers[ev].push(handler);
}
switch (ev) {
case 'stunservers':
case 'turnservers':
var servers = this.settings[ev] || [];
if (servers.length) {
// The caller expects the handler to be called when the data
// is available, so defer to simulate a delayed response.
_.defer(function() {
handler(servers);
});
}
break;
}
};
SignalingBase.prototype._trigger = function(ev, args) {
var handlers = this.handlers[ev];
if (!handlers) {
return;
}
handlers = handlers.slice(0);
for (var i = 0, len = handlers.length; i < len; i++) {
var handler = handlers[i];
handler.apply(handler, args);
}
};
SignalingBase.prototype.getSessionid = function() {
return this.sessionId;
};
SignalingBase.prototype.disconnect = function() {
this.sessionId = '';
this.currentCallToken = null;
};
SignalingBase.prototype.hasFeature = function(feature) {
return this.features && this.features[feature];
};
SignalingBase