getAliVoice () {
var aliWebrtc = this.aliWebrtc;
//检测浏览器是否支持webrtc
let options = {
isReceiveOnly: true,//是否为纯订阅模式。取值:true|false(默认值)
isDebug: true//线上环境必须使用https协议。您可以添加{isDebug: true}参数进行localhost(本地主机)调试跳过https协议检测。
};
aliWebrtc.isSupport(options).then(res => {
console.log(res, '支持');
this.init();
}).catch(error => {
console.log(error, '不支持RTC');
})
}
init () {
var aliWebrtc = this.aliWebrtc;
this.$axios.get(url', {
params: {
channelId: id,
userId: userId
}
}).then(res => {
let info = {
appid: res.appId,
userid: res.userId,
timestamp: res.timestamp,
nonce: res.nonce,
token: res.token,
gslb: [res.gslb],
channel: res.channelId
}
//加入频道
aliWebrtc.joinChannel(info, 自己的id).then(() => {
console.log('加入成功');
aliWebrtc.subscribe(推流的id).then((data) => {
console.log(data, 'subscribe执行~~~')
aliWebrtc.configRemoteAudio(推流的id, true);
aliWebrtc.configRemoteCameraTrack(推流的id, false);
aliWebrtc.configRemoteScreenTrack(推流的id, false);
}).catch(error => {
console.log(error.message, 'subscribe错误');
});
}).catch(error => {
// 入会失败,打印错误内容,可以看到失败原因
console.log(error.message, '加入房间失败');
});
//当远程用户推流时,在SDK里会触发onPublisher回调,通过订阅这个回调,能够得到频道里已经推流的用户
aliWebrtc.on('onPublisher', (data) => {
console.log(data, '用户推流')
})
//订阅流成功回调。当订阅远程流成功时触发,会返回远程流的Stream对象,通过H5 Video或Audio播放
aliWebrtc.on('onMediaStream', (subscriber, stream) => {
console.log(subscriber, stream, '阅流成功回调');
// aliWebrtc.setDisplayRemoteVideo(subscriber, _this.$refs.htmlVideo, stream);
})
}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
经过多次测试 发现在安卓设备上发布的音频流 ,PC上可以播放 而ios设备上发布的音频流却无法订阅
//当远程用户推流时,在SDK里会触发onPublisher回调,通过订阅这个回调,能够得到频道里已经推流的用户
aliWebrtc.on('onPublisher', () => {
console.log('用户推流--- onPublisher')
//订阅远程流
aliWebrtc.subscribe(.userId).then(() => {
console.log('订阅远程流成功~')
aliWebrtc.setDisplayRemoteVideo(buserId, this.$refs.htmlVideo, 1);
}).catch(error => {
console.log(error.message, '订阅错误回调');
});
})
这个回调没有触发
有没有打