首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >实时音视频 -- Received event: [ undefined ]?

实时音视频 -- Received event: [ undefined ]?

提问于 2020-08-15 15:26:14
回答 0关注 0查看 243

怎么本地流 也提示这样,,别人都可以 本地,远端有问题。。。。


代码语言:js
复制
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();

回答

和开发者交流更多问题细节吧,去 写回答
相关文章

相似问题

相关问答用户
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档