使用Pubnub后如何关闭网络摄像头?

时间:2015-12-18 15:02:24

标签: webcam pubnub

我开始使用Pubnub进行视频群聊。但是,当我测试它时,我发现了一个小问题:当我将计算机连接到他们的服务器时,我的网络摄像头会打开并且永远不会关闭,除非我离开页面。

但是,我希望能够关闭视频聊天,同时关闭网络摄像头。怎么做?

非常感谢!

编辑:这是我用于测试的代码,我正在使用教程中给出的代码:

<script src="js/jquery-2.1.4.min.js"></script>
<script src="js/jquery-ui.min.js"></script>
<script src="js/pubnub-3.7.18.min.js"></script>
<script src="js/webrtc.js"></script>
<script src="js/rtc-controller.js"></script>
<div id="vid-box"></div>
<div id="vid-thumb"></div>

<form name="loginForm" id="login" action="#" onsubmit="return login(this);">
    <input type="text" name="username" id="username" placeholder="Pick a username!" />
    <input type="submit" name="login_submit" value="Log In">
</form>


<form name="callForm" id="call" action="#" onsubmit="return makeCall(this);">
    <input type="text" name="number" placeholder="Enter user to dial!" />
    <input type="submit" value="Call"/>
</form>

<div id="inCall"> <!-- Buttons for in call features -->
    <button id="end" onclick="end()">End</button> <button id="mute" onclick="mute()">Mute</button> <button id="pause" onclick="pause()">Pause</button>
</div>
<script>
    var video_out = document.getElementById("vid-box");
    var vid_thumb = document.getElementById("vid-thumb");
    function login(form) {
        var phone = window.phone = PHONE({
            number        : form.username.value || "Anonymous", // listen on username line else Anonymous
            media : { audio : true, video : true },
            publish_key   : 'pub-c-c66a9681-5497-424d-b613-e44bbbea45a0',
            subscribe_key : 'sub-c-35aca7e0-a55e-11e5-802b-02ee2ddab7fe',
        }); 
        var ctrl = window.ctrl = CONTROLLER(phone);
        ctrl.ready(function(){
            form.username.style.background="#55ff5b"; // Turn input green
            form.login_submit.hidden="true";    // Hide login button
            ctrl.addLocalStream(vid_thumb);     // Place local stream in div
        });             // Called when ready to receive call
        ctrl.receive(function(session){
            session.connected(function(session){ video_out.appendChild(session.video); });
            session.ended(function(session) { ctrl.getVideoElement(session.number).remove(); });
        });
        ctrl.videoToggled(function(session, isEnabled){
            ctrl.getVideoElement(session.number).toggle(isEnabled); // Hide video is stream paused
        });
        ctrl.audioToggled(function(session, isEnabled){
            ctrl.getVideoElement(session.number).css("opacity",isEnabled ? 1 : 0.75); // 0.75 opacity is audio muted
        });
        return false; //prevents form from submitting
    }

    function makeCall(form){
        if (!window.ctrl) alert("Login First!");
        else ctrl.dial(form.number.value);
        return false;
    }
    function end(){
        ctrl.hangup();
    }
    function mute(){
        var audio = ctrl.toggleAudio();
        if (!audio) $("#mute").html("Unmute");
        else $("#mute").html("Mute");
    }

    function pause(){
        var video = ctrl.toggleVideo();
        if (!video) $('#pause').html('Unpause');
        else $('#pause').html('Pause');
    }
</script>

请注意,除了我的搜索,我还试图通过控制台找到该功能,但我无法找到它...

0 个答案:

没有答案