angularjs - WebRTC remote video stream not working despite having src -


i'm trying make simple angularjs webrtc video chat app based on this tutorial.

i'm able connect connect clients, add streams , play own stream, somehow can't play remote stream.

when check elements can see videoplayer in fact have blob source, won't play it.

can tell me why won't show?

html element: blob src

room controller:

angular.module('publicapp').controller('roomctrl', function ($sce, videostream, $location, $routeparams, $scope, room) {     if (!window.rtcpeerconnection || !navigator.getusermedia) {   $scope.error = 'webrtc not supported browser. can try app chrome , firefox.';   return; }  var stream;  videostream.get() .then(function (s) {   stream = s;   room.init(stream);   stream = url.createobjecturl(stream);   if (!$routeparams.roomid) {     room.createroom()     .then(function (roomid) {       $location.path('/room/' + roomid);     });   } else {     room.joinroom($routeparams.roomid);   } }, function () {   $scope.error = 'no audio/video permissions. please refresh browser , allow audio/video capturing.'; });  $scope.peers = [];  room.on('peer.stream', function (peer) {   console.log('client connected, adding new stream');   $scope.peers.push({     id: peer.id,     stream: url.createobjecturl(peer.stream)   });   console.log($scope.peers); });  room.on('peer.disconnected', function (peer) {   console.log('client disconnected, removing stream');   $scope.peers = $scope.peers.filter(function (p) {     return p.id !== peer.id;   }); });  $scope.getlocalvideo = function () {   return $sce.trustasresourceurl(stream); }; }); 

room factory:

angular.module('publicapp').factory('room', function ($rootscope, $q, io, config) { var iceconfig = { 'iceservers': [{ 'url': 'stun:stun.l.google.com:19302' }]},     peerconnections = {},     currentid, roomid,     stream;  function getpeerconnection(id) {   if (peerconnections[id]) {     return peerconnections[id];   }   var pc = new rtcpeerconnection(iceconfig);   peerconnections[id] = pc;   pc.addstream(stream);   pc.onicecandidate = function (evnt) {     socket.emit('msg', { by: currentid, to: id, ice: evnt.candidate, type: 'ice' });   };   pc.onaddstream = function (evnt) {     console.log('received new stream');     api.trigger('peer.stream', [{       id: id,       stream: evnt.stream     }]);     if (!$rootscope.$$digest) {       $rootscope.$apply();     }   };   return pc; }  function makeoffer(id) {   var pc = getpeerconnection(id);   pc.createoffer(function (sdp) {     pc.setlocaldescription(sdp);     console.log('creating offer for', id);     socket.emit('msg', { by: currentid, to: id, sdp: sdp, type: 'sdp-offer' });   }, function (e) {     console.log(e);   },   { mandatory: { offertoreceivevideo: true, offertoreceiveaudio: true }}); }  function handlemessage(data) {   var pc = getpeerconnection(data.by);   switch (data.type) {     case 'sdp-offer':       pc.setremotedescription(new rtcsessiondescription(data.sdp), function () {         console.log('setting remote description offer');         pc.createanswer(function (sdp) {           pc.setlocaldescription(sdp);           socket.emit('msg', { by: currentid, to: data.by, sdp: sdp, type: 'sdp-answer' });         });       });       break;     case 'sdp-answer':       pc.setremotedescription(new rtcsessiondescription(data.sdp), function () {         console.log('setting remote description answer');       }, function (e) {         console.error(e);       });       break;     case 'ice':       if (data.ice) {         console.log('adding ice candidates');         pc.addicecandidate(new rtcicecandidate(data.ice));       }       break;   } }  var socket = io.connect(config.signalig_server_url),     connected = false;  function addhandlers(socket) {   socket.on('peer.connected', function (params) {     makeoffer(params.id);   });    socket.on('peer.disconnected', function (data) {     api.trigger('peer.disconnected', [data]);     if (!$rootscope.$$digest) {       $rootscope.$apply();     }   });    socket.on('msg', function (data) {     handlemessage(data);   }); }  var api = {   joinroom: function (r) {     if (!connected) {       socket.emit('init', { room: r }, function (roomid, id) {         currentid = id;         roomid = roomid;       });       connected = true;     }   },   createroom: function () {     var d = $q.defer();     socket.emit('init', null, function (roomid, id) {       d.resolve(roomid);       roomid = roomid;       currentid = id;       connected = true;     });     return d.promise;   },   init: function (s) {     stream = s;   } }; eventemitter.call(api); object.setprototypeof(api, eventemitter.prototype);  addhandlers(socket); return api; }); 

directive:

angular.module('publicapp').directive('videoplayer', function ($sce) { return {   template: '<div><video ng-src="{{trustsrc()}}" autoplay></video></div>',   restrict: 'e',   replace: true,   scope: {     vidsrc: '@'   },   link: function (scope) {     console.log('initializing video-player');     scope.trustsrc = function () {       if (!scope.vidsrc) {         console.log('no vidsrc found');         return undefined;       }       return $sce.trustasresourceurl(scope.vidsrc);     };   } }; }); 

room.html:

<div class="video-wrapper">   <video-player class="col-md-4" ng-repeat="peer in peers" vid-src="{{peer.stream}}"></video-player> </div>  <div class="video-wrapper">   <div class="col-md-2">     <video ng-src="{{getlocalvideo()}}" autoplay muted></video>   </div> </div> 


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -