Skip to content

Commit

Permalink
rename fn
Browse files Browse the repository at this point in the history
  • Loading branch information
mifi committed Oct 13, 2023
1 parent 3fa992b commit 0cc6bc5
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions packages/@uppy/companion/src/server/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,25 @@ module.exports = (server) => {
*
* @param {{action: string, payload: object}} data
*/
function sendProgress (data) {
function send (data) {
ws.send(jsonStringify(data), (err) => {
if (err) logger.error(err, 'socket.progress.error', shortenToken(token))
if (err) logger.error(err, 'socket.redis.error', shortenToken(token))
})
}

// if the redisClient is available, then we attempt to check the storage
// if we have any already stored progress data on the upload.
// if we have any already stored state on the upload.
if (redisClient) {
redisClient.get(`${STORAGE_PREFIX}:${token}`).then((data) => {
if (data) {
const dataObj = JSON.parse(data.toString())
if (dataObj.action) sendProgress(dataObj)
if (dataObj.action) send(dataObj)
}
}).catch((err) => logger.error(err, 'socket.redis.error', shortenToken(token)))
}

emitter().emit(`connection:${token}`)
emitter().on(token, sendProgress)
emitter().on(token, send)

ws.on('message', (jsonData) => {
const data = JSON.parse(jsonData.toString())
Expand All @@ -57,7 +57,7 @@ module.exports = (server) => {
})

ws.on('close', () => {
emitter().removeListener(token, sendProgress)
emitter().removeListener(token, send)
})
})
}

0 comments on commit 0cc6bc5

Please sign in to comment.