第一个webSocket视频在页面上运行第二个时停止

时间:2016-04-19 11:13:54

标签: javascript websocket angular video-streaming

我有Angular 2应用程序,其中有一个名为stream的组件。我的应用视图:

enter image description here

该应用程序仅以streamstream1 {{}}开头。有一个背景视频,适用于webSockets。通过Android-eye手机播放视频。它在手机和流媒体视频上发布了Wifi camera应用。

问题是当屏幕上有1个流(蓝色块)时,视频效果很好。当我在stream1(蓝色块)中初始化第二个流(黄色块)视频时,最后一帧停止,而stream2(黄色块)中的视频效果很好。我认为我的js代码存在问题。当我初始化新流并绑定webSockets时,有一段代码:



if (!self.videoSockets[item.clientId]) {
	var url;
	if (item.clientId == 'board1') url = 'ws://192.168.100.47:8088';
	else url = 'ws://192.168.100.6:8088';
	var streamer = {};
	self.state[item.clientId] = 0;    // -1: error; 0: idle; 1: wainting; 2: palying
	self.player[item.clientId] = null;
	self.media[item.clientId] = null;
	streamer.onOpen = function(event) {
		console.log(self.player);
	};
	streamer.onMessage = function(evt) {
		if (self.state[item.clientId] != 2) self.state[item.clientId] = 2;
		var blob = evt.data;
		if (blob.slice !== undefined) {
			var media = new TeaMedia(blob, function() {
				self.player[item.clientId].playMedia(media);
			}.bind(this));
		}
	};
	streamer.onClose = function(event) {
		console.log('onClose', event);
	};
	streamer.onError = function(event) {
		console.log('onError', event);
	};

	self.videoSockets[item.clientId] = new WebSocket(url);
	self.videoSockets[item.clientId].onopen = streamer.onOpen;
	self.videoSockets[item.clientId].onmessage = streamer.onMessage;
	self.videoSockets[item.clientId].onclose = streamer.onClose;
	self.videoSockets[item.clientId].onerror = streamer.onError;
	self.player[item.clientId] = new Player(document.getElementById(item.clientId), 8000);

}




为什么初始化stream2会导致某些stream1

0 个答案:

没有答案