帖子
帖子
用户
博客
课程
显示全部楼层
24
帖子
0
勋章
255
Y币

[插件使用] agoraLive模块调用顺序

[复制链接]
发表于 2023-4-13 14:38:55
这是在官方技术大佬支持下,提供了模块的调用顺序, 非常感谢!!
  1. <!DOCTYPE HTML>
  2. <html>

  3. <head>
  4.     <meta charset="utf-8">
  5.     <meta name="viewport"
  6.         content="maximum-scale=1.0, minimum-scale=1.0, user-scalable=0, initial-scale=1.0, width=device-width" />
  7.     <meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
  8.     <title>Hello APP</title>
  9.     <link rel="stylesheet" type="text/css" href="../css/api.css" />
  10.     <style>
  11.         div {
  12.             margin: 5px;
  13.             float: left;
  14.         }
  15.     </style>
  16. </head>

  17. <body>

  18.     <p>a手机操作:</p>
  19.     <div onclick="fnsetlocView(uid1)">设置本地123的窗口</div>
  20.     <div onclick="fnstartPreview(uid1)">预览本地123的窗口</div>
  21.     <div onclick="fnjoinChannelByToken(uid1)">123加入频道</div>
  22.     <div>对方456加入频道后操作:</div>
  23.     <div onclick="fnsetremView(uid2)">设置远端456的窗口</div>
  24.     <div onclick="fnsetupRemoteVideo(uid2)">打开远端456的窗口</div>


  25.     <p style="clear: left;">b手机操作 </p>
  26.     <div onclick="fnsetlocView(uid2)">设置本地456的窗口</div>
  27.     <div onclick="fnstartPreview(uid2)">预览本地456的窗口</div>
  28.     <div onclick="fnjoinChannelByToken(uid2)">456加入频道</div>
  29.     <div>对方123加入频道后操作:</div>
  30.     <div onclick="fnsetremView(uid1)">设置远端123的窗口</div>
  31.     <div onclick="fnsetupRemoteVideo(uid1)">打开远端123的窗口</div>



  32. </body>
  33. <script type="text/javascript" src="../script/api.js"></script>
  34. <script type="text/javascript">
  35.     var agoraLive;
  36.     var uid1 = 123321;
  37.     var uid2 = 456654;
  38.     apiready = function () {
  39.         agoraLive = api.require('agoraLive');
  40.         agoraLive.init({
  41.             appId: '826f5e5e147f453******'     // 改成自己的
  42.         }, function (ret) {
  43.             if (ret.status) {

  44.                 agoraLive.enableVideo();

  45.                 //agoraLive.enableAudio();
  46.                 agoraLive.setChannelProfile({
  47.                     profile: 'liveBroadcasting'
  48.                 }, function (ret) {
  49.                     if (ret.status) {
  50.                         alert('设置直播模式成功');
  51.                     }
  52.                 });

  53.                 //仅Android
  54.                 agoraLive.setClientRoleOrAndroid({
  55.                     role: '1'
  56.                 }, function (ret) {

  57.                 });

  58.                 //设置加入频道监听
  59.                 agoraLive.userJoinedListener({
  60.                     enable: true
  61.                 }, function (ret) {
  62.                     api.alert({ msg: '加入频道监听:' + JSON.stringify(ret) });
  63.                 });

  64.                 agoraLive.firstRemoteVideoFrameListener({
  65.                     enable: true
  66.                 }, function (ret) {
  67.                     console.log('第一帧远程视频显示在视图回调:' + JSON.stringify(ret));
  68.                 });

  69.                 agoraLive.firstRemoteVideoDecodedListener({
  70.                     enable: true
  71.                 }, function (ret) {
  72.                     console.log('收到第一帧远程视频流并解码成功时,触发此调用:' + JSON.stringify(ret));
  73.                 });

  74.                 agoraLive.errorListener({
  75.                     enable: true
  76.                 }, function (ret) {

  77.                     console.log('err:-----' + JSON.stringify(ret))
  78.                 });
  79.                 alert('初始化成功');
  80.             }
  81.         });



  82.     };

  83.     function fnjoinChannelByToken(uid) {

  84.         agoraLive.joinChannelByToken({
  85.             channelToken: '',
  86.             channelId: 'testac',
  87.             uid: uid
  88.         }, function (ret, err) {
  89.             if (ret.status) {
  90.                 api.alert({ msg: JSON.stringify(ret) });
  91.             } else {
  92.                 api.alert({ msg: JSON.stringify(err) });
  93.             }
  94.         });
  95.     }

  96.     //设置本地窗口
  97.     function fnsetlocView(uid) {
  98.         agoraLive.initVideoRect({
  99.             uid: uid,
  100.             rect: {
  101.                 x: 0,
  102.                 y: 350,
  103.                 w: 120,
  104.                 h: 200
  105.             },
  106.             fixedOn: api.frameName
  107.         });
  108.     }

  109.     function fnstartPreview(uid) {

  110.         agoraLive.setupLocalVideo({
  111.             renderMode: 'RENDER_MODE_HIDDEN',
  112.             uid: uid
  113.         }, function (ret) {
  114.             if (ret.status) {
  115.                 //alert(JSON.stringify(ret));
  116.             }
  117.         });

  118.         agoraLive.startPreview(function (ret) {
  119.             if (ret.status) {
  120.                 alert('本地预览成功');
  121.                 agoraLive.bringToFront({ uid: uid });
  122.             }
  123.         });
  124.     }

  125.     //设置远端窗口
  126.     function fnsetremView(uid) {

  127.         agoraLive.initVideoRect({
  128.             uid: uid,
  129.             rect: {
  130.                 x: 220,
  131.                 y: 400,
  132.                 w: 200,
  133.                 h: 300
  134.             }
  135.         });
  136.     }

  137.     //打开远端窗口

  138.     function fnsetupRemoteVideo(uid) {
  139.         agoraLive.setupRemoteVideo({
  140.             renderMode: 'RENDER_MODE_HIDDEN',
  141.             uid: uid
  142.         }, function (ret) {
  143.             if (ret.status) {
  144.                 alert('打开远端窗口成功');
  145.             }
  146.         });
  147.     }


  148. </script>

  149. </html>
复制代码



支持
您需要登录后才可以回帖 登录

本版积分规则