@@ -80,6 +80,12 @@ export default class SocketWorker {
80
80
this . boot ( ) ;
81
81
}
82
82
83
+ @action
84
+ private connected ( ) {
85
+ this . connectionStatus = 'connected' ;
86
+ this . hasConnectedOnce = true ;
87
+ }
88
+
83
89
@action
84
90
private connectWebSocket ( ) {
85
91
if ( ! this . active || this . endpoint == null || this . ws != null ) {
@@ -97,11 +103,6 @@ export default class SocketWorker {
97
103
98
104
const token = tokenEl . getAttribute ( 'content' ) ;
99
105
this . ws = new WebSocket ( `${ this . endpoint } ?csrf=${ token } ` ) ;
100
- this . ws . addEventListener ( 'open' , action ( ( ) => {
101
- this . retryDelay . reset ( ) ;
102
- this . connectionStatus = 'connected' ;
103
- this . hasConnectedOnce = true ;
104
- } ) ) ;
105
106
this . ws . addEventListener ( 'close' , this . reconnectWebSocket ) ;
106
107
this . ws . addEventListener ( 'message' , this . handleNewEvent ) ;
107
108
}
@@ -127,7 +128,9 @@ export default class SocketWorker {
127
128
const eventData = this . parseMessageEvent ( event ) ;
128
129
if ( eventData == null ) return ;
129
130
130
- if ( isNotificationEventLogoutJson ( eventData ) ) {
131
+ if ( eventData . event === 'connection.ready' ) {
132
+ this . connected ( ) ;
133
+ } else if ( isNotificationEventLogoutJson ( eventData ) ) {
131
134
this . destroy ( ) ;
132
135
core . userLoginObserver . logout ( ) ;
133
136
} else if ( isNotificationEventVerifiedJson ( eventData ) ) {
0 commit comments