VideoApe.js
4.2 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// //////////////////////////////////////////////////////////////////////////////
//
// 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 'pdus';
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));
}
/////////////发送数据操作//////////////////////////////////////////////////////
//获取播流地址
getPlayVideoPath(_param){
loger.log('getPlayVideoPath');
return {"code":0,"data":"播放流地址XXXXXXXXXXXXXXXXXXXXX"};
}
//获取推流地址
getPublishVideoPath(_param){
loger.log('getPublishVideoPath');
return {"code":0,"data":"推流地址XXXXXXXXXXXXXXXXXXXXXXX"};
}
//推流
publishVideo(_param){
loger.log('publishVideo');
}
//停止推流
stopPublishVideo(_param){
loger.log('stopPublishVideo.');
}
/////收到消息处理/////////////////////////////////////////////////////////////////////////////////
// 视频消息处理
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('视频消息处理 videoIncomingHandler.', video_data);
this._emit(MessageTypes.VIDEO_RECEIVE, video_data);
}
tableUpdateHandler(owner, itemIdx, itemData) {
// debugger;
let videoChannelInfo = pdu['RCVideoChannelInfoRecordPdu'].decode(itemData);
videoChannelInfo.owner = owner;
videoChannelInfo.channelId = itemIdx;
videoChannelInfo.status = owner === 0 ? ApeConsts.CGS_RELEASED : videoChannelInfo.status;
loger.log('视频消息处理 tableUpdateHandler.',videoChannelInfo);
this.videoChannels[itemIdx] = 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._classInfo.msType === '1') {
this.activeURL = `http://dazhi.3mang.com/live/${this._classInfo.classId}/${this._classInfo.classId}_${videoChannelInfo.channelId}_flash_cam_mic_aac/playlist.m3u8`;
}else {
this.activeURL = `http://hls.3mang.com/live/${this._classInfo.classId}_${videoChannelInfo.channelId}_flash_cam_mic_aac/playlist.m3u8`;
}
// 任何人都可以打开流
this.emitVideoChange();
break;
}
}
emitVideoChange() {
this._emit(MessageTypes.VIDEO_RECEIVE, {
activeChannelId: this.activeChannelId,
HLSURL: this.activeURL,
});
};
}
export default VideoChat;