Skip to content

Commit

Permalink
WIP - auth over websocket
Browse files Browse the repository at this point in the history
  • Loading branch information
meissadia committed Sep 1, 2022
1 parent c5024d0 commit 341f534
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/filing/actions/listenForProgress.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
MACRO_EDITS,
UPLOADED
} from '../constants/statusCodes.js'
import * as AccessToken from '../../common/api/AccessToken.js'

// Extract completion percentage
export const parseProgress = string => {
Expand All @@ -34,18 +35,25 @@ export default function listenForProgress() {
dispatch(receiveError(json))
throw new Error(json && `${json.status}: ${json.statusText}`)
}
console.log('- Getting latest submission JSON')
return dispatch(receiveSubmission(json))
})
})
.then((json) => {
if (!json) return
if (!json) {
console.warn('-- No submission JSON found, skipping WS connection')

return
}

const { status, id } = json
const { lei, period, sequenceNumber } = id
const { year, quarter } = period
const { code } = status

if (code >= UPLOADED) {
console.log('- Opening websocket to listen for progress...')

// Open a websocket and listen for updates
const wsBaseUrl = process.env.REACT_APP_ENVIRONMENT === 'CI'
? `${window.location.hostname}:8080`
Expand All @@ -58,10 +66,18 @@ export default function listenForProgress() {
: `/institutions/${lei}/filings/${year}/submissions/${sequenceNumber}/progress`

let socket = new WebSocket(`${socketType}://${wsBaseUrl}${wsProgressUrl}`)
// let socket = new WebSocket(`${socketType}://${wsBaseUrl}${wsProgressUrl}?accessToken=${AccessToken.get()}`)

socket.onopen = (event) => {
console.log('>>> Socket open! Listening for Progress...')
console.log('-- Socket open! Sending Bearer token and then listening for Progress...')
dispatch(requestProcessingProgress())
socket.send(
JSON.stringify({
headers: {
Authorization: 'Bearer ' + AccessToken.get(),
},
})
)
}

// Listen for messages
Expand Down

0 comments on commit 341f534

Please sign in to comment.