File tree Expand file tree Collapse file tree 2 files changed +27
-9
lines changed Expand file tree Collapse file tree 2 files changed +27
-9
lines changed Original file line number Diff line number Diff line change @@ -771,6 +771,8 @@ class SocketClient {
771
771
this . socket . on ( 'cursor activity' , this . cursorActivityEventHandler . bind ( this ) )
772
772
// received cursor blur
773
773
this . socket . on ( 'cursor blur' , this . cursorBlurEventHandlder . bind ( this ) )
774
+ // check version
775
+ this . socket . on ( 'version' , this . checkVersionEventHandler . bind ( this ) )
774
776
}
775
777
776
778
isNoteAndUserExists ( ) {
@@ -812,6 +814,13 @@ class SocketClient {
812
814
} )
813
815
}
814
816
817
+ checkVersionEventHandler ( ) {
818
+ this . socket . emit ( 'version' , {
819
+ version : config . fullversion ,
820
+ minimumCompatibleVersion : config . minimumCompatibleVersion
821
+ } )
822
+ }
823
+
815
824
refreshEventHandler ( ) {
816
825
exports . emitRefresh ( this . socket )
817
826
}
@@ -998,14 +1007,6 @@ function connection (socket) {
998
1007
}
999
1008
socket . emit ( 'online users' , out )
1000
1009
} )
1001
-
1002
- // check version
1003
- socket . on ( 'version' , function ( ) {
1004
- socket . emit ( 'version' , {
1005
- version : config . fullversion ,
1006
- minimumCompatibleVersion : config . minimumCompatibleVersion
1007
- } )
1008
- } )
1009
1010
}
1010
1011
1011
1012
exports = module . exports = realtime
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ function makeMockSocket (headers, query) {
15
15
query : Object . assign ( { } , query )
16
16
} ,
17
17
on : sinon . fake ( ) ,
18
+ emit : sinon . fake ( ) ,
18
19
broadCastChannelCache : { } ,
19
20
broadcast : {
20
21
to : ( channel ) => {
@@ -459,7 +460,10 @@ describe('realtime', function () {
459
460
parseNoteTitle : ( data ) => ( data )
460
461
}
461
462
} )
462
- mock ( '../lib/config' , { } )
463
+ mock ( '../lib/config' , {
464
+ fullversion : '1.5.0' ,
465
+ minimumCompatibleVersion : '1.0.0'
466
+ } )
463
467
realtime = require ( '../lib/realtime' )
464
468
465
469
// get all socket event handler
@@ -609,5 +613,18 @@ describe('realtime', function () {
609
613
} )
610
614
} )
611
615
616
+ describe ( 'version' , function ( ) {
617
+ it ( 'should emit server version ' , ( ) => {
618
+ const versionFunc = eventFuncMap . get ( 'version' )
619
+ versionFunc ( )
620
+ assert ( clientSocket . emit . called )
621
+ assert ( clientSocket . emit . lastCall . args [ 0 ] , 'version' )
622
+ assert . deepStrictEqual ( clientSocket . emit . lastCall . args [ 1 ] , {
623
+ version : '1.5.0' ,
624
+ minimumCompatibleVersion : '1.0.0'
625
+ } )
626
+ } )
627
+ } )
628
+
612
629
} )
613
630
} )
You can’t perform that action at this time.
0 commit comments