WhiteBoardApe.js
10.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
// //////////////////////////////////////////////////////////////////////////////
//
// 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-26 17:36:20
// QQ Email: 1669499355@qq.com
// Last Modified time: 2016-09-21 14:06:12
// Description: LiveClass-WhiteBoardApe
//
// //////////////////////////////////////////////////////////////////////////////
import Ape from './Ape';
import ApeConsts from './ApeConsts';
import pdu from 'pdus';
import Loger from 'Loger';
import MessageTypes from 'MessageTypes';
import { Zlib } from 'zlibjs/bin/zlib.min';
import UTF8 from 'utf-8';
import GlobalConfig from 'GlobalConfig';
let loger = Loger.getLoger('WhiteBoardApe');
let insertIdx=1;//table插入新数据的计数id
class WhiteBoardApe extends Ape {
constructor() {
super(
ApeConsts.WHITEBOARD_SESSION_ID,
ApeConsts.WHITEBOARD_SESSION_NAME,
ApeConsts.WHITEBOARD_SESSION_TAG
);
// properties
this.annoInfos = {};
//Ape Models
this.registerKey(this._session_id, this._session_name, this._session_tag, new ArrayBuffer);
this.registerObj(pdu.RCPDU_REG_REGISTER_TABLE, ApeConsts.WHITEBOARD_OBJ_TABLE_ID,
ApeConsts.WHITEBOARD_OBJ_TABLE_NAME, ApeConsts.WHITEBOARD_OBJ_TABLE_TAG, 0, new ArrayBuffer);
// ape listeners
this.on(pdu.RCPDU_CONFERENCE_SEND_DATA_REQUEST, this.whiteboardMsgComingHandler.bind(this));
this.on(pdu.RCPDU_SESSION_JOIN_RESPONSE, this._joinSessionHandler.bind(this));
// 白板延迟
this._apeDelayed = true;
}
_joinSessionHandler(confInfo) {
loger.log("RCPDU_SESSION_JOIN_RESPONSE");
}
/////////////发送数据操作//////////////////////////////////////////////////////
// 添加标注,发送信息
sendInsetAnnotaion(_param){
insertIdx=parseInt(Date.now()/1000);
let whiteBoardModelPdu =new pdu['RCWhiteBoardData'];
whiteBoardModelPdu.id =insertIdx;
whiteBoardModelPdu.initiator =GlobalConfig.nodeId;
whiteBoardModelPdu.data ="白板数据 "+insertIdx;
whiteBoardModelPdu.type = 3;
//required uint32 id= 1;
//required uint32 initiator=2;
//optional string data= 3;
//optional uint32 type= 4;
//RCWhiteBoardData
//com.seemq.wrcp.RCApe._update_table_item(obj_id:int, idx:int, item_data:ByteArray, has_owner:Boolean=true):int
//public function add_item(idx:int, owner:int = 0, item_data:ByteArray = null):void
//registry_table_operator.add_item(((RCConst_E.VIDEO_SESSION_ID << 16) + i), 0, channel_data); VIDEO
//tableItemPdu.itemIdx=ApeConsts.WHITEBOARD_OBJ_TABLE_ID;//收到flash的是999这个值,不清楚先写固定WHITEBOARD_OBJ_TABLE_ID
//tableItemPdu.itemIdx=ApeConsts.WHITEBOARD_OBJ_TABLE_ID+insertIdx;
//insertIdx++;
let tableItemPdu = new pdu['RCRegistryTableItemPdu'];
tableItemPdu.itemIdx=insertIdx;//直接用时间戳作为id
tableItemPdu.registerObjId=ApeConsts.WHITEBOARD_OBJ_TABLE_ID;
tableItemPdu.owner = 0;//收到flash的是这个值,不清楚先写固定
//tableItemPdu.itemData =whiteBoardModelPdu.toArrayBuffer();
tableItemPdu.itemData =whiteBoardModelPdu.toArrayBuffer();
//console.log("解析");
//console.log(pdu['RCWhiteBoardData'].decode(tableItemPdu.itemData));
/* message RCRegistryTableItemPdu {
required uint32 item_idx = 1;
required uint32 owner = 2;
required bytes item_data = 3;
}*/
//insert
let tableInsertItemPdu = new pdu['RCRegistryTableInsertItemPdu'];
//optional RCPduType_E type = 1 [default = RCPDU_REG_TABLE_UPDATE_PDU];
//repeated RCRegistryTableItemPdu items = 2;
tableInsertItemPdu.type = pdu.RCPDU_REG_TABLE_INSERT_PDU;//
tableInsertItemPdu.items.push(tableItemPdu);
let updateObjPdu = new pdu['RCRegistryUpdateObjPdu'];
updateObjPdu.objId = ApeConsts.WHITEBOARD_OBJ_TABLE_ID;
updateObjPdu.subType = tableInsertItemPdu.type;
updateObjPdu.userData = tableInsertItemPdu.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);
console.log("白板insert数据======111111111111=tableItemPdu.itemIdx="+tableItemPdu.itemIdx);
this.sendUniform(adapterPdu,true);
}
//删除所有标注
sendDeleteAllAnnotation(_param){
let len=0;
for (let key in this.annoInfos){
console.log("key:"+key);
console.log("删除白板数据,itemIdx:"+this.annoInfos[key]);
this.sendDeleteAnnotaion({"itemIdx":key});
}
}
//删除标注,发送信息
sendDeleteAnnotaion(_param){
//delete
let tableDeleteItemPdu = new pdu['RCRegistryTableDeleteItemPdu'];
//optional RCPduType_E type = 1 [default = RCPDU_REG_TABLE_DELETE_PDU];
// repeated uint32 item_idx = 2;
tableDeleteItemPdu.type = pdu.RCPDU_REG_TABLE_DELETE_PDU;//
tableDeleteItemPdu.itemIdx=parseInt(_param.itemIdx);//这里需要设置要删除的数据的itemIdx,每条数据的这个id都不一样
let updateObjPdu = new pdu['RCRegistryUpdateObjPdu'];
updateObjPdu.objId = ApeConsts.WHITEBOARD_OBJ_TABLE_ID;
updateObjPdu.subType = tableDeleteItemPdu.type;
updateObjPdu.userData = tableDeleteItemPdu.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);
console.log("白板发送删除数据============="+tableDeleteItemPdu.itemIdx);
this.sendUniform(adapterPdu,true);
}
//更新标注
sendUpdaterAnnotaion(_param){
let whiteBoardModelPdu =new pdu['RCWhiteBoardData'];
whiteBoardModelPdu.id =ApeConsts.WHITEBOARD_OBJ_TABLE_ID;
whiteBoardModelPdu.initiator =GlobalConfig.nodeId;
whiteBoardModelPdu.data ="白板数据 "+insertIdx;
whiteBoardModelPdu.type = 3;
let tableItemPdu = new pdu['RCRegistryTableItemPdu'];
/* tableItemPdu.itemIdx =ApeConsts.WHITEBOARD_OBJ_TABLE_ID;
tableItemPdu.owner = GlobalConfig.nodeId;
tableItemPdu.itemData =whiteBoardModelPdu.toArrayBuffer();*/
//com.seemq.wrcp.RCApe._update_table_item(obj_id:int, idx:int, item_data:ByteArray, has_owner:Boolean=true):int
//public function add_item(idx:int, owner:int = 0, item_data:ByteArray = null):void
//registry_table_operator.add_item(((RCConst_E.VIDEO_SESSION_ID << 16) + i), 0, channel_data); VIDEO
//tableItemPdu.itemIdx=ApeConsts.WHITEBOARD_OBJ_TABLE_ID;//收到flash的是999这个值,不清楚先写固定WHITEBOARD_OBJ_TABLE_ID
tableItemPdu.itemIdx=ApeConsts.WHITEBOARD_OBJ_TABLE_ID;
tableItemPdu.owner = 0;//收到flash的是这个值,不清楚先写固定
tableItemPdu.registerObjId=ApeConsts.WHITEBOARD_OBJ_TABLE_ID;
tableItemPdu.itemData =whiteBoardModelPdu.toArrayBuffer();
//updater
let whiteBoardUpdateItem = new pdu['RCRegistryTableUpdateItemPdu'];
//optional RCPduType_E type = 1 [default = RCPDU_REG_TABLE_UPDATE_PDU];
//repeated RCRegistryTableItemPdu items = 2;
whiteBoardUpdateItem.type = pdu.RCPDU_REG_TABLE_UPDATE_PDU;//
whiteBoardUpdateItem.items.push(tableItemPdu);
let updateObjPdu = new pdu['RCRegistryUpdateObjPdu'];
updateObjPdu.objId = ApeConsts.WHITEBOARD_OBJ_TABLE_ID;
updateObjPdu.subType = whiteBoardUpdateItem.type;
updateObjPdu.userData = whiteBoardUpdateItem.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);
console.log("白板发送更新数据===============22");
this.sendUniform(adapterPdu,true);
}
/////收到消息处理/////////////////////////////////////////////////////////////////////////////////
whiteboardMsgComingHandler(pdu) {
//loger.warn('whiteboardMsgComingHandler needs to be handled.');
console.log("白板收到数据=============================RCPDU_CONFERENCE_SEND_DATA_REQUEST");
}
tableInsertHandler(owner, itemIdx,itemData) {
this.annoInfos[itemIdx] = itemData;
console.log("白板收到数据==========tableInsertHandler");
let nodeData = pdu['RCWhiteBoardData'].decode(itemData);
console.log("白板收到数据==========tableInsertHandler"+nodeData);
console.log(nodeData);
//this.emitDocChange(ApeConsts.DOCUMENT_DEL);
}
tableUpdateHandler(owner, itemIdx, itemData) {
this.annoInfos[itemIdx] = itemData;
console.log("白板收到数据===tableUpdateHandler itemData="+itemData);
try{
console.log("白板收到数据===tableUpdateHandler ");
let whiteBoardModelPdu= pdu['RCWhiteBoardData'].decode(itemData);
console.log(whiteBoardModelPdu);
}catch (err){
console.log("tableUpdateHandler Pdu解析错误,itemIdx="+itemIdx+" err:"+err.message);
}
/*const recordInfo = pdu['RCWhiteboardDataRequestPdu'].decode(recordData);
console.log("recordInfo");
loger.log(recordInfo);
// 目前只处理 文档标注
if (recordInfo.type == ApeConsts.WBA_DOC_ANNOTATION) {
const uncompressedBytes = new Zlib.Inflate(recordInfo.action.compact().view).decompress();
const annoInfo = {
id: recordId,
svg: UTF8.getStringFromBytes(uncompressedBytes)
};
loger.log(annoInfo);
this.annoInfos[recordId] = annoInfo;
this._emit(MessageTypes.ANNOTATION_UPDATE, annoInfo);
} else {
loger.log('白板动作忽略,类型:', ApeConsts(recordInfo.type));
}*/
}
tableDeleteHandler(object_id, tableDeleteData){
console.log("白板收到数据=============================tableDeleteHandler");
}
}
export default WhiteBoardApe;