Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ node_modules
npm-debug.log

# *Storm
.idea/
.idea/*
671 changes: 0 additions & 671 deletions .idea/workspace.xml

This file was deleted.

69 changes: 51 additions & 18 deletions js/modules/webrtc/qbWebRTCClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var WebRTCSignalingProcessor = require('./qbWebRTCSignalingProcessor');
var WebRTCSignalingProvider = require('./qbWebRTCSignalingProvider');
var Helpers = require('./qbWebRTCHelpers');
var RTCPeerConnection = require('./qbRTCPeerConnection');
var SignalingConstants = require('./qbWebRTCSignalingConstants')

function WebRTCClient(service, connection) {
if (WebRTCClient.__instance) {
Expand Down Expand Up @@ -52,9 +53,13 @@ function WebRTCClient(service, connection) {
* @param {enum} Call type
*/
WebRTCClient.prototype.createNewSession = function(opponentsIDs, callType) {
var newSession = this._createAndStoreSession(null, Helpers.getIdFromNode(this.connection.jid), opponentsIDs, callType);
return newSession;
}

//if( !this.isExistActiveSession(this.sessions) ) {
return this._createAndStoreSession(null, Helpers.getIdFromNode(this.connection.jid), opponentsIDs, callType);
//} else {
//throw new Error('Session already have state "NEW" or "ACTIVE"');
//}
};

WebRTCClient.prototype._createAndStoreSession = function(sessionID, callerID, opponentsIDs, callType) {
var newSession = new WebRTCSession(sessionID, callerID, opponentsIDs, callType, this.signalingProvider, Helpers.getIdFromNode(this.connection.jid))
Expand All @@ -75,18 +80,36 @@ function WebRTCClient(service, connection) {
*/
WebRTCClient.prototype.clearSession = function(sessionId){
delete WebRTCClient.sessions[sessionId];
}

};

/**
* Checks is session active or not
* @param {string} Session ID
*/
WebRTCClient.prototype.isSessionActive = function(sessionId){
var session = WebRTCClient.sessions[sessionId];
return (session != null && session.state == WebRTCSession.State.ACTIVE);
var session = this.sessions[sessionId];

return (session != null && session.state == WebRTCSession.State.ACTIVE || session != null && session.state == WebRTCSession.State.NEW);
};

/**
* Check all session and check theirs state
* @param {object} sessions
* @returns {boolean} is active call exist
*/
WebRTCClient.prototype.isExistActiveSession = function(sessions){
var self = this,
ans = false;

if(Object.keys(sessions).length > 0) {
for(var i in sessions) {
if( self.isSessionActive(sessions[i].ID) ) { ans = true; break; }
}
}

return ans;
};

/**
* Checks is session rejected or not
* @param {string} Session ID
Expand All @@ -112,20 +135,30 @@ function WebRTCClient(service, connection) {


WebRTCClient.prototype._onCallListener = function(userID, sessionID, extension) {
Helpers.trace("onCall. UserID:" + userID + ". SessionID: " + sessionID);
var self = this,
session = self.sessions[sessionID];

var session = this.sessions[sessionID];
if(!session){
session = this._createAndStoreSession(sessionID, extension.callerID, extension.opponentsIDs, extension.callType);

var extensionClone = JSON.parse(JSON.stringify(extension));
this._cleanupExtension(extensionClone);
Helpers.trace("onCall. UserID:" + userID + ". SessionID: " + sessionID);

if (typeof this.onCallListener === 'function'){
this.onCallListener(session, extensionClone);
if( self.isExistActiveSession(self.sessions) ) {
Helpers.trace('User with id ' + userID + 'is busy at now.');
/* session id */
extension["sessionID"] = sessionID;
self.signalingProvider.sendMessage(userID, extension, SignalingConstants.SignalingType.REJECT);
} else {
if(!session){
session = this._createAndStoreSession(sessionID, extension.callerID, extension.opponentsIDs, extension.callType);

var extensionClone = JSON.parse(JSON.stringify(extension));
this._cleanupExtension(extensionClone);

if (typeof this.onCallListener === 'function'){
this.onCallListener(session, extensionClone);
}
}

session.processOnCall(userID, extension);
}
session.processOnCall(userID, extension);
};

WebRTCClient.prototype._onAcceptListener = function(userID, sessionID, extension) {
Expand Down Expand Up @@ -212,6 +245,6 @@ WebRTCClient.prototype._cleanupExtension = function(extension){
delete extension.opponentsIDs;
delete extension.callerID;
delete extension.callType;
}
};

