VideoApe.js
3.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// //////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2016-present All Rights Reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// http://www.apache.org/licenses/LICENSE-2.0
//
// Github Home: https://github.com/AlexWang1987
// Author: AlexWang
// Date: 2016-08-23 18:07:28
// QQ Email: 1669499355@qq.com
// Last Modified time: 2016-09-06 11:13:59
// Description: LiveClass-VideoApe
//
// //////////////////////////////////////////////////////////////////////////////
import Ape from './Ape';
import ApeConsts from './ApeConsts';
import pdu from 'pdu';
import Loger from 'Loger';
import MessageTypes from 'MessageTypes';
let loger = Loger.getLoger('VideoChat');
class VideoChat extends Ape {
constructor() {
super(
ApeConsts.VIDEO_SESSION_ID,
ApeConsts.VIDEO_SESSION_NAME,
ApeConsts.VIDEO_SESSION_TAG
);
//Attributes
this.videoChannels = {};
this.activeChannelId = 0;
this.activeURL = '';
// Ape Models
this.registerKey(this._session_id, this._session_name, this._session_tag, new ArrayBuffer);
this.registerObj(pdu.RCPDU_REG_REGISTER_TABLE, ApeConsts.VIDEO_OBJ_TABLE_ID, ApeConsts.VIDEO_OBJ_TABLE_NAME, ApeConsts.VIDEO_OBJ_TABLE_TAG, 0, new ArrayBuffer);
// ape listeners
this.on(pdu.RCPDU_VIDEO_SEND_DATA_REQUEST, this.videoIncomingHandler.bind(this));
}
// 视频消息处理
videoIncomingHandler(videoBuffer) {
let videoReceivePdu = pdu['VideoSendDataRequestPdu'].decode(videoBuffer);
let video_data = { };
video_data._initiator = videoReceivePdu.initiator;
video_data._is_key_frame = videoReceivePdu.keyFrame;
video_data._sequence_id = videoReceivePdu.sequenceId;
video_data._slice_id = videoReceivePdu.sliceId;
video_data._data = videoReceivePdu.userData;
// this._notify(RCApeEvent.E_VIDEO_DATA, videoReceivePdu.sessionId, videoReceivePdu.channelId, video_data);
loger.log('接受视频消息.', video_data);
this._emit(MessageTypes.VIDEO_SHOW, video_data);
}
tableUpdateHandler(ownerId, channelId, channelInfo) {
// debugger;
let videoChannelInfo = pdu['RCVideoChannelInfoRecordPdu'].decode(channelInfo);
videoChannelInfo.owner = ownerId;
videoChannelInfo.channelId = channelId;
videoChannelInfo.status = ownerId === 0 ? ApeConsts.CGS_RELEASED : videoChannelInfo.status;
this.videoChannels[channelId] = videoChannelInfo;
switch (videoChannelInfo.status) {
case ApeConsts.CGS_RELEASED:
case ApeConsts.CGS_PENDING:
case ApeConsts.CGS_GRABBING:
// 只能关闭自己的流
if (this.activeChannelId === videoChannelInfo.channelId) {
this.activeChannelId = 0;
this.activeURL = '';
this.emitVideoChange();
}
break;
case ApeConsts.CGS_OPENNED:
this.activeChannelId = videoChannelInfo.channelId;
// AMS
if (this._confInfo.msType === '1') {
this.activeURL = `http://dazhi.3mang.com/live/${this._confInfo.confId}/${this._confInfo.confId}_${videoChannelInfo.channelId}_flash_cam_mic_aac/playlist.m3u8`;
}else {
this.activeURL = `http://hls.3mang.com/live/${this._confInfo.confId}_${videoChannelInfo.channelId}_flash_cam_mic_aac/playlist.m3u8`;
}
// 任何人都可以打开流
this.emitVideoChange();
break;
}
}
emitVideoChange() {
this._emit(MessageTypes.VIDEO_SHOW, {
activeChannelId: this.activeChannelId,
HLSURL: this.activeURL,
});
};
}
export default VideoChat;