李勇

1.发送数据到MCU增加大小限制 最大10kb;2.优化日志输出

... ... @@ -63,7 +63,7 @@ export default class MessageEntrance extends Emiter {
super();
this.lastClassActiveTime=0;//最后一次课堂激活的时间戳
//sdk 信息
GlobalConfig.sdkVersion = "v2.26.4.20171102";
GlobalConfig.sdkVersion = "v2.26.6.20171103";
loger.warn("sdkVersion:" + GlobalConfig.sdkVersion);
console.log("sdkVersion:" + GlobalConfig.sdkVersion);
//设置
... ... @@ -2527,11 +2527,12 @@ export default class MessageEntrance extends Emiter {
//文档加入频道成功,同步到MCU服务器上的数据
docJoinChannelSuccess() {
let interval=new Date().getTime()-parseInt(this.lastClassActiveTime);
loger.log("最后一次记录的时间->"+this.lastClassActiveTime,"当前时间:"+new Date().getTime(),"间隔:"+interval/1000);
interval=interval/1000;
loger.log("最后一次记录的时间->"+this.lastClassActiveTime,"当前时间:"+new Date().getTime(),"间隔:"+interval+"秒");
loger.log("文档加入频道成功->isHost=", GlobalConfig.isHost, "当前总人数:", GlobalConfig.rosterNumber, "sassDoclength=", GlobalConfig.docListPrepare.length);
//如果当前课堂内只有自己或者离开上次课堂的时间大于8分钟,需要停止服务端的视频录制
if(GlobalConfig.rosterNumber<=1&&interval>=(8*60)){
//如果当前课堂内只有自己或者离开上次课堂的时间大于8分钟,需要停止服务端的视频录制,设备不是H5
if(GlobalConfig.rosterNumber<=1&&interval>=(8*60)&&GlobalConfig.deviceType!=3){
loger.log("调用服务端音视频停止录制->interval:"+interval);
this._mediaRecordControl({"status": WebRtcApe.RECORD_STATUS_2});
}
... ... @@ -3270,7 +3271,7 @@ export default class MessageEntrance extends Emiter {
if (!_params) {
return;
}
loger.log("设置appConfig", _params);
loger.log("设置appConfig");
if (GlobalConfig.appId) {
loger.log("本地已经设置appConfig,不需要再设置");
return;
... ...
... ... @@ -19,199 +19,210 @@ import GlobalConfig from 'GlobalConfig';
let loger = Loger.getLoger('EverSocket');
const MCU_MAX_RECONNECTION = 4;//最多重连次数
class EverSocket extends Emiter {
constructor() {
super();
this._connected = false;
this._lastActiveTime = 0;//最后一次收到消息的时间
this._enableEverSocket = false;
this.reConnectionCounter = 0;//重连次数
}
begin(ip, port) {
this._clearHistory();
loger.log('开始WebSocket应用.');
if(!ip){
loger.error('开始MCU连接->MCU连接地址无效');
}
this._enableEverSocket = true;
//this.wsURL = 'ws://' + ip + ':' + port;
if(port){
this.wsURL = GlobalConfig.websocketProtocol + ip + ':' + port;
}else {
this.wsURL = GlobalConfig.websocketProtocol + ip;
}
this._newConnection();
}
end() {
loger.log('停止WebSocket应用.');
this._clear();
}
switchSocketIp(ip,port) {
/* if(port){
this.wsURL = 'ws://' + ip + ':' + port;
}else {
this.wsURL = 'ws://' + ip;
}*/
if(port){
this.wsURL = GlobalConfig.websocketProtocol + ip + ':' + port;
}else {
this.wsURL = GlobalConfig.websocketProtocol + ip;
}
}
get connected() {
return this._connected;
}
send(data) {
if (this._connected) {
if (data&& data.byteLength>1024) {
loger.warn('发送到MCU的数据文件超过1k-->byteLength->', data.byteLength);
}
this.websocket.send(data);
} else {
loger.warn('WebSocket未建立连接.消息忽略');
constructor() {
super();
this._connected = false;
this._lastActiveTime = 0;//最后一次收到消息的时间
this._enableEverSocket = false;
this.reConnectionCounter = 0;//重连次数
}
begin(ip, port) {
this._clearHistory();
loger.log('开始WebSocket应用.');
if (!ip) {
loger.error('开始MCU连接->MCU连接地址无效');
}
this._enableEverSocket = true;
//this.wsURL = 'ws://' + ip + ':' + port;
if (port) {
this.wsURL = GlobalConfig.websocketProtocol + ip + ':' + port;
} else {
this.wsURL = GlobalConfig.websocketProtocol + ip;
}
this._newConnection();
}
end() {
loger.log('停止WebSocket应用.');
this._clear();
}
switchSocketIp(ip, port) {
/* if(port){
this.wsURL = 'ws://' + ip + ':' + port;
}else {
this.wsURL = 'ws://' + ip;
}*/
if (port) {
this.wsURL = GlobalConfig.websocketProtocol + ip + ':' + port;
} else {
this.wsURL = GlobalConfig.websocketProtocol + ip;
}
}
get connected() {
return this._connected;
}
send(data) {
if (this._connected) {
if (data) {
let len=data.byteLength;
if (len> 1024) {
loger.warn('发送到MCU的数据文件超过1k-->byteLength->', len);
}
}
_setConnected(isConn = true) {
this._connected = isConn;
if (this._connected) {
this._emit(EverSocket.OPEN);
} else {
this._emit(EverSocket.CLOSED);
if (len>=1024*10) {
loger.warn('发送到MCU的数据文件超过10k-->byteLength->', len);
return;
}
}
_newConnection() {
if(GlobalConfig.isHttps==true){
//https的时候替换所有80端口
this.wsURL= GlobalConfig.replacePort(this.wsURL,":80","");
}
this.websocket = new WebSocket(this.wsURL);
this.websocket.binaryType = 'arraybuffer';
this.websocket.onopen = this._onOpen.bind(this);
this.websocket.onclose = this._onClose.bind(this);
this.websocket.onerror = this._onError.bind(this);
this.websocket.onmessage = this._onMessage.bind(this);
}
_reConnection() {
this._clear();
window.clearTimeout(this.reConnectionTimeout);
this.reConnectionCounter++;
if (this.reConnectionCounter > MCU_MAX_RECONNECTION) {
loger.warn('MCU断线重连->已经达到最大重连次数!');
this._emit(EverSocket.ERROR, EverSocket.ERR_SOCKET_RECONNECT_FAILED);
this.reConnectionCounter=0;
}
this.reConnectionTimeout = window.setTimeout(() => {
loger.log('MCU断线重连->', this.reConnectionCounter);
window.clearTimeout(this.reConnectionTimeout);
this._newConnection();
}, EverSocket.RECONN_INTERVAL);
}
_clear() {
loger.log('WebSocket,Timers销毁');
window.clearInterval(this.pingTimer);
window.clearInterval(this.pongTimer);
window.clearInterval(this.reConnectionTimeout);
this._setConnected(false);//先设置状态
this._enableEverSocket = false;
if (this.websocket == null) {
loger.log('WebSocket,Timers已经销毁');
return;
}
this.websocket.onopen = undefined;
this.websocket.onclose = undefined;
this.websocket.onerror = undefined;
this.websocket.onmessage = undefined;
try {
this.websocket.close();
} catch (e) {
loger.log('ignore errors');
}
this.websocket = undefined;
}
_clearHistory(){
loger.log('WebSocket->清除记录');
window.clearInterval(this.pingTimer);
window.clearInterval(this.pongTimer);
window.clearInterval(this.reConnectionTimeout);
//this._setConnected(false);//先设置状态
this._connected = false;
this._enableEverSocket = false;
if (this.websocket == null) {
loger.log('WebSocket->已经销毁');
return;
}
this.websocket.onopen = undefined;
this.websocket.onclose = undefined;
this.websocket.onerror = undefined;
this.websocket.onmessage = undefined;
try {
this.websocket.close();
} catch (e) {
loger.log('ignore errors');
}
this.websocket = undefined;
}
_onOpen() {
loger.log('WebSocket建立成功', this.wsURL);
this.reConnectionCounter = 0;
//启动心跳,检查socket链接状态
this.pingTimer = window.setInterval(this._sendPingHandler.bind(this), EverSocket.PING_INTERVAL);
this.pongTimer = window.setInterval(this._checkPongHandler.bind(this), EverSocket.PONG_INTERVAL);
this._setConnected();
}
_onClose(closeEvent) {
loger.log(`WebSocket连接断开 CODE:${closeEvent.code} REASON:${closeEvent.reason} CLEAN: ${closeEvent.wasClean}`, this.wsURL);
this._reConnection();
}
_onError() {
loger.log('WebSocket错误出现');
this._connected = false;
this._reConnection();
}
_onMessage(messageEvent) {
this._lastActiveTime = Date.now();
const bufferData = messageEvent.data;
//loger.log('RECEIVE MESSAGE-->byteLength->',bufferData.byteLength);
if (bufferData.byteLength > 0) {
this._emit(EverSocket.MESSAGE, bufferData);
}
}
_sendPingHandler() {
if (this._connected) {
this.websocket.send(new ArrayBuffer);
} else {
this._reConnection();
}
}
_checkPongHandler() {
let pongTime = Date.now();
if (this._lastActiveTime &&
this._lastActiveTime >= pongTime - EverSocket.PONG_INTERVAL &&
this._lastActiveTime <= pongTime
) {
} else {
loger.warn('---服务器PINGPONG超时-----');
this._reConnection();
}
}
this.websocket.send(data);
} else {
loger.warn('WebSocket未建立连接.消息忽略');
}
}
_setConnected(isConn = true) {
this._connected = isConn;
if (this._connected) {
this._emit(EverSocket.OPEN);
} else {
this._emit(EverSocket.CLOSED);
}
}
_newConnection() {
if (GlobalConfig.isHttps == true) {
//https的时候替换所有80端口
this.wsURL = GlobalConfig.replacePort(this.wsURL, ":80", "");
}
this.websocket = new WebSocket(this.wsURL);
this.websocket.binaryType = 'arraybuffer';
this.websocket.onopen = this._onOpen.bind(this);
this.websocket.onclose = this._onClose.bind(this);
this.websocket.onerror = this._onError.bind(this);
this.websocket.onmessage = this._onMessage.bind(this);
}
_reConnection() {
this._clear();
window.clearTimeout(this.reConnectionTimeout);
this.reConnectionCounter++;
if (this.reConnectionCounter > MCU_MAX_RECONNECTION) {
loger.warn('MCU断线重连->已经达到最大重连次数!');
this._emit(EverSocket.ERROR, EverSocket.ERR_SOCKET_RECONNECT_FAILED);
this.reConnectionCounter = 0;
}
this.reConnectionTimeout = window.setTimeout(() => {
loger.log('MCU断线重连->', this.reConnectionCounter);
window.clearTimeout(this.reConnectionTimeout);
this._newConnection();
}, EverSocket.RECONN_INTERVAL);
}
_clear() {
loger.log('WebSocket,Timers销毁');
window.clearInterval(this.pingTimer);
window.clearInterval(this.pongTimer);
window.clearInterval(this.reConnectionTimeout);
this._setConnected(false);//先设置状态
this._enableEverSocket = false;
if (this.websocket == null) {
loger.log('WebSocket,Timers已经销毁');
return;
}
this.websocket.onopen = undefined;
this.websocket.onclose = undefined;
this.websocket.onerror = undefined;
this.websocket.onmessage = undefined;
try {
this.websocket.close();
} catch (e) {
loger.log('ignore errors');
}
this.websocket = undefined;
}
_clearHistory() {
loger.log('WebSocket->清除记录');
window.clearInterval(this.pingTimer);
window.clearInterval(this.pongTimer);
window.clearInterval(this.reConnectionTimeout);
//this._setConnected(false);//先设置状态
this._connected = false;
this._enableEverSocket = false;
if (this.websocket == null) {
loger.log('WebSocket->已经销毁');
return;
}
this.websocket.onopen = undefined;
this.websocket.onclose = undefined;
this.websocket.onerror = undefined;
this.websocket.onmessage = undefined;
try {
this.websocket.close();
} catch (e) {
loger.log('ignore errors');
}
this.websocket = undefined;
}
_onOpen() {
loger.log('WebSocket建立成功', this.wsURL);
this.reConnectionCounter = 0;
//启动心跳,检查socket链接状态
this.pingTimer = window.setInterval(this._sendPingHandler.bind(this), EverSocket.PING_INTERVAL);
this.pongTimer = window.setInterval(this._checkPongHandler.bind(this), EverSocket.PONG_INTERVAL);
this._setConnected();
}
_onClose(closeEvent) {
loger.log(`WebSocket连接断开 CODE:${closeEvent.code} REASON:${closeEvent.reason} CLEAN: ${closeEvent.wasClean}`, this.wsURL);
this._reConnection();
}
_onError() {
loger.log('WebSocket错误出现');
this._connected = false;
this._reConnection();
}
_onMessage(messageEvent) {
this._lastActiveTime = Date.now();
const bufferData = messageEvent.data;
//loger.log('RECEIVE MESSAGE-->byteLength->',bufferData.byteLength);
if (bufferData.byteLength > 0) {
this._emit(EverSocket.MESSAGE, bufferData);
}
}
_sendPingHandler() {
if (this._connected) {
this.websocket.send(new ArrayBuffer);
} else {
this._reConnection();
}
}
_checkPongHandler() {
let pongTime = Date.now();
if (this._lastActiveTime &&
this._lastActiveTime >= pongTime - EverSocket.PONG_INTERVAL &&
this._lastActiveTime <= pongTime
) {
} else {
loger.warn('---服务器PINGPONG超时-----');
this._reConnection();
}
}
}
... ... @@ -228,7 +239,7 @@ EverSocket.prototype.PING_INTERVAL = EverSocket.PING_INTERVAL = 10000;//心跳
EverSocket.prototype.RECONN_INTERVAL = EverSocket.RECONN_INTERVAL = 5000;//重连的间隔
EverSocket.prototype.ERR_SOCKET_RECONNECT_FAILED =EverSocket.ERR_SOCKET_RECONNECT_FAILED=20001;//MCU自动重连失败,已经达到最大重连次数
EverSocket.prototype.ERR_SOCKET_RECONNECT_FAILED = EverSocket.ERR_SOCKET_RECONNECT_FAILED = 20001;//MCU自动重连失败,已经达到最大重连次数
EverSocket.prototype.CONNECTING = EverSocket.CONNECTING = 0;
EverSocket.prototype.OPEN = EverSocket.OPEN = 1;
... ...
... ... @@ -62,7 +62,7 @@ class LogManager {
//发送log到服务器
static sendLogToServer(_msgType) {
if (!this.logUrl) {
console.warn("日志服务器地址无效->无法上传日志");
console.warn("日志服务器地址->"+this.logUrl);
return;
}
const msgType = _msgType;
... ...
// //////////////////////////////////////////////////////////////////////////////
//
// 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: 2017-06-29 14:09:25
// Description: LiveClass-CursorApe
//
// //////////////////////////////////////////////////////////////////////////////
import Ape from './Ape';
import ApeConsts from './ApeConsts';
import pdu from 'pdus';
... ... @@ -87,8 +72,6 @@ class CursorApe extends Ape {
let adapterPdu = new pdu['RCAdapterPdu'];
adapterPdu.type = pdu.RCPDU_REG_ADAPTER;
adapterPdu.item.push(adapterItemPdu);
loger.log("发送更新.itemIdx=" + tableItemPdu.itemIdx);
this.sendUniform(adapterPdu, true);
}
... ... @@ -96,7 +79,7 @@ class CursorApe extends Ape {
tableUpdateHandler(owner, itemIdx, itemData) {
let cursorModel = this.unPackPdu(owner, itemIdx, itemData);
// loger.log('鼠标数据->tableUpdateHandler');
loger.log(cursorModel);
//loger.log(cursorModel);
if (cursorModel) {
this._emit(MessageTypes.CURSOR_UPDATE, cursorModel);
}
... ...
... ... @@ -587,8 +587,15 @@ class DocApe extends Ape {
//loger.log('添加文档->设置当前激活的文档id');
}
let getdocPackFullInfo = this._docPackFullInfo(itemDataInfo);
loger.log('添加文档->', getdocPackFullInfo);
this._emit(MessageTypes.DOC_UPDATE, getdocPackFullInfo);//用添加和更新都统一DOC_UPDATE
//日志输出
let docInfo = this._docPackFullInfo(itemDataInfo);
if(docInfo){
delete docInfo.images;
loger.log('添加文档->', docInfo);
}
} else {
loger.warn('文档数据解析失败->删除->itemIdx:' + insertItem.itemIdx);
this.documentDelete({"itemIdx": insertItem.itemIdx});
... ...
... ... @@ -23,7 +23,7 @@ class MediaModule {
//获取播流地址
getMediaPlayPath(_param) {
loger.log('获取播放地址->');
//loger.log('获取播放地址->');
if (_param == null || _param.streamId == null) {
loger.warn('获取播放地址->参数错误', _param);
//this._emit(MessageTypes.MCU_ERROR, MessageTypes.ERR_APE_INTERFACE_PARAM_WRONG);
... ... @@ -96,7 +96,7 @@ class MediaModule {
//获取录制回放时点播的地址,只有m3u8
getMediaRecordPlaybackPath(_param) {
loger.log('获取录制回放时点播的地址->m3u8');
//loger.log('获取录制回放时点播的地址->m3u8');
if (_param == null || _param.streamId == null) {
loger.warn('获取录制回放时点播的地址->参数错误', _param);
return {"code": ApeConsts.RETURN_FAILED, "data": ""};
... ...
... ... @@ -119,8 +119,7 @@ class MediaSharedApe extends Ape {
//把总时间取出来,外部更新的时候不传这个值
_pduDataModel.duration=localDataItem.duration||0;
}
loger.log("发送媒体文件->更新 ", _pduDataModel);
//loger.log("发送媒体文件->更新 ", _pduDataModel);
let pduDataModel = this.packPdu(_pduDataModel, _itemIdx);
let tableItemPdu = new pdu['RCRegistryTableItemPdu'];
... ...
... ... @@ -119,7 +119,7 @@ class MusicSharedApe extends Ape {
//把总时间取出来,外部更新的时候不传这个值
_pduDataModel.duration=localDataItem.duration||0;
}
loger.log("发送伴音文件->更新 ", _pduDataModel);
// loger.log("发送伴音文件->更新 ", _pduDataModel);
let pduDataModel = this.packPdu(_pduDataModel, _itemIdx);
let tableItemPdu = new pdu['RCRegistryTableItemPdu'];
... ...
... ... @@ -228,7 +228,7 @@ class VideoApe extends Ape {
}
//推流状态发生改变
mediaPublishStatusChange(_data){
loger.log("推流状态发生改变->",_data);
//loger.log("推流状态发生改变->",_data);
this.sendVideoBroadcastMsg({
"actionType": ApeConsts.MEDIA_ACTION_PUBLISH_STATUS,
"toNodeId": 0,
... ...
... ... @@ -458,7 +458,7 @@ class WebRtcApe extends Emiter {
}
//根据nodeId查找视频
try {
loger.log("立即删除停止推流人员的视图");
//loger.log("立即删除停止推流人员的视图");
$('#' + this.xdyRemote + _data.nodeId).remove();
} catch (err) {
... ...