WhiteBoardApe.js
2.3 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
// //////////////////////////////////////////////////////////////////////////////
//
// 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 'pdu';
import Loger from 'Loger';
import MessageTypes from 'MessageTypes';
import { Zlib } from 'zlibjs/bin/zlib.min';
import UTF8 from 'utf-8';
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;
}
whiteboardMsgComingHandler(pdu) {
loger.warn('whiteboardMsgComingHandler needs to be handled.');
}
tableInsertHandler(tableId, record) {
this.emitDocChange(ApeConsts.DOCUMENT_DEL);
}
tableUpdateHandler(owner, recordId, recordData) {
const recordInfo = pdu['RCWhiteboardDataRequestPdu'].decode(recordData);
// 目前只处理 文档标注
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.ANNO_UPDATE, annoInfo);
} else {
loger.log('白板动作忽略,类型:', ApeConsts(recordInfo.type));
}
}
}
export default WhiteBoardApe;