@@ -12,6 +12,7 @@ import {
12
12
MACRO_EDITS ,
13
13
UPLOADED
14
14
} from '../constants/statusCodes.js'
15
+ import * as AccessToken from '../../common/api/AccessToken.js'
15
16
16
17
// Extract completion percentage
17
18
export const parseProgress = string => {
@@ -34,21 +35,28 @@ export default function listenForProgress() {
34
35
dispatch ( receiveError ( json ) )
35
36
throw new Error ( json && `${ json . status } : ${ json . statusText } ` )
36
37
}
38
+ console . log ( '- Getting latest submission JSON' )
37
39
return dispatch ( receiveSubmission ( json ) )
38
40
} )
39
41
} )
40
42
. then ( ( json ) => {
41
- if ( ! json ) return
43
+ if ( ! json ) {
44
+ console . warn ( '-- No submission JSON found, skipping WS connection' )
45
+
46
+ return
47
+ }
42
48
43
49
const { status, id } = json
44
50
const { lei, period, sequenceNumber } = id
45
51
const { year, quarter } = period
46
52
const { code } = status
47
53
48
54
if ( code >= UPLOADED ) {
55
+ console . log ( '- Opening websocket to listen for progress...' )
56
+
49
57
// Open a websocket and listen for updates
50
58
const wsBaseUrl = process . env . REACT_APP_ENVIRONMENT === 'CI'
51
- ? `${ window . location . hostname } :8080`
59
+ ? `${ window . location . hostname } :8080` // `IP-ADDRESS:8080`
52
60
: `${ window . location . host } /v2/filing`
53
61
54
62
const socketType = window . location . protocol == 'https:' ? 'wss' : 'ws'
@@ -57,11 +65,27 @@ export default function listenForProgress() {
57
65
? `/institutions/${ lei } /filings/${ year } /quarter/${ quarter } /submissions/${ sequenceNumber } /progress`
58
66
: `/institutions/${ lei } /filings/${ year } /submissions/${ sequenceNumber } /progress`
59
67
60
- let socket = new WebSocket ( `${ socketType } ://${ wsBaseUrl } ${ wsProgressUrl } ` )
68
+ let socket
69
+
70
+ try {
71
+ console . log ( `-- Attempting connection to ${ socketType } ://${ wsBaseUrl } ${ wsProgressUrl } ` )
72
+ socket = new WebSocket ( `${ socketType } ://${ wsBaseUrl } ${ wsProgressUrl } ` )
73
+ } catch ( e ) {
74
+ console . log ( `--- Connection to ${ socketType } ://${ wsBaseUrl } ${ wsProgressUrl } failed!` )
75
+ error ( e )
76
+ console . log ( '---' )
77
+ }
61
78
62
79
socket . onopen = ( event ) => {
63
- console . log ( '>>> Socket open! Listening for Progress...' )
80
+ console . log ( '-- Socket open! Sending Bearer token and then listening for Progress...' )
64
81
dispatch ( requestProcessingProgress ( ) )
82
+ socket . send (
83
+ JSON . stringify ( {
84
+ headers : {
85
+ Authorization : 'Bearer ' + AccessToken . get ( ) ,
86
+ } ,
87
+ } )
88
+ )
65
89
}
66
90
67
91
// Listen for messages
@@ -126,13 +150,13 @@ export default function listenForProgress() {
126
150
else {
127
151
// e.g. server process killed or network down
128
152
// event.code is usually 1006 in this case
129
- console . log ( '[close ] Connection died' )
153
+ console . log ( '[socket onclose ] Connection died' , event )
130
154
}
131
155
}
132
156
133
157
// TODO: What to do on websocket error?
134
158
socket . onerror = function ( error ) {
135
- console . log ( `[error ] ${ error . message } ` )
159
+ console . log ( `[socket onerror ] ${ error . message } ` , error )
136
160
}
137
161
}
138
162
else if (
0 commit comments