ConferApe.js
5.0 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// //////////////////////////////////////////////////////////////////////////////
//
// 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-22 09:57:12
// QQ Email: 1669499355@qq.com
// Last Modified time: 2016-09-07 16:16:35
// Description: LiveClass-ConferApe
//
// //////////////////////////////////////////////////////////////////////////////
import Ape from './Ape';
import ApeConsts from './ApeConsts';
import MessageTypes from 'MessageTypes';
import pdu from 'pdus';
import { Zlib } from 'zlibjs/bin/zlib.min';
import UTF8 from 'utf-8';
import Loger from 'Loger';
let loger = Loger.getLoger('ConferApe');
class ConferApe extends Ape {
constructor() {
super(
ApeConsts.CONFERENCE_SESSION_ID,
ApeConsts.CONFERENCE_SESSION_NAME,
ApeConsts.CONFERENCE_SESSION_TAG
);
// Attribures
this.hostNodeId = -1;
this.hostUserId = '';
this.rosters = {};
this.activeDocId = '';
// Ape Models
this.registerKey(this._session_id, this._session_name, this._session_tag, new ArrayBuffer);
this.registerObj(pdu.RCPDU_REG_REGISTER_ROSTER, ApeConsts.CONFERENCE_OBJ_ROSTER_ID,
ApeConsts.CONFERENCE_OBJ_ROSTER_NAME, ApeConsts.CONFERENCE_OBJ_ROSTER_TAG, 0, new ArrayBuffer);
this.registerObj(pdu.RCPDU_REG_REGISTER_QUEUE, ApeConsts.CONFERENCE_OBJ_QUEUE_ID,
ApeConsts.CONFERENCE_OBJ_QUEUE_NAME, ApeConsts.CONFERENCE_OBJ_QUEUE_TAG, 0, new ArrayBuffer);
this.registerObj(pdu.RCPDU_REG_REGISTER_TABLE, ApeConsts.CONFERENCE_OBJ_TABLE_ID,
ApeConsts.CONFERENCE_OBJ_TABLE_NAME, ApeConsts.CONFERENCE_OBJ_TABLE_TAG, 0, new ArrayBuffer);
this.registerObj(pdu.RCPDU_REG_REGISTER_COUNTER, ApeConsts.CONFERENCE_OBJ_COUNTER_ID,
ApeConsts.CONFERENCE_OBJ_COUNTER_NAME, ApeConsts.CONFERENCE_OBJ_COUNTER_TAG, 0, new ArrayBuffer);
this.on(pdu.RCPDU_SESSION_JOIN_RESPONSE, this._joinSessionHandler.bind(this));
}
_joinSessionHandler(confInfo) {
let nodeInfoRecordPdu = this.mcu.mcuConfInfo.self;
let userDataPdu = new pdu['RCNodeInfoUserDataPdu'];
userDataPdu.qq = '';
userDataPdu.skype = '';
userDataPdu.mobile = '';
nodeInfoRecordPdu.userData = userDataPdu.toArrayBuffer();
nodeInfoRecordPdu.deviceType = 3;
let item = new pdu['RCRegistryRosterItemPdu'];
item.nodeId = nodeInfoRecordPdu.nodeId;
item.nodeData = nodeInfoRecordPdu.toArrayBuffer();
let rosterUpdateItem = new pdu['RCRegistryRosterUpdateItemPdu'];
rosterUpdateItem.type = pdu.RCPDU_REG_ROSTER_UPDATE_PDU;
rosterUpdateItem.items.push(item);
let updateObjPdu = new pdu['RCRegistryUpdateObjPdu'];
updateObjPdu.objId = ApeConsts.CONFERENCE_OBJ_ROSTER_ID;
updateObjPdu.subType = rosterUpdateItem.type;
updateObjPdu.userData = rosterUpdateItem.toArrayBuffer();
let adapterItemPdu = new pdu['RCAdapterItemPdu'];
adapterItemPdu.type = pdu.RCPDU_REG_UPDATE_OBJ;
adapterItemPdu.itemData = updateObjPdu.toArrayBuffer();
let adapterPdu = new pdu['RCAdapterPdu'];
adapterPdu.type = pdu.RCPDU_REG_ADAPTER;
adapterPdu.item.push(adapterItemPdu);
this.sendUniform(adapterPdu, true);
}
tableUpdateHandler(owner, recordId, recordData) {
try {
let tabUpdatePdu = pdu.RCTabUpdateDataRequestPdu.decode(recordData);
const uncompressedBytes = new Zlib.Inflate(tabUpdatePdu.action.compact().view).decompress();
let tabInfo = UTF8.getStringFromBytes(uncompressedBytes);
let tabTypeMatches = tabInfo.match(/<TabType>(.+)<\/TabType>/);
if (tabTypeMatches.length > 1 && tabTypeMatches[1] == 'show.docsharing') {
if (tabInfo.match(/<visible>(.+)<\/visible>/)[1] == 'true') {
this.activeDocId = tabInfo.match(/<TabID>(.+)<\/TabID>/)[1];
this._emit(MessageTypes.DOC_SWITCH, this.activeDocId);
}
}
} catch (e) {
loger.warn('ConferApe table update got exception.');
}
}
rosterInsertHandler(nodeId, nodeData) {
this.rosterUpdateHandler(nodeId, nodeData);
}
//更新人员列表数据
rosterUpdateHandler(nodeId, nodeData) {
if (nodeData.role === ApeConsts.NR_MASTER ||
nodeData.role === ApeConsts.NR_SLAVE) {
this.hostNodeId = nodeData.nodeId;
this.hostUserId = nodeData.userId;
}
if (nodeData.role === ApeConsts.NR_NORMAL &&
this.hostNodeId === nodeData.nodeId) {
this.hostNodeId = -1;
this.hostUserId = '';
}
let rosterExists = this.rosters[nodeId];
this.rosters[nodeId] = nodeData;
if (!rosterExists) {
this.emitRosterChange();
}
}
rosterDelHandler(nodeId) {
delete this.rosters[nodeId];
this.emitRosterChange();
// 自己退出
if (nodeId == this._confInfo.nodeId) {
this._emit(MessageTypes.CLASS_EXIT);
}
}
emitRosterChange() {
this._emit(MessageTypes.CLASS_SHOW_ROSTER_NUM, Object.keys(this.rosters).length);
}
}
export default ConferApe;