module.exports = WebRTCClient;
71 changes: 52 additions & 19 deletions quickblox.js
Original file line number Diff line number Diff line change
Expand Up @@ -2156,6 +2156,7 @@ var WebRTCSignalingProcessor = require('./qbWebRTCSignalingProcessor');
var WebRTCSignalingProvider = require('./qbWebRTCSignalingProvider');
var Helpers = require('./qbWebRTCHelpers');
var RTCPeerConnection = require('./qbRTCPeerConnection');
var SignalingConstants = require('./qbWebRTCSignalingConstants')

function WebRTCClient(service, connection) {
if (WebRTCClient.__instance) {
Expand Down Expand Up @@ -2189,9 +2190,13 @@ function WebRTCClient(service, connection) {
* @param {enum} Call type
*/
WebRTCClient.prototype.createNewSession = function(opponentsIDs, callType) {
var newSession = this._createAndStoreSession(null, Helpers.getIdFromNode(this.connection.jid), opponentsIDs, callType);
return newSession;
}

//if( !this.isExistActiveSession(this.sessions) ) {
return this._createAndStoreSession(null, Helpers.getIdFromNode(this.connection.jid), opponentsIDs, callType);
//} else {
//throw new Error('Session already have state "NEW" or "ACTIVE"');
//}
};

WebRTCClient.prototype._createAndStoreSession = function(sessionID, callerID, opponentsIDs, callType) {
var newSession = new WebRTCSession(sessionID, callerID, opponentsIDs, callType, this.signalingProvider, Helpers.getIdFromNode(this.connection.jid))
Expand All @@ -2212,18 +2217,36 @@ function WebRTCClient(service, connection) {
*/
WebRTCClient.prototype.clearSession = function(sessionId){
delete WebRTCClient.sessions[sessionId];
}

};

/**
* Checks is session active or not
* @param {string} Session ID
*/
WebRTCClient.prototype.isSessionActive = function(sessionId){
var session = WebRTCClient.sessions[sessionId];
return (session != null && session.state == WebRTCSession.State.ACTIVE);
var session = this.sessions[sessionId];

return (session != null && session.state == WebRTCSession.State.ACTIVE || session != null && session.state == WebRTCSession.State.NEW);
};

/**
* Check all session and check theirs state
* @param {object} sessions
* @returns {boolean} is active call exist
*/
WebRTCClient.prototype.isExistActiveSession = function(sessions){
var self = this,
ans = false;

if(Object.keys(sessions).length > 0) {
for(var i in sessions) {
if( self.isSessionActive(sessions[i].ID) ) { ans = true; break; }
}
}

return ans;
};

/**
* Checks is session rejected or not
* @param {string} Session ID
Expand All @@ -2249,20 +2272,30 @@ function WebRTCClient(service, connection) {


WebRTCClient.prototype._onCallListener = function(userID, sessionID, extension) {
var self = this,
session = self.sessions[sessionID];

Helpers.trace("onCall. UserID:" + userID + ". SessionID: " + sessionID);

var session = this.sessions[sessionID];
if(!session){
session = this._createAndStoreSession(sessionID, extension.callerID, extension.opponentsIDs, extension.callType);
if( self.isExistActiveSession(self.sessions) ) {
Helpers.trace('User with id ' + userID + 'is busy at now.');
/* session id */
extension["sessionID"] = sessionID;
self.signalingProvider.sendMessage(userID, extension, SignalingConstants.SignalingType.REJECT);
} else {
if(!session){
session = this._createAndStoreSession(sessionID, extension.callerID, extension.opponentsIDs, extension.callType);

var extensionClone = JSON.parse(JSON.stringify(extension));
this._cleanupExtension(extensionClone);
var extensionClone = JSON.parse(JSON.stringify(extension));
this._cleanupExtension(extensionClone);

if (typeof this.onCallListener === 'function'){
this.onCallListener(session, extensionClone);
if (typeof this.onCallListener === 'function'){
this.onCallListener(session, extensionClone);
}
}

session.processOnCall(userID, extension);
}
session.processOnCall(userID, extension);
};

WebRTCClient.prototype._onAcceptListener = function(userID, sessionID, extension) {
Expand Down Expand Up @@ -2349,11 +2382,11 @@ WebRTCClient.prototype._cleanupExtension = function(extension){
delete extension.opponentsIDs;
delete extension.callerID;
delete extension.callType;
}
};

module.exports = WebRTCClient;

},{"./qbRTCPeerConnection":8,"./qbWebRTCHelpers":10,"./qbWebRTCSession":11,"./qbWebRTCSignalingProcessor":13,"./qbWebRTCSignalingProvider":14}],10:[function(require,module,exports){
},{"./qbRTCPeerConnection":8,"./qbWebRTCHelpers":10,"./qbWebRTCSession":11,"./qbWebRTCSignalingConstants":12,"./qbWebRTCSignalingProcessor":13,"./qbWebRTCSignalingProvider":14}],10:[function(require,module,exports){
/*
* QuickBlox JavaScript SDK
*
Expand Down Expand Up @@ -8159,8 +8192,8 @@ exports.isBuffer = isBuffer;
function objectToString(o) {
return Object.prototype.toString.call(o);
}
}).call(this,{"isBuffer":require("/Users/igorkhomenko/workspace/quickblox-javascript-sdk/node_modules/grunt-browserify/node_modules/browserify/node_modules/insert-module-globals/node_modules/is-buffer/index.js")})
},{"/Users/igorkhomenko/workspace/quickblox-javascript-sdk/node_modules/grunt-browserify/node_modules/browserify/node_modules/insert-module-globals/node_modules/is-buffer/index.js":34}],44:[function(require,module,exports){
}).call(this,{"isBuffer":require("C:\\OpenServer\\domains\\quickblox-javascript-sdk\\node_modules\\grunt-browserify\\node_modules\\browserify\\node_modules\\insert-module-globals\\node_modules\\is-buffer\\index.js")})
},{"C:\\OpenServer\\domains\\quickblox-javascript-sdk\\node_modules\\grunt-browserify\\node_modules\\browserify\\node_modules\\insert-module-globals\\node_modules\\is-buffer\\index.js":34}],44:[function(require,module,exports){
module.exports = require("./lib/_stream_passthrough.js")

},{"./lib/_stream_passthrough.js":39}],45:[function(require,module,exports){
Expand Down
16 changes: 8 additions & 8 deletions quickblox.min.js

Large diffs are not rendered by default.

65 changes: 37 additions & 28 deletions samples/webrtc/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ $(document).ready(function() {
// Audio call
//
$('#audiocall').on('click', function() {
/* $('#audiocall, #videocall').attr('disabled', 'disabled'); */

if(Object.keys(callees).length == 0){
alert('Please choose users to call');
return;
Expand All @@ -74,6 +76,8 @@ $(document).ready(function() {
// Video call
//
$('#videocall').on('click', function() {
/* $('#audiocall, #videocall').attr('disabled', 'disabled'); */

if(Object.keys(callees).length == 0){
alert('Please choose users to call');
return;
Expand Down Expand Up @@ -313,37 +317,42 @@ function callWithParams(mediaParams, isOnlyAudio){
// create a session
//
currentSession = QB.webrtc.createNewSession(Object.keys(callees), isOnlyAudio ? QB.webrtc.CallType.AUDIO : QB.webrtc.CallType.VIDEO);
console.log("Session: " + currentSession);

// get local stream
//
currentSession.getUserMedia(mediaParams, function(err, stream) {
if (err) {
console.log(err);
updateInfoMessage('Error: devices (camera or microphone) are not found');
/**
* Check session
*/
//if( currentSession ) {
// get local stream
//

} else {
setupVolumeMeter(stream);

$('.btn_mediacall, #hangup').removeAttr('disabled');
$('#audiocall, #videocall').attr('disabled', 'disabled');
updateInfoMessage('Calling...');
$('#callingSignal')[0].play();

// create video elements for opponents
//
Object.keys(callees).forEach(function(userID, i, arr) {
var videoEl = "<video class='remoteVideoClass' id='remoteVideo_" + userID + "'></video>";
$(videoEl).appendTo('.remoteControls');
});
currentSession.getUserMedia(mediaParams, function(err, stream) {
if (err) {
updateInfoMessage('Error: devices (camera or microphone) are not found');

// start call
//
var extension = {
};
currentSession.call(extension);
}
});
} else {

setupVolumeMeter(stream);

$('.btn_mediacall, #hangup').removeAttr('disabled');
$('#audiocall, #videocall').attr('disabled', 'disabled');
updateInfoMessage('Calling...');
$('#callingSignal')[0].play();

// create video elements for opponents
//
Object.keys(callees).forEach(function(userID, i, arr) {
var videoEl = "<video class='remoteVideoClass' id='remoteVideo_" + userID + "'></video>";
$(videoEl).appendTo('.remoteControls');
});

// start call
//
var extension = {
};
currentSession.call(extension);
}
});
//}
}

function clearRemoteVideoView(userID){
Expand Down
Loading