vue学习

声网(Agora)视频通话-小程序

2019-06-01  本文已影响0人  69e1d9dadce5

声网(Agora)

微信小程序

邮箱账号: sales@agora.io

(2)给声网客服打电话开通,声网电话:400 6326626
注:给官网邮箱发邮件,没人回复我,后来还是打客服开通的,客服态度很好哦

const AgoraMiniappSDK = require('../../lib/Agora_Miniapp_SDK_for_WeChat.js');
// 推流上下文
    this.ctx = wx.createLivePusherContext("livePush");
//  拉流上下文
    this.liveP = wx.createLivePlayerContext('livePlayer');

    var that = this;
    let client = new AgoraMiniappSDK.Client();
    that.setData({
      client: client
    });
    // 初始化
    client.init("这是你的appid", function () {
      // 初始化成功
      console.log("初始化成功");
      client.join("token 如果没有写null", "房间号", "这里是用户uid", function (uid) {
        // 加入成功
        console.log("加入成功User " + uid + " join channel successfully");
        // 发布本地音频流并获取推流 url 地址
        client.publish(function (res) {
          // 发布成功
          console.log("发布成功pushPath" + res);
          that.setData({
            pushPath: res
          })
          // 监听
          client.on('error', function (err) {
            console.log("Got error msg:", err.reason);
            if (err.reason === 'DYNAMIC_KEY_TIMEOUT') {
              client.renewChannelKey(that.data.fangjianhao, function () {
                console.log("Renew channel key successfully");
              }, function (err) {
                console.log("Renew channel key failed: ", err);
              });
            }
          });
          // 监听远程视频添加
          client.on('stream-added', function (evt) {
            client.subscribe(evt.uid, function (res) {
              console.log("订阅视频流成功playUrl" + res);
              that.setData({
                playUrl: res
              });
            }, function (err) {
              console.log("订阅视频流错误", err);
            });
          });

          client.on('update-url', function (evt) {
            console.log("视频播放", evt);
          });

          client.on('stream-removed', function (evt) {
            console.log("视频停止播放");
          });

          client.on('video-rotation', function (evt) {
            console.log(evt.uid + " leaved from this channel");
          });


        }, function (err) {
          // 发布失败
          console.log("发布失败" + err);
        });
      }, function (err) {
        // 加入失败
        console.log("加入失败", err);
      });
    }, function (err) {
      //初始化失败
      console.log("初始化失败", err);
    });

注: 不同appid不能通话
官网api:https://docs.agora.io/cn/Video/API%20Reference/wechat/index.html

https://github.com/AgoraIO/Agora-Miniapp-Tutorial
https://miniapp.agoraio.cn
https://miniapp-1.agoraio.cn
https://miniapp-2.agoraio.cn
https://miniapp-3.agoraio.cn
https://miniapp-4.agoraio.cn
https://uni-webcollector.agora.io
wss://miniapp.agoraio.cn
示例代码:
  client = AgoraRTC.createClient({mode: 'live'});
修改后:
  client = AgoraRTC.createClient({mode: 'live',codec: "h264"});

注明

上一篇 下一篇

猜你喜欢

热点阅读