Skip to content
Merged
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
8 changes: 8 additions & 0 deletions js/modules/webrtc/qbWebRTCSession.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,14 @@ WebRTCSession.prototype.accept = function(extension) {

Helpers.trace('Accept, extension: ' + JSON.stringify(ext));

/*
* Check state of current session
*/
if(self.state === WebRTCSession.State.ACTIVE) {
Helpers.traceError('Session already active');
return;
}

self.state = WebRTCSession.State.ACTIVE;

self._clearAnswerTimer();
Expand Down
12 changes: 10 additions & 2 deletions quickblox.js
Original file line number Diff line number Diff line change
Expand Up @@ -2809,6 +2809,14 @@ WebRTCSession.prototype.accept = function(extension) {

Helpers.trace('Accept, extension: ' + JSON.stringify(ext));

/*
* Check state of current session
*/
if(self.state === WebRTCSession.State.ACTIVE) {
Helpers.traceError('Session already active');
return;
}

self.state = WebRTCSession.State.ACTIVE;

self._clearAnswerTimer();
Expand Down Expand Up @@ -8352,8 +8360,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\\qb-WEBSDK\\node_modules\\grunt-browserify\\node_modules\\browserify\\node_modules\\insert-module-globals\\node_modules\\is-buffer\\index.js")})
},{"C:\\OpenServer\\domains\\qb-WEBSDK\\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
12 changes: 6 additions & 6 deletions quickblox.min.js

Large diffs are not rendered by default.

151 changes: 83 additions & 68 deletions samples/webrtc/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,66 +119,74 @@ $(document).ready(function() {
// Accept call
//
$('#accept').on('click', function() {
$('#incomingCall').modal('hide');
$('#ringtoneSignal')[0].pause();

var mediaParams = {
audio: true,
video: currentSession.callType === 1 ? true : false,
// video: {
// mandatory: {
// maxWidth: 1280,
// maxHeight: 720,
// minWidth: 1280,
// minHeight: 720
// }
// },
elemId: 'localVideo',
options: {
muted: true,
mirror: true
}
};

currentSession.getUserMedia(mediaParams, function(err, stream) {
if (err) {
console.log(err);
var deviceNotFoundError = 'Devices are not found';
updateInfoMessage(deviceNotFoundError);

} else {
// create video elements for opponents
//
var opponents = [currentSession.initiatorID];
currentSession.opponentsIDs.forEach(function(userID, i, arr) {
if(userID != currentSession.currentUserID){
opponents.push(userID);
}
});
//
opponents.forEach(function(userID, i, arr) {
var videoEl = "<video class='remoteVideoClass' id='remoteVideo_" + userID + "'></video>";
$(videoEl).appendTo('.remoteControls');

var peerState = currentSession.connectionStateForUser(userID);
if(peerState === QB.webrtc.PeerConnectionState.CLOSED){
clearRemoteVideoView(userID);
}
});


setupVolumeMeter(stream);

$('.btn_mediacall, #hangup').removeAttr('disabled');
$('#audiocall, #videocall, #screen_sharing').attr('disabled', 'disabled');
var $popupIncomingCall = $('#incomingCall');

if(currentSession.state !== QB.webrtc.SessionConnectionState.CONNECTED) {
$popupIncomingCall.modal('hide');
$('#ringtoneSignal')[0].pause();

var mediaParams = {
audio: true,
video: currentSession.callType === 1 ? true : false,
// video: {
// mandatory: {
// maxWidth: 1280,
// maxHeight: 720,
// minWidth: 1280,
// minHeight: 720
// }
// },
elemId: 'localVideo',
options: {
muted: true,
mirror: true
}
};

var extension = {};
currentSession.accept(extension);
}
});
currentSession.getUserMedia(mediaParams, function(err, stream) {

if (err) {
console.log(err);
var deviceNotFoundError = 'Devices are not found';
updateInfoMessage(deviceNotFoundError);

} else {
// create video elements for opponents
//

var opponents = [currentSession.initiatorID];
currentSession.opponentsIDs.forEach(function(userID, i, arr) {
if(userID != currentSession.currentUserID){
opponents.push(userID);
}
});
//
opponents.forEach(function(userID, i, arr) {
if(!checkVideoEl(userID)) {
var videoEl = "<video class='remoteVideoClass' id='remoteVideo_" + userID + "'></video>";
$(videoEl).appendTo('.remoteControls');

var peerState = currentSession.connectionStateForUser(userID);
if(peerState === QB.webrtc.PeerConnectionState.CLOSED){
clearRemoteVideoView(userID);
}
}
});

setupVolumeMeter(stream);

$('.btn_mediacall, #hangup').removeAttr('disabled');
$('#audiocall, #videocall, #screen_sharing').attr('disabled', 'disabled');

var extension = {};
currentSession.accept(extension);
}
});
} else {
$popupIncomingCall.modal('hide');
}
});


// Reject
//
$('#reject').on('click', function() {
Expand Down Expand Up @@ -501,20 +509,22 @@ function setupVolumeMeter(localStream){

function drawLoop(time) {
// clear the background
canvasContext.clearRect(0, 0, METER_WIDTH, METER_HEIGHT);
if(canvasContext) {
canvasContext.clearRect(0, 0, METER_WIDTH, METER_HEIGHT);

// check if we're currently clipping
if (meter.checkClipping()){
canvasContext.fillStyle = "red";
}else{
canvasContext.fillStyle = "green";
}
// check if we're currently clipping
if (meter.checkClipping()){
canvasContext.fillStyle = "red";
}else{
canvasContext.fillStyle = "green";
}

// draw a bar based on the current volume
canvasContext.fillRect(0, 0, meter.volume * METER_WIDTH * 1.4, METER_HEIGHT);
// draw a bar based on the current volume
canvasContext.fillRect(0, 0, meter.volume * METER_WIDTH * 1.4, METER_HEIGHT);

// set up the next visual callback
animationRequestID = window.requestAnimationFrame(drawLoop);
// set up the next visual callback
animationRequestID = window.requestAnimationFrame(drawLoop);
}
}

function clearVolumeMeter() {
Expand All @@ -529,3 +539,8 @@ function clearVolumeMeter() {
mediaStreamSource = null;
meter = null;
}

function checkVideoEl(userID) {
var videoEl = document.getElementById('remoteVideo_' + userID);
return (videoEl !== null);
}