第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會有你想問的

Agora API Addview 函數(shù)在 Javascript 中不起作用

Agora API Addview 函數(shù)在 Javascript 中不起作用

慕桂英4014372 2023-10-04 15:37:09
我正在嘗試使用Agora API一切都很好,但我的 Javascript 中創(chuàng)建容器以查看我的網(wǎng)絡(luò)攝像頭的 Addview 功能不起作用我在聽完“stream-subscribed”事件后調(diào)用它,但它不起作用。我發(fā)現(xiàn)它不監(jiān)聽“stream-added”事件我不知道為什么>請注意:我添加了 App_ID 我添加了頻道名稱 我添加了令牌感謝幫助我的網(wǎng)頁<!DOCTYPE html><html><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="ie=edge"><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"><title>Basic Live Broadcast</title><link rel="stylesheet" href="/css/common.css" /></head><body><button id="create"> create</button><button id="leave">leave</button><script src="/vendor/jquery.min.js"></script><script src="/vendor/materialize.min.js"></script><script src="/node_modules/agora-rtc-sdk/AgoraRTCSDK.min.js"></script><script src="/js/agora_ver4.js"></script></body></html>
查看完整描述

1 回答

?
慕的地10843

TA貢獻(xiàn)1785條經(jīng)驗(yàn) 獲得超8個(gè)贊

您需要將事件回調(diào)移至加入頻道成功之外??蛻舳嘶卣{(diào)需要在與客戶端初始化相同的塊內(nèi)發(fā)生。


通過等待 joinChannel 成功,為時(shí)已晚,引擎在添加偵聽器之前就觸發(fā)了該事件。


使用上面的 JS 代碼,它應(yīng)該如下所示:


// rtc object

var rtc = {

  client: null,

  joined: false,

  published: false,

  localStream: null,

  remoteStreams: [],

  params: {}

};


// Options for joining a channel

var option = {

  appID: "MY_APP_ID",

  channel: "MY_Channel_Name",

  uid: null,

  token: "Channel_Token"

}


$('#create').click(function() {



  // Create a client

  rtc.client = AgoraRTC.createClient({

    mode: "live",

    codec: "h264"

  });


  // Initialize the client

  rtc.client.init(option.appID, function() {

    console.log("init success");

    // The value of role can be "host" or "audience".

    rtc.client.setClientRole("host");


    // define callbacks before joining the channel

    rtc.client.on("stream-added", function(evt) {

      var remoteStream = evt.stream;

      var id = remoteStream.getId();

      if (id !== rtc.params.uid) {

        rtc.client.subscribe(remoteStream, function(err) {

          console.log("stream subscribe failed", err);

        })

      }

      console.log('stream-added remote-uid: ', id);

    });

    rtc.client.on("stream-subscribed", function(evt) {

      var remoteStream = evt.stream;

      var id = remoteStream.getId();

      // Add a view for the remote stream.

      addView(id);

      // Play the remote stream.

      remoteStream.play("remote_video_" + id);

      console.log('stream-subscribed remote-uid: ', id);

    })


    // Join a channel

    rtc.client.join(option.token ? option.token : null, option.channel, option.uid ? +option.uid : null, function(uid) {

      console.log("join channel: " + option.channel + " success, uid: " + uid);

      rtc.params.uid = uid;

      // Create a local stream

      rtc.localStream = AgoraRTC.createStream({

        streamID: rtc.params.uid,

        audio: true,

        video: true,

        screen: false,

      })

      // Initialize the local stream

      rtc.localStream.init(function() {

        console.log("init local stream success");

        // Publish the local stream

        rtc.client.publish(rtc.localStream, function(err) {

          console.log("publish failed");

          console.error(err);

        })

      }, function(err) {

        console.error("init local stream failed ", err);

      })

    }, function(err) {

      console.error("client join failed", err)

    })

  }, (err) => {

    console.error(err);

  });


});


$('#leave').click(function() {



  // Leave the channel

  rtc.client.leave(function() {

    // Stop playing the local stream

    rtc.localStream.stop();

    // Close the local stream

    rtc.localStream.close();

    // Stop playing the remote streams and remove the views

    while (rtc.remoteStreams.length > 0) {

      var stream = rtc.remoteStreams.shift();

      var id = stream.getId();

      stream.stop();

      removeView(id);

    }

    console.log("client leaves channel success");

  }, function(err) {

    console.log("channel leave failed");

    console.error(err);

  })

});


function addView(id, show) {

  if (!$("#" + id)[0]) {

    $("<div/>", {

      id: "remote_video_panel_" + id,

      class: "video-view",

    }).appendTo("#video");

    $("<div/>", {

      id: "remote_video_" + id,

      class: "video-placeholder",

    }).appendTo("#remote_video_panel_" + id);

    $("<div/>", {

      id: "remote_video_info_" + id,

      class: "video-profile " + (show ? "" : "hide"),

    }).appendTo("#remote_video_panel_" + id);

    $("<div/>", {

      id: "video_autoplay_" + id,

      class: "autoplay-fallback hide",

    }).appendTo("#remote_video_panel_" + id);

  }

}


function removeView(id) {

  if ($("#remote_video_panel_" + id)[0]) {

    $("#remote_video_panel_" + id).remove();

  }

}



查看完整回答
反對 回復(fù) 2023-10-04
  • 1 回答
  • 0 關(guān)注
  • 75 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號