File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -52,7 +52,8 @@ const defaultConfiguration = {
5252 }
5353 } ,
5454 ws : {
55- port : null
55+ port : null ,
56+ ping : 30 * 1000
5657 } ,
5758 proxy : [
5859 /*
Original file line number Diff line number Diff line change @@ -165,6 +165,18 @@ class CoreServiceProvider extends ServiceProvider {
165165 ws . upgradeReq = ws . upgradeReq || req ;
166166 ws . _osjs_client = Object . assign ( { } , req . session . user ) ;
167167
168+ const interval = this . core . config ( 'ws.ping' , 0 ) ;
169+
170+ const pingInterval = interval ? setInterval ( ( ) => {
171+ ws . send ( JSON . stringify ( {
172+ name : 'osjs/core:ping'
173+ } ) ) ;
174+ } , interval ) : undefined ;
175+
176+ ws . on ( 'close' , ( ) => {
177+ clearInterval ( pingInterval ) ;
178+ } ) ;
179+
168180 ws . on ( 'message' , msg => {
169181 try {
170182 const { name, params} = JSON . parse ( msg ) ;
You can’t perform that action at this time.
0 commit comments