怎么本地流 也提示这样,,别人都可以 本地,远端有问题。。。。
function getQueryVariable(variable) {
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if(pair[0] == variable){return pair[1];}
}
return(false);
}
var el = document.getElementById('app');
function XW( sdkAppId, userId, userSig) {
this.userId = userId;
this.sdkAppId = sdkAppId;
this.userSig = userSig;
// this.TRTC = TRTC;
this.client = '';
this.localStream = '';
};
// 创建Client 对象
XW.prototype.createClient = function( ) {
this.client = TRTC.createClient({
mode: 'rtc',
sdkAppId: this.sdkAppId,
userId: this.userId,
userSig: this.userSig,
});
}
// 进入音视频通话房间
XW.prototype.join = function( ) {
let self = this;
this.client.join({ roomId: 8888 }).catch(error => {
console.error('进房失败 ' + error);
}).then(() => {
console.log('进房成功');
self.createStream();
});
}
//创建本地音视频流
XW.prototype.createStream = function( ) {
this.localStream = TRTC.createStream({ userId: this.userId, audio: true, video: true });
this.localStreaminitialize();
}
//初始化本地音视频流
XW.prototype.localStreaminitialize = function( ) {
let self = this;
this.localStream.initialize().catch(error => {
console.error('初始化本地流失败 ' + error);
}).then(() => {
console.log('初始化本地流成功');
self.publish();
self.localStream.play('app');
});
}
//发布本地音视频流
XW.prototype.publish = function( ) {
this.client.publish( this.localStream ).catch(error => {
console.error('本地流发布失败 ' + error);
}).then(() => {
console.log('本地流发布成功');
});
}
//订阅远端音视频流
XW.prototype.subscribed = function( ) {
let self = this;
this.client.on('stream-added', event => {
const remoteStream = event.stream;
console.log('远端流增加: ' + remoteStream.getId());
//订阅远端流
self.client.subscribe(remoteStream);
});
this.client.on('stream-subscribed', event => {
const remoteStream = event.stream;
console.log('远端流订阅成功:' + remoteStream.getId());
// 播放远端流
remoteStream.play('remote_stream-' + remoteStream.getId());
});
}
xwObj = new XW( sdkAppId, uuid, userSig);
xwObj.createClient();
// xwObj.subscribed();
xwObj.join();
// xwObj.createStream();
// xwObj.localStreaminitialize();
相似问题