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
}
},