javascript - StopClose webcam using getUserMedia and RTCPeerConnection Chrome 25 - Stack Overflow

I'm on Chrome 25 successfully using getUserMedia and RTCPeerConnection to connect audio from a web

I'm on Chrome 25 successfully using getUserMedia and RTCPeerConnection to connect audio from a web page to another party, but I'm unable to get the API to stop the red blinking indication icon in the Chrome tab that media is being used on that page. My question is essentially a duplicate of Stop/Close webcam which is opened by navigator.getUserMedia except that the resolution there isn't working. If I have a page that just uses getUserMedia with no remote media (no peer), then stopping the camera turns off the blinking tab indicator. Adding remote streams seems to be a/the issue. Here's what I've currently got for my "close" code:

if (localStream) {
    if (peerConnection && peerConnection.removeStream) {
        peerConnection.removeStream(localStream);
    }
    if (localStream.stop) {
        localStream.stop();
    }
    localStream.onended = null;
    localStream = null;
}
if (localElement) {
    localElement.onerror = null;
    localElement.pause();
    localElement.src = undefined;
    localElement = null;
}
if (remoteStream) {
    if (peerConnection && peerConnection.removeStream) {
        peerConnection.removeStream(remoteStream);
    }
    if(remoteStream.stop) {
        remoteStream.stop();
    }
    remoteStream.onended = null;
    remoteStream = null;
}
if (remoteElement) {
    remoteElement.onerror = null;
    remoteElement.pause();
    remoteElement.src = undefined;
    remoteElement = null;
}
if (peerConnection) {
    peerConnection.close();
    peerConnection = null;
}

I've tried with and without the removeStream() call, I've tried with and without the stop() call, I've tried the element.src="" and element.src=null, I'm running out of ideas. Anyone know if this is a bug or user/my error in the use of the API?

EDIT: I set my default device (using Windows) to a camera that has a light when it's in use, and upon stopping, the camera light goes off, so perhaps this is a Chrome bug. I also discovered that if I use chrome://settings/content to change the microphone device to anything other than "Default", Chrome audio fails altogether. And finally, I realized that using element.src=undefined resulted in Chrome attempting to load a resource and throwing a 404 so that's clearly not correct... so back to element.src='' on that.

I'm on Chrome 25 successfully using getUserMedia and RTCPeerConnection to connect audio from a web page to another party, but I'm unable to get the API to stop the red blinking indication icon in the Chrome tab that media is being used on that page. My question is essentially a duplicate of Stop/Close webcam which is opened by navigator.getUserMedia except that the resolution there isn't working. If I have a page that just uses getUserMedia with no remote media (no peer), then stopping the camera turns off the blinking tab indicator. Adding remote streams seems to be a/the issue. Here's what I've currently got for my "close" code:

if (localStream) {
    if (peerConnection && peerConnection.removeStream) {
        peerConnection.removeStream(localStream);
    }
    if (localStream.stop) {
        localStream.stop();
    }
    localStream.onended = null;
    localStream = null;
}
if (localElement) {
    localElement.onerror = null;
    localElement.pause();
    localElement.src = undefined;
    localElement = null;
}
if (remoteStream) {
    if (peerConnection && peerConnection.removeStream) {
        peerConnection.removeStream(remoteStream);
    }
    if(remoteStream.stop) {
        remoteStream.stop();
    }
    remoteStream.onended = null;
    remoteStream = null;
}
if (remoteElement) {
    remoteElement.onerror = null;
    remoteElement.pause();
    remoteElement.src = undefined;
    remoteElement = null;
}
if (peerConnection) {
    peerConnection.close();
    peerConnection = null;
}

I've tried with and without the removeStream() call, I've tried with and without the stop() call, I've tried the element.src="" and element.src=null, I'm running out of ideas. Anyone know if this is a bug or user/my error in the use of the API?

EDIT: I set my default device (using Windows) to a camera that has a light when it's in use, and upon stopping, the camera light goes off, so perhaps this is a Chrome bug. I also discovered that if I use chrome://settings/content to change the microphone device to anything other than "Default", Chrome audio fails altogether. And finally, I realized that using element.src=undefined resulted in Chrome attempting to load a resource and throwing a 404 so that's clearly not correct... so back to element.src='' on that.

Share Improve this question edited May 23, 2017 at 12:16 CommunityBot 11 silver badge asked Feb 28, 2013 at 13:43 markmark 5,4792 gold badges23 silver badges35 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

Ended up being my fault (yes, shocking). Turns out I wasn't saving localStream correctly in the onUserMediaSuccess callback of getUserMedia... once that was set, Chrome is turning off the blinking recording icon. That didn't explain the other anomalies, but it closes the main point of the question.

I just got this working yesterday after trawling through the WebRTC specification. I don't know if this is the "right" way to do it, but I found that renegotiating the PeerConnection with a new offer after removing the stream did the trick.

var pc = peerConnections[socketId];
pc.removeStream(stream);
pc.createOffer( function(session_description) {
  pc.setLocalDescription(session_description);
  _socket.send(JSON.stringify({
    "eventName": "send_offer",
    "data":{
      "socketId": socketId,
      "sdp": session_description
      }
    }));
},
function(error) {},
defaultConstraints);

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745325762a4622649.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信