|
|
|
@ -26,8 +26,7 @@ define(['jquery', 'underscore', 'text!partials/audiovideo.html', 'text!partials/ |
|
|
|
|
|
|
|
|
|
|
|
var controller = ['$scope', '$element', '$attrs', function($scope, $element, $attrs) { |
|
|
|
var controller = ['$scope', '$element', '$attrs', function($scope, $element, $attrs) { |
|
|
|
|
|
|
|
|
|
|
|
var peers = {}; |
|
|
|
var streams = {}; |
|
|
|
var events = $({}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$scope.container = $element.get(0); |
|
|
|
$scope.container = $element.get(0); |
|
|
|
$scope.layoutparent = $element.parent(); |
|
|
|
$scope.layoutparent = $element.parent(); |
|
|
|
@ -39,6 +38,9 @@ define(['jquery', 'underscore', 'text!partials/audiovideo.html', 'text!partials/ |
|
|
|
|
|
|
|
|
|
|
|
$scope.hasUsermedia = false; |
|
|
|
$scope.hasUsermedia = false; |
|
|
|
$scope.isActive = false; |
|
|
|
$scope.isActive = false; |
|
|
|
|
|
|
|
$scope.haveStreams = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$scope.peersTalking = {}; |
|
|
|
|
|
|
|
|
|
|
|
$scope.rendererName = $scope.defaultRendererName = "democrazy"; |
|
|
|
$scope.rendererName = $scope.defaultRendererName = "democrazy"; |
|
|
|
|
|
|
|
|
|
|
|
@ -46,31 +48,30 @@ define(['jquery', 'underscore', 'text!partials/audiovideo.html', 'text!partials/ |
|
|
|
|
|
|
|
|
|
|
|
$scope.addRemoteStream = function(stream, currentcall) { |
|
|
|
$scope.addRemoteStream = function(stream, currentcall) { |
|
|
|
|
|
|
|
|
|
|
|
//console.log("Add remote stream to scope", pc.id, stream);
|
|
|
|
if (streams.hasOwnProperty(stream.id)) { |
|
|
|
|
|
|
|
console.warn("Cowardly refusing to add stream id twice", stream.id, currentcall); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//console.log("Add remote stream to scope", stream.id, stream, currentcall);
|
|
|
|
// Create scope.
|
|
|
|
// Create scope.
|
|
|
|
var subscope = $scope.$new(true); |
|
|
|
var subscope = $scope.$new(); |
|
|
|
var peerid = subscope.peerid = currentcall.id; |
|
|
|
var peerid = subscope.peerid = currentcall.id; |
|
|
|
buddyData.push(peerid); |
|
|
|
buddyData.push(peerid); |
|
|
|
subscope.withvideo = false; |
|
|
|
subscope.withvideo = false; |
|
|
|
subscope.onlyaudio = false; |
|
|
|
subscope.onlyaudio = false; |
|
|
|
subscope.talking = false; |
|
|
|
|
|
|
|
subscope.destroyed = false; |
|
|
|
subscope.destroyed = false; |
|
|
|
subscope.applyTalking = function(talking) { |
|
|
|
|
|
|
|
subscope.talking = !! talking; |
|
|
|
|
|
|
|
safeApply(subscope); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
subscope.$on("active", function() { |
|
|
|
subscope.$on("active", function() { |
|
|
|
console.log("Stream scope is now active", peerid); |
|
|
|
console.log("Stream scope is now active", stream.id, peerid); |
|
|
|
events.triggerHandler("active." + peerid, [subscope, currentcall, stream]); |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
subscope.$on("$destroy", function() { |
|
|
|
subscope.$on("$destroy", function() { |
|
|
|
console.log("Destroyed scope for audiovideo", subscope); |
|
|
|
console.log("Destroyed scope for stream", stream.id, peerid); |
|
|
|
subscope.destroyed = true; |
|
|
|
subscope.destroyed = true; |
|
|
|
}); |
|
|
|
}); |
|
|
|
console.log("Created stream scope", peerid); |
|
|
|
console.log("Created stream scope", stream.id, peerid); |
|
|
|
|
|
|
|
|
|
|
|
// Add created scope.
|
|
|
|
// Add created scope.
|
|
|
|
peers[peerid] = subscope; |
|
|
|
streams[stream.id] = subscope; |
|
|
|
|
|
|
|
|
|
|
|
// Render template.
|
|
|
|
// Render template.
|
|
|
|
peerTemplate(subscope, function(clonedElement, scope) { |
|
|
|
peerTemplate(subscope, function(clonedElement, scope) { |
|
|
|
@ -118,10 +119,11 @@ define(['jquery', 'underscore', 'text!partials/audiovideo.html', 'text!partials/ |
|
|
|
|
|
|
|
|
|
|
|
$scope.removeRemoteStream = function(stream, currentcall) { |
|
|
|
$scope.removeRemoteStream = function(stream, currentcall) { |
|
|
|
|
|
|
|
|
|
|
|
var subscope = peers[currentcall.id]; |
|
|
|
//console.log("remove stream", stream, stream.id, currentcall);
|
|
|
|
|
|
|
|
var subscope = streams[stream.id]; |
|
|
|
if (subscope) { |
|
|
|
if (subscope) { |
|
|
|
buddyData.pop(currentcall.id); |
|
|
|
buddyData.pop(currentcall.id); |
|
|
|
delete peers[currentcall.id]; |
|
|
|
delete streams[stream.id]; |
|
|
|
//console.log("remove scope", subscope);
|
|
|
|
//console.log("remove scope", subscope);
|
|
|
|
if (subscope.element) { |
|
|
|
if (subscope.element) { |
|
|
|
subscope.element.remove(); |
|
|
|
subscope.element.remove(); |
|
|
|
@ -134,17 +136,9 @@ define(['jquery', 'underscore', 'text!partials/audiovideo.html', 'text!partials/ |
|
|
|
|
|
|
|
|
|
|
|
// Talking updates receiver.
|
|
|
|
// Talking updates receiver.
|
|
|
|
mediaStream.api.e.on("received.talking", function(event, id, from, talking) { |
|
|
|
mediaStream.api.e.on("received.talking", function(event, id, from, talking) { |
|
|
|
var scope = peers[from]; |
|
|
|
$scope.$apply(function(scope) { |
|
|
|
//console.log("received.talking", talking, scope);
|
|
|
|
scope.peersTalking[from] = !!talking; |
|
|
|
if (scope) { |
|
|
|
}); |
|
|
|
scope.applyTalking(talking); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
console.log("Received talking state without scope -> adding event.", from, talking); |
|
|
|
|
|
|
|
events.one("active." + from, function(event, scope) { |
|
|
|
|
|
|
|
console.log("Applying previously received talking state", from, talking); |
|
|
|
|
|
|
|
scope.applyTalking(talking); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
$scope.$on("active", function(currentcall) { |
|
|
|
$scope.$on("active", function(currentcall) { |
|
|
|
@ -177,27 +171,36 @@ define(['jquery', 'underscore', 'text!partials/audiovideo.html', 'text!partials/ |
|
|
|
|
|
|
|
|
|
|
|
mediaStream.webrtc.e.on("usermedia", function(event, usermedia) { |
|
|
|
mediaStream.webrtc.e.on("usermedia", function(event, usermedia) { |
|
|
|
|
|
|
|
|
|
|
|
//console.log("XXXXXXXXXXXXXXXXXXXXXXXXX usermedia event", usermedia);
|
|
|
|
//console.log("XXXX XXXXXXXXXXXXXXXXXXXXX usermedia event", usermedia);
|
|
|
|
$scope.hasUsermedia = true; |
|
|
|
if ($scope.haveStreams) { |
|
|
|
usermedia.attachMediaStream($scope.localVideo); |
|
|
|
|
|
|
|
var count = 0; |
|
|
|
usermedia.attachMediaStream($scope.miniVideo); |
|
|
|
var waitForLocalVideo = function() { |
|
|
|
$scope.redraw(); |
|
|
|
if (!$scope.hasUsermedia) { |
|
|
|
|
|
|
|
return; |
|
|
|
} else { |
|
|
|
} |
|
|
|
|
|
|
|
if ($scope.localVideo.videoWidth > 0) { |
|
|
|
$scope.hasUsermedia = true; |
|
|
|
$scope.localVideo.style.opacity = 1; |
|
|
|
usermedia.attachMediaStream($scope.localVideo); |
|
|
|
$scope.redraw(); |
|
|
|
var count = 0; |
|
|
|
} else { |
|
|
|
var waitForLocalVideo = function() { |
|
|
|
count++; |
|
|
|
if (!$scope.hasUsermedia) { |
|
|
|
if (count < 100) { |
|
|
|
return; |
|
|
|
setTimeout(waitForLocalVideo, 100); |
|
|
|
} |
|
|
|
|
|
|
|
if ($scope.localVideo.videoWidth > 0) { |
|
|
|
|
|
|
|
$scope.localVideo.style.opacity = 1; |
|
|
|
|
|
|
|
$scope.redraw(); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
console.warn("Timeout while waiting for local video.") |
|
|
|
count++; |
|
|
|
|
|
|
|
if (count < 100) { |
|
|
|
|
|
|
|
setTimeout(waitForLocalVideo, 100); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
console.warn("Timeout while waiting for local video.") |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
waitForLocalVideo(); |
|
|
|
waitForLocalVideo(); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
@ -205,6 +208,7 @@ define(['jquery', 'underscore', 'text!partials/audiovideo.html', 'text!partials/ |
|
|
|
|
|
|
|
|
|
|
|
$scope.hasUsermedia = false; |
|
|
|
$scope.hasUsermedia = false; |
|
|
|
$scope.isActive = false; |
|
|
|
$scope.isActive = false; |
|
|
|
|
|
|
|
$scope.peersTalking = {}; |
|
|
|
if (BigScreen.enabled) { |
|
|
|
if (BigScreen.enabled) { |
|
|
|
BigScreen.exit(); |
|
|
|
BigScreen.exit(); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -220,20 +224,22 @@ define(['jquery', 'underscore', 'text!partials/audiovideo.html', 'text!partials/ |
|
|
|
$scope.localVideo.style.opacity = 0; |
|
|
|
$scope.localVideo.style.opacity = 0; |
|
|
|
$scope.remoteVideos.style.opacity = 0; |
|
|
|
$scope.remoteVideos.style.opacity = 0; |
|
|
|
$element.removeClass('active'); |
|
|
|
$element.removeClass('active'); |
|
|
|
_.each(peers, function(scope, k) { |
|
|
|
_.each(streams, function(scope, k) { |
|
|
|
scope.$destroy(); |
|
|
|
scope.$destroy(); |
|
|
|
delete peers[k]; |
|
|
|
delete streams[k]; |
|
|
|
}); |
|
|
|
}); |
|
|
|
$scope.rendererName = $scope.defaultRendererName; |
|
|
|
$scope.rendererName = $scope.defaultRendererName; |
|
|
|
|
|
|
|
$scope.haveStreams = false; |
|
|
|
|
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
mediaStream.webrtc.e.on("streamadded", function(event, stream, currentcall) { |
|
|
|
mediaStream.webrtc.e.on("streamadded", function(event, stream, currentcall) { |
|
|
|
|
|
|
|
|
|
|
|
console.log("Remote stream added.", stream, currentcall); |
|
|
|
console.log("Remote stream added.", stream, currentcall); |
|
|
|
if (_.isEmpty(peers)) { |
|
|
|
if (!$scope.haveStreams) { |
|
|
|
//console.log("First stream");
|
|
|
|
//console.log("First stream");
|
|
|
|
$window.reattachMediaStream($scope.miniVideo, $scope.localVideo); |
|
|
|
$window.reattachMediaStream($scope.miniVideo, $scope.localVideo); |
|
|
|
|
|
|
|
$scope.haveStreams = true; |
|
|
|
} |
|
|
|
} |
|
|
|
$scope.addRemoteStream(stream, currentcall); |
|
|
|
$scope.addRemoteStream(stream, currentcall); |
|
|
|
|
|
|
|
|
|
|
|
@ -247,7 +253,7 @@ define(['jquery', 'underscore', 'text!partials/audiovideo.html', 'text!partials/ |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
|
return { |
|
|
|
peers: peers |
|
|
|
streams: streams |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
}]; |
|
|
|
}]; |
|
|
|
|