Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/380.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何断开客户端与opentok会话的连接?_Javascript_Opentok_Tokbox - Fatal编程技术网

Javascript 如何断开客户端与opentok会话的连接?

Javascript 如何断开客户端与opentok会话的连接?,javascript,opentok,tokbox,Javascript,Opentok,Tokbox,每当我调用session.disconnect()方法从会话中删除客户端时,都会收到以下警告:“OpenTok:Publisher:warn Received connectivity event:“Cancel”而不“trunt” 此错误:“OpenTok:Subscriber:error无效状态转换:事件“disconnect”在“disconnected”状态下不可能发生” 有人能给我解释一下这个错误是什么意思吗?提前谢谢 // Initialize the session

每当我调用session.disconnect()方法从会话中删除客户端时,都会收到以下警告:“OpenTok:Publisher:warn Received connectivity event:“Cancel”而不“trunt”

此错误:“OpenTok:Subscriber:error无效状态转换:事件“disconnect”在“disconnected”状态下不可能发生”

有人能给我解释一下这个错误是什么意思吗?提前谢谢


// Initialize the session
      var session = OT.initSession(data['apikey'], data['session_id']);
      console.log(session);

      // Initialize the publisher for the recipient
      var publisherProperties = {insertMode: "append", width: '100%', height: '100%'};
      var publisher = OT.initPublisher('publisher', publisherProperties, function (error) {
        if (error) {
          console.log(`Couldn't initialize the publisher: ${error}`);
        } else {
          console.log("Receiver publisher initialized.");
        }
      });
      $('#session-modal').modal("show");

      // Detect when new streams are created and subscribe to them.
      session.on("streamCreated", function (event) {
        console.log("New stream in the session");
        var subscriberProperties = {insertMode: 'append', width: '100%', height: '100%'};
        var subscriber = session.subscribe(event.stream, 'subscriber', subscriberProperties, function(error) {
          if (error) {
            console.log(`Couldn't subscribe to the stream: ${error}`);
          } else {
            console.log("Receiver subscribed to the sender's stream");
          }
        });
      });

      //When a stream you publish leaves a session, the Publisher object dispatches a streamDestroyed event:
      publisher.on("streamDestroyed", function (event) {
        console.log("The publisher stopped streaming. Reason: "
        + event.reason);

      });

      //When a stream, other than your own, leaves a session, the Session object dispatches a streamDestroyed event:
      session.on("streamDestroyed", function (event) {
        console.log("Stream stopped. Reason: " + event.reason);
        session.disconnect();
        console.log("called session.disconnect().");


      });


      session.on({
        connectionCreated: function (event) {
          connectionCount++;
          if (event.connection.connectionId != session.connection.connectionId) {
            console.log(`Another client connected. ${connectionCount} total.`);
          }
        },
        connectionDestroyed: function connectionDestroyedHandler(event) {
          connectionCount--;
          console.log(`A client disconnected. ${connectionCount} total.`);
        }
      });

      // Connect to the session
      // If the connection is successful, publish an audio-video stream.
      session.connect(data['token'], function(error) {
        if (error) {
          console.log("Error connecting to the session:", error.name, error.message);
        } else {
          console.log("Connected to the session.");
          session.publish(publisher, function(error) {
            if (error) {
              console.log(`couldn't publish to the session: ${error}`);
            } else {
              console.log("The receiver is publishing a stream");
            }
          });
        }
      });

      // Stop the publisher from streaming to the session if the user dismiss the modal
      const stopSession = document.getElementById('stop-session');
      stopSession.addEventListener("click", (event) => {
        event.preventDefault();
        session.disconnect();
      });



我非常怀疑你能用JavaScript断开客户端的连接

// Connect to the session
session.connect(token, function connectCallback(error) {
 // Get the connectionId
    connectionId = session.connection.connectionId;
并在后端使用其中一个SDK


我知道这有点旧,但我想分享我的解决方案以避免此错误。我不确定此错误的含义,但我在调用session.disconnect()之前调用publisher.destroy()以避免此错误

openTokPublisher.destroy();
openTokSession.disconnect();
openTokPublisher.destroy();
openTokSession.disconnect();