浏览器vue接入声网

npm install agora-rtc-sdk
    agoraInit:function(){
                const _this = this;
                if(AgoraRTC.checkSystemRequirements()){
                    const agoraClient = AgoraRTC.createClient({
                        mode: 'rtc', // 模式
                        codec: 'vp8', // 编码格式
                    })
                    _this.agoraClient = agoraClient;
                    console.log(_this.agoraOptions.appid)
                    agoraClient.init(
                    _this.agoraOptions.appid,
                    (res) => {
                        console.log("初始化成功!");
                        agoraClient.join(
                        _this.agoraOptions.tokenOrKey ? _this.agoraOptions.tokenOrKey : null,
                        _this.agoraOptions.channel ? _this.agoraOptions.channel :'call',
                        null,
                        uid => {
                            console.log("链接成功", uid)
                                _this.createStream(uid);
                        },
                        err => {
                            // Error handling
                            console.log("加入频道失败!", err)
                        })
                    }, 
                    err => {
                        console.log("AgoraRTC 初始化失败!")
                    })
                
                }else{
                    _this.$message({
                        message:"当前设备不支持声网",
                        type:"error",
                        offset:'80'
                    })
                }
            },
            
            /**
             * 创建音视频流
             */
            createStream:function(uid){
                const _this = this;
                const agoraStream = AgoraRTC.createStream({
                    streamID:uid,
                    audio:true,
                    video:true,
                    screen:false
                })
                _this.agoraStream = agoraStream;
                agoraStream.init((res) => {
                    console.log("接入成功", res)
                    _this.agoraStream.play("pusher")
                },(err) => {
                    console.log("音视频创建失败")
                })
            },
            
            checkVideo:function(){
                const _this = this;
                if(_this.track.video){
                    _this.agoraStream.muteVideo()
                    _this.track.video = false;
                }else{
                    _this.agoraStream.unmuteVideo()
                    _this.track.video = true
                }
            },
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容