Toggle navigation
Toggle navigation
此项目
正在载入...
Sign in
李勇
/
McuClient
转到一个项目
Toggle navigation
项目
群组
代码片段
帮助
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
李勇
2017-04-20 09:23:16 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
9f50a3012fd862f5a3952324058c834122049043
9f50a301
1 parent
47066cbb
1.增加MCU动态切换,如果MCU连接出错,自动重连5次没连接成功,会进行MCU选点,切换MCU再连接
隐藏空白字符变更
内嵌
并排对比
正在显示
5 个修改的文件
包含
188 行增加
和
135 行删除
dist/McuClient.js
src/EngineEntrance.js
src/EverSocket.js
src/MessageTypes.js
src/mcu.js
dist/McuClient.js
查看文件 @
9f50a30
此 diff 太大无法显示。
src/EngineEntrance.js
查看文件 @
9f50a30
...
...
@@ -27,7 +27,7 @@ import Server from "config/Server";
import
UTF8
from
'utf-8'
;
let
loger
=
Loger
.
getLoger
(
'McuClient'
);
let
_sdkInfo
=
{
"version"
:
"v1.9.1
1
.20170419"
,
"author"
:
"www.3mang.com"
};
let
_sdkInfo
=
{
"version"
:
"v1.9.1
2
.20170419"
,
"author"
:
"www.3mang.com"
};
//APE
let
_sass
;
...
...
@@ -78,6 +78,7 @@ export default class MessageEntrance extends Emiter {
_mcu
=
Mcu
;
_mcu
.
on
(
'*'
,
(
type
,
data
)
=>
this
.
_emit
(
type
,
data
));
_mcu
.
on
(
MessageTypes
.
CLASS_JOIN_MCU_SUCCESS
,
this
.
_mcuJoinMCUClassSuccessHandler
.
bind
(
this
));
//加入MCU课堂完成
_mcu
.
on
(
MessageTypes
.
CHANGE_MCU_IP
,
this
.
_changeMcuIpHandler
.
bind
(
this
));
//切换MCU,重新选点
//录制回放
_recordPlayback
=
RecordPlayBackParse
;
...
...
@@ -198,8 +199,8 @@ export default class MessageEntrance extends Emiter {
_mcuErrorHandler
(
_data
,
_option
)
{
let
option
=
_option
||
""
;
let
errorMessage
=
{
"code"
:
_data
,
"reson"
:
MessageTypes
.
ErrorReson
[
_data
]
+
" "
+
option
};
loger
.
error
(
"MCU_ERROR"
,
errorMessage
);
this
.
_emit
(
MessageTypes
.
ERROR_EVENT
,
errorMessage
);
loger
.
error
(
"MCU_ERROR"
,
errorMessage
);
}
//获取当前的状态
...
...
@@ -734,6 +735,31 @@ export default class MessageEntrance extends Emiter {
this
.
_emit
(
MessageTypes
.
CLASS_JOIN_SUCCESS
,
joinClassSuccessCallBackData
);
}
//切换MCU
_changeMcuIpHandler
(){
if
(
GlobalConfig
.
isRecordPlayBack
){
//录制回放不做操作
return
;
}
loger
.
log
(
'MCU->动态选点'
);
let
_this
=
this
;
this
.
_getFastestMcuServer
(
function
(
_data
)
{
loger
.
log
(
"MCU选点结束->"
,
_data
);
if
(
_data
&&
_data
.
ip
)
{
GlobalConfig
.
MCUServerIP
=
_data
.
ip
;
GlobalConfig
.
MCUServerPort
=
_data
.
port
;
}
else
{
//随机选择一个
if
(
GlobalConfig
.
mcuList
&&
GlobalConfig
.
mcuList
.
length
>
0
)
{
let
index
=
parseInt
(
Math
.
random
()
*
GlobalConfig
.
mcuList
.
length
);
GlobalConfig
.
DOCServerIP
=
GlobalConfig
.
mcuList
[
index
].
ip
||
""
;
GlobalConfig
.
DOCServerPort
=
GlobalConfig
.
mcuList
[
index
].
port
||
""
;
}
}
loger
.
log
(
'MCU->切换->'
,
GlobalConfig
.
DOCServerIP
,
GlobalConfig
.
DOCServerPort
);
});
}
//Sass删除文档数据
_sassDeleteDocument
(
_param
)
{
if
(
!
_mcu
.
connected
)
{
...
...
src/EverSocket.js
查看文件 @
9f50a30
...
...
@@ -15,153 +15,164 @@
import
Emiter
from
'Emiter'
;
import
Loger
from
'Loger'
;
let
loger
=
Loger
.
getLoger
(
'EverSocket'
);
const
MCU_MAX_RECONNECTION
=
5
;
//最多重连次数
class
EverSocket
extends
Emiter
{
constructor
()
{
super
();
this
.
_connected
=
false
;
this
.
_lastActiveTime
=
0
;
//最后一次收到消息的时间
this
.
_enableEverSocket
=
false
;
}
begin
(
ip
,
port
)
{
loger
.
log
(
'开始WebSocket应用.'
);
this
.
_enableEverSocket
=
true
;
this
.
wsURL
=
'ws://'
+
ip
+
':'
+
port
;
this
.
_newConnection
();
}
end
()
{
loger
.
log
(
'停止WebSocket应用.'
);
this
.
_clear
();
}
get
connected
()
{
return
this
.
_connected
;
}
send
(
data
)
{
if
(
this
.
_connected
)
{
if
(
data
){
loger
.
log
(
'SEND MESSAGE,byteLength---->'
,
data
.
byteLength
);
}
else
{
loger
.
log
(
'SEND MESSAGE---->'
);
}
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
)
{
loger
.
log
(
'开始WebSocket应用.'
);
this
.
_enableEverSocket
=
true
;
this
.
wsURL
=
'ws://'
+
ip
+
':'
+
port
;
this
.
_newConnection
();
}
end
()
{
loger
.
log
(
'停止WebSocket应用.'
);
this
.
_clear
();
}
}
_setConnected
(
isConn
=
true
)
{
this
.
_connected
=
isConn
;
if
(
this
.
_connected
)
{
this
.
_emit
(
EverSocket
.
OPEN
);
}
else
{
this
.
_emit
(
EverSocket
.
CLOSED
);
get
connected
()
{
return
this
.
_connected
;
}
send
(
data
)
{
if
(
this
.
_connected
)
{
if
(
data
)
{
loger
.
log
(
'SEND MESSAGE,byteLength---->'
,
data
.
byteLength
);
}
else
{
loger
.
log
(
'SEND MESSAGE---->'
);
}
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
()
{
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
();
this
.
reConnectionTimeout
=
window
.
setTimeout
(()
=>
{
loger
.
log
(
'WebSocket重新建立.'
);
window
.
clearTimeout
(
this
.
reConnectionTimeout
);
this
.
_newConnection
();
},
EverSocket
.
RECONN_INTERVAL
);
}
_clear
()
{
//this._emit(EverSocket.CLOSED);
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
;
_newConnection
()
{
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
);
}
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'
);
_reConnection
()
{
this
.
_clear
();
window
.
clearTimeout
(
this
.
reConnectionTimeout
);
this
.
reConnectionCounter
++
;
if
(
this
.
reConnectionCounter
>
MCU_MAX_RECONNECTION
)
{
loger
.
warn
(
'已经达到最大重连次数!'
);
this
.
_emit
(
EverSocket
.
ERROR
,
EverSocket
.
ERR_SOCKET_RECONNECT_FAILED
);
this
.
reConnectionCounter
=
0
;
}
this
.
reConnectionTimeout
=
window
.
setTimeout
(()
=>
{
loger
.
log
(
'WebSocket重新建立.'
);
window
.
clearTimeout
(
this
.
reConnectionTimeout
);
this
.
_newConnection
();
},
EverSocket
.
RECONN_INTERVAL
);
}
this
.
websocket
=
undefined
;
}
_clear
()
{
//this._emit(EverSocket.CLOSED);
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
;
_onOpen
()
{
loger
.
log
(
'WebSocket建立成功'
,
this
.
wsURL
);
}
//启动心跳,检查socket链接状态
this
.
pingTimer
=
window
.
setInterval
(
this
.
_sendPingHandler
.
bind
(
this
),
EverSocket
.
PING_INTERVAL
);
this
.
pongTimer
=
window
.
setInterval
(
this
.
_checkPongHandler
.
bind
(
this
),
EverSocket
.
PONG_INTERVAL
);
_onOpen
()
{
loger
.
log
(
'WebSocket建立成功'
,
this
.
wsURL
);
this
.
reConnectionCounter
=
0
;
this
.
_setConnected
();
}
//启动心跳,检查socket链接状态
this
.
pingTimer
=
window
.
setInterval
(
this
.
_sendPingHandler
.
bind
(
this
),
EverSocket
.
PING_INTERVAL
);
this
.
pongTimer
=
window
.
setInterval
(
this
.
_checkPongHandler
.
bind
(
this
),
EverSocket
.
PONG_INTERVAL
);
_onClose
(
closeEvent
)
{
loger
.
log
(
`
WebSocket
连接断开
CODE
:
$
{
closeEvent
.
code
}
REASON
:
$
{
closeEvent
.
reason
}
CLEAN
:
$
{
closeEvent
.
wasClean
}
`
,
this
.
wsURL
);
this
.
_reConnection
();
}
this
.
_setConnected
();
}
_onError
()
{
loger
.
log
(
'WebSocket错误出现'
);
this
.
_connected
=
false
;
this
.
_reConnection
();
}
_onClose
(
closeEvent
)
{
loger
.
log
(
`
WebSocket
连接断开
CODE
:
$
{
closeEvent
.
code
}
REASON
:
$
{
closeEvent
.
reason
}
CLEAN
:
$
{
closeEvent
.
wasClean
}
`
,
this
.
wsURL
);
this
.
_reConnection
();
}
_onMessage
(
messageEvent
)
{
loger
.
log
(
'<----RECEIVE MESSAGE'
);
this
.
_lastActiveTime
=
Date
.
now
();
const
bufferData
=
messageEvent
.
data
;
if
(
bufferData
.
byteLength
>
0
)
{
this
.
_emit
(
EverSocket
.
MESSAGE
,
bufferData
);
_onError
()
{
loger
.
log
(
'WebSocket错误出现'
);
this
.
_connected
=
false
;
this
.
_reConnection
();
}
}
_sendPingHandler
()
{
if
(
this
.
_connected
)
{
this
.
websocket
.
send
(
new
ArrayBuffer
);
}
else
{
this
.
_reConnection
();
_onMessage
(
messageEvent
)
{
loger
.
log
(
'<----RECEIVE MESSAGE'
);
this
.
_lastActiveTime
=
Date
.
now
();
const
bufferData
=
messageEvent
.
data
;
if
(
bufferData
.
byteLength
>
0
)
{
this
.
_emit
(
EverSocket
.
MESSAGE
,
bufferData
);
}
}
}
_checkPongHandler
()
{
let
pongTime
=
Date
.
now
();
if
(
this
.
_lastActiveTime
&&
this
.
_lastActiveTime
>=
pongTime
-
EverSocket
.
PONG_INTERVAL
&&
this
.
_lastActiveTime
<=
pongTime
)
{
}
else
{
loger
.
warn
(
'---服务器PINGPONG超时-----'
);
this
.
_reConnection
();
_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
();
}
}
}
}
/*//修改之前的
EverSocket.prototype.PONG_INTERVAL = EverSocket.PONG_INTERVAL = 5000;
EverSocket.prototype.PING_INTERVAL = EverSocket.PING_INTERVAL = 3000;
EverSocket.prototype.RECONN_INTERVAL = EverSocket.RECONN_INTERVAL = 2000;*/
EverSocket.prototype.PONG_INTERVAL = EverSocket.PONG_INTERVAL = 5000;
EverSocket.prototype.PING_INTERVAL = EverSocket.PING_INTERVAL = 3000;
EverSocket.prototype.RECONN_INTERVAL = EverSocket.RECONN_INTERVAL = 2000;*/
//20170223-mcu服务端修改了心跳的逻辑,如果客户端30秒没有请求,就会按离开的处理
...
...
@@ -170,11 +181,14 @@ EverSocket.prototype.PONG_INTERVAL = EverSocket.PONG_INTERVAL = 21000;//
EverSocket
.
prototype
.
PING_INTERVAL
=
EverSocket
.
PING_INTERVAL
=
10000
;
//心跳间隔
EverSocket
.
prototype
.
RECONN_INTERVAL
=
EverSocket
.
RECONN_INTERVAL
=
3000
;
//重连的间隔
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
;
EverSocket
.
prototype
.
CLOSING
=
EverSocket
.
CLOSING
=
2
;
EverSocket
.
prototype
.
CLOSED
=
EverSocket
.
CLOSED
=
3
;
EverSocket
.
prototype
.
MESSAGE
=
EverSocket
.
MESSAGE
=
4
;
EverSocket
.
prototype
.
ERROR
=
EverSocket
.
ERROR
=
5
;
export
default
new
EverSocket
();
...
...
src/MessageTypes.js
查看文件 @
9f50a30
...
...
@@ -42,8 +42,6 @@ MessageTypes.VIDEO_BROADCAST= "video_broadcast";//'视频控制广播消息;
MessageTypes
.
VIDEO_GET_PUBLISH_PATH
=
"video_get_publish_path"
;
//获取视频推流地址
MessageTypes
.
VIDEO_PUBLISH_RESULT
=
"video_publish_result"
;
//获取视频推流结果
//音频模块事件定义
MessageTypes
.
AUDIO_PLAY
=
"audio_play"
;
// 'audio.play';//播放
MessageTypes
.
AUDIO_STOP
=
"audio_stop"
;
//'audio.stop';//停止
...
...
@@ -52,6 +50,9 @@ MessageTypes.AUDIO_BROADCAST= "audio_broadcast";//'audio.broadcast';
MessageTypes
.
AUDIO_GET_PUBLISH_PATH
=
"audio_get_publish_path"
;
//获取音频推流地址
MessageTypes
.
AUDIO_PUBLISH_RESULT
=
"audio_publish_result"
;
//获取音频推流结果
MessageTypes
.
CHANGE_MS_IP
=
"change_ms_ip"
;
//切换ms 重新选点
//文档模块事件定义
MessageTypes
.
DOC_DELETE
=
"document_delete"
;
//'document.delete';//删除文档
MessageTypes
.
DOC_UPDATE
=
"document_update"
;
// 'document.update';//更新文档(添加、变更)
...
...
@@ -71,6 +72,10 @@ MessageTypes.WHITEBOARD_ANNOTATION_UPDATE ="whiteboard_annotation_update";// 'wh
//MessageTypes.WHITEBOARD_ANNOTATION_CLEAR = 'whiteboard.annotation.clear';
//MCU
MessageTypes
.
CHANGE_MCU_IP
=
"change_mcu_ip"
;
//切换mcu 重新选点
//录制回放
MessageTypes
.
RECORD_PLAYBACK_UPDATE
=
"record_playback_update"
;
//录制回放更新信息
...
...
@@ -127,6 +132,7 @@ MessageTypes.ERR_NETWORK=10000;//网络错误
MessageTypes
.
ERR_UNKNOWN
=
10001
;
//未知错误
MessageTypes
.
ERR_SOCKET_DISCONNECT
=
20000
;
//MCU断开连接,已经离开课堂
MessageTypes
.
ERR_SOCKET_RECONNECT_FAILED
=
20001
;
//MCU自动重连失败,已经达到最大重连次数
//---------------错误消息 Error Reson 定义-------------------------------------------------
MessageTypes
.
ErrorReson
=
{};
...
...
@@ -178,8 +184,7 @@ MessageTypes.ErrorReson[MessageTypes.ERR_NETWORK]="网络错误";
MessageTypes
.
ErrorReson
[
MessageTypes
.
ERR_UNKNOWN
]
=
"未知错误"
;
MessageTypes
.
ErrorReson
[
MessageTypes
.
ERR_SOCKET_DISCONNECT
]
=
"MCU断开连接,已经离开课堂"
;
MessageTypes
.
ErrorReson
[
MessageTypes
.
ERR_SOCKET_RECONNECT_FAILED
]
=
"MCU自动重连失败,已经达到最大重连次数"
;
export
default
MessageTypes
;
...
...
src/mcu.js
查看文件 @
9f50a30
...
...
@@ -24,6 +24,7 @@ class MCU extends Emiter {
this
.
_everSocket
.
on
(
everSocket
.
OPEN
,
this
.
_everSocketOpenHandler
.
bind
(
this
));
this
.
_everSocket
.
on
(
everSocket
.
MESSAGE
,
this
.
_everSocketMsgReceivedHandler
.
bind
(
this
));
this
.
_everSocket
.
on
(
everSocket
.
CLOSED
,
this
.
_everSocketCloseHandler
.
bind
(
this
));
this
.
_everSocket
.
on
(
everSocket
.
ERROR
,
this
.
_everSocketErrorHandler
.
bind
(
this
));
}
// 注册Ape
...
...
@@ -41,7 +42,14 @@ class MCU extends Emiter {
GlobalConfig
.
setCurrentStatus
(
GlobalConfig
.
statusCode_3
);
this
.
_emit
(
MessageTypes
.
MCU_ERROR
,
MessageTypes
.
ERR_SOCKET_DISCONNECT
);
}
//EverSocket错误异常
_everSocketErrorHandler
(
_errorCode
){
this
.
_emit
(
MessageTypes
.
MCU_ERROR
,
_errorCode
);
//如果自动重连次数已经达到最大值,重新选点
if
(
_errorCode
==
everSocket
.
ERR_SOCKET_RECONNECT_FAILED
){
this
.
_emit
(
MessageTypes
.
CHANGE_MCU_IP
);
}
}
//MCU-发送加入课堂请求
_sendJoinClassRequest
()
{
...
...
请
注册
或
登录
后发表评论