如何隐藏此选项卡正在使用您的相机或麦克风opentok

时间:2018-02-09 04:16:59

标签: javascript node.js webrtc opentok

我使用opentok javascript库作为视频通话应用。通过我正在呼叫的呼叫结束视频通话时

session.disconnect(); 
session.destroy();
session.unpublish(publisher);
(至少)中,红色相机图标仍然可见,并显示消息"此选项卡正在使用您的相机或麦克风"。

如何隐藏此警告红点图标?此图标始终显示在我的网站中。

请帮帮我们

 var publisher = OT.initPublisher(targetElement, publisherProperties, function(error) {
            if (error) {

              if (error.name === 'OT_USER_MEDIA_ACCESS_DENIED') {
                // Access denied can also be handled by the accessDenied event
                videocall_err.innerHTML='Please allow access to the Camera and Microphone and try publishing again.';
              } else {
                videocall_err.innerHTML='Failed to get access to your camera or microphone. Please check that your webcam' + ' is connected and not being used by another application and try again.';
              }
              publisher.destroy();
              publisher = null;

               videocall_err.innerHTML = '';
            } else {
              console.log('Publisher initialized.');
            }
          });
         // publisher = OT.initPublisher('myPublisherDiv', publisherProperties);
          console.log(publisher);
          session.publish(publisher, function(error) {
            if (error) {
              console.log(error);
            } else {
              console.log('Publishing a stream.');
            }
          });
          publisher.on('streamCreated', function (event) {
              console.log('The publisher started streaming.');
          });




 publisher.on("streamDestroyed", function (event) {
                 event.preventDefault();
    session.disconnect(); 
session.destroy();
session.unpublish(publisher);
                 console.log("The publisher stopped streaming. Reason: "
                  + event.reason);


              });

即时通讯使用event.preventDefault();因为我想重用我的发布者

1 个答案:

答案 0 :(得分:1)

您仍然看到网络摄像头很亮,因为您在发布商的streamDestroyed事件上调用了preventDefault()。

请参阅:https://tokbox.com/developer/sdks/js/reference/Publisher.html#.event:streamDestroyed

  

发布商已停止流式传输到会话。默认   行为是从HTML DOM中删除Publisher对象。   Publisher元素在元素发送时调度销毁的事件   从HTML DOM中删除。如果你调用的是preventDefault()方法   事件侦听器中的事件对象,默认行为是   阻止,您可以选择保留发布者以供重复使用或   使用您自己的代码清理它。

如果您打算在将来的会话中重复使用此发布者,则应该只调用preventDefault()。