UNPKG

bfx-api-node-core

Version:
36 lines (30 loc) 862 B
'use strict' const debug = require('debug')('bfx:api:ws:events:subscribed') const findSubscription = require('../find_subscription') /** * Adds the channel information to the internal channel map * * Emits: * * event:subscribed * * @param {Object} state * @param {Object} msg * @return {Object} nextState */ module.exports = (state = {}, msg = {}) => { const { channels, emit, pendingSubscriptions } = state const { chanId } = msg emit('event:subscribed', msg) debug('subscribed to channel %d: %j', chanId, msg) // Remove pending subscription const subscription = findSubscription(pendingSubscriptions, msg, true) const nextPendingSubs = pendingSubscriptions.filter(item => item !== subscription) return { ...state, pendingSubscriptions: nextPendingSubs, channels: { ...channels, [chanId]: msg } } }