WhiteBoardApe.js
5.8 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
// //////////////////////////////////////////////////////////////////////////////
//
// 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');
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._apeDelayed = true;
}
// 添加标注,发送信息
sendAnnotaion(_param){
//var objPoint={
// "type":0,
// "id":111111,
// "color":0,
// "thickness":0,
// "radius":0,
// "text":0,
// "fontS":0,
// "fontN":0,
// "pointD":[]
//};
//message RCWhiteboardDataRequest2Pdu {
// required uint32 id = 1;
// required uint32 type = 2;
// required uint32 initiator = 3;
// required bytes drawData = 4;
//}
//message RCWhiteboardCurveLinePdu {
// required uint32 color = 1;
// required uint32 thickness = 2;
// required string pointData = 3;
//}
//
//var coverLine=new pdu['RCWhiteboardCurveLinePdu'];
//coverLine.color=0xff00ff;
//coverLine.thickness=2;
//coverLine.pointData="白板数据测试测试";
//
//var sendData=new pdu['RCWhiteboardDataRequest2Pdu'];
//sendData.id=parseInt(Date.now() / 1000);
//sendData.type=pdu.RCPDU_AUDIO_SEND_DATA_REQUEST;
//sendData.initiator = this._confInfo.nodeId;//发起人
//sendData.peer = parseInt(101);//发送给谁,公聊的时候是0,私聊的时候是指定的用户id
//sendData.isPublic = true;
//sendData.drawData=coverLine.toArrayBuffer();
//console.log("白板发送数据=============================");
//this.sendUniform(sendData);
let chatSendPdu = new pdu['RCChatSendDataRequestPdu'];
chatSendPdu.type = pdu.RCPDU_CONFERENCE_SEND_DATA_REQUEST;
chatSendPdu.initiator = this._confInfo.nodeId;//发起人
chatSendPdu.peer = parseInt(0);//发送给谁,公聊的时候是0,私聊的时候是指定的用户id
chatSendPdu.isPublic = true;
chatSendPdu.userData = this._rCArrayBufferUtil.strToUint8Array("h5" +"白板测试");
chatSendPdu.fromName = this._rCArrayBufferUtil.strToUint8Array("h5" + this._confInfo.userName);
chatSendPdu.fromRole = this._confInfo.classRole;
//同步
let adapterItemPdu = new pdu['RCAdapterItemPdu'];
adapterItemPdu.type = pdu.RCPDU_REG_UPDATE_OBJ;
adapterItemPdu.itemData = chatSendPdu.toArrayBuffer();
let adapterPdu = new pdu['RCAdapterPdu'];
adapterPdu.type = pdu.RCPDU_REG_ADAPTER;
adapterPdu.item.push(adapterItemPdu);
console.log("白板发送数据=============================QQ");
this.sendUniform(adapterPdu, true);
// this.sendUniform(chatSendPdu);
//if (!(chatSendPdu.isPublic || 0 === chatSendPdu.peer)) {
// //发送给制定的人
// this.send(chatSendPdu);
//} else {
// //发送给所有人
// this.sendUniform(chatSendPdu);
//}
}
//删除标注,发送信息
deleteAnnotaion(_param){
}
whiteboardMsgComingHandler(pdu) {
//loger.warn('whiteboardMsgComingHandler needs to be handled.');
console.log("白板收到数据=============================QQ");
}
wbReceriveHandler(chatBuffer) {
console.log("白板收到数据=============================QQ");
//var chatReceivePdu = pdu['RCChatSendDataRequestPdu'].decode(chatBuffer);
//
//var chatMsg = {};
//chatMsg.fromNodeID = chatReceivePdu.initiator;
//chatMsg.toNodeID = chatReceivePdu.peer;
//chatMsg.message = this._rCArrayBufferUtil.uint8ArrayToStr(chatReceivePdu.userData, 2);
//chatMsg.fromName = this._rCArrayBufferUtil.uint8ArrayToStr(chatReceivePdu.fromName, 2);
//chatMsg.fromRole = chatReceivePdu.fromRole;
//
//loger.log('接收聊天消息.', chatMsg);
//
//this._emit(MessageTypes.CHAT_RECEIVE, chatMsg);
}
tableInsertHandler(tableId, record) {
this.emitDocChange(ApeConsts.DOCUMENT_DEL);
}
tableUpdateHandler(owner, recordId, recordData) {
const recordInfo = pdu['RCWhiteboardDataRequestPdu'].decode(recordData);
console.log("recordInfo");
console.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)
};
this.annoInfos[recordId] = annoInfo;
this._emit(MessageTypes.ANNOTATION_UPDATE, annoInfo);
} else {
loger.log('白板动作忽略,类型:', ApeConsts(recordInfo.type));
}
}
}
export default WhiteBoardApe;