chore: call processInBuffer for all msg handling

This commit is contained in:
Adhiraj Singh
2022-10-18 16:57:40 +05:30
parent 2b854b37e4
commit 9c28dde04d

View File

@@ -617,17 +617,16 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
}
}
const flushBufferIfLastOfflineNode = (
/// processes a node with the given function
/// and adds the task to the existing buffer if we're buffering events
const processNodeWithBuffer = (
node: BinaryNode,
identifier: string,
exec: (node: BinaryNode) => Promise<any>
) => {
const task = exec(node)
.catch(err => onUnexpectedError(err, identifier))
const offline = node.attrs.offline
if(offline) {
ev.processInBuffer(task)
}
ev.processInBuffer(task)
}
// called when all offline notifs are handled
@@ -643,19 +642,19 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
// recv a message
ws.on('CB:message', (node: BinaryNode) => {
flushBufferIfLastOfflineNode(node, 'processing message', handleMessage)
processNodeWithBuffer(node, 'processing message', handleMessage)
})
ws.on('CB:call', async(node: BinaryNode) => {
flushBufferIfLastOfflineNode(node, 'handling call', handleCall)
processNodeWithBuffer(node, 'handling call', handleCall)
})
ws.on('CB:receipt', node => {
flushBufferIfLastOfflineNode(node, 'handling receipt', handleReceipt)
processNodeWithBuffer(node, 'handling receipt', handleReceipt)
})
ws.on('CB:notification', async(node: BinaryNode) => {
flushBufferIfLastOfflineNode(node, 'handling notification', handleNotification)
processNodeWithBuffer(node, 'handling notification', handleNotification)
})
ws.on('CB:ack,class:message', (node: BinaryNode) => {