(res: HttpResponse)
| 140 | } |
| 141 | |
| 142 | channels(res: HttpResponse) { |
| 143 | this.attachMiddleware(res, [ |
| 144 | this.corkMiddleware, |
| 145 | this.corsMiddleware, |
| 146 | this.appMiddleware, |
| 147 | this.authMiddleware, |
| 148 | this.readRateLimitingMiddleware, |
| 149 | ]).then(res => { |
| 150 | this.server.adapter.getChannelsWithSocketsCount(res.params.appId).then(channels => { |
| 151 | let response: { [channel: string]: ChannelResponse } = [...channels].reduce((channels, [channel, connections]) => { |
| 152 | if (connections === 0) { |
| 153 | return channels; |
| 154 | } |
| 155 | |
| 156 | // In case ?filter_by_prefix= is specified, the channel must start with that prefix. |
| 157 | if (res.query.filter_by_prefix && !channel.startsWith(res.query.filter_by_prefix)) { |
| 158 | return channels; |
| 159 | } |
| 160 | |
| 161 | channels[channel] = { |
| 162 | subscription_count: connections, |
| 163 | occupied: true, |
| 164 | }; |
| 165 | |
| 166 | return channels; |
| 167 | }, {}); |
| 168 | |
| 169 | return response; |
| 170 | }).catch(err => { |
| 171 | Log.error(err); |
| 172 | |
| 173 | return this.serverErrorResponse(res, 'A server error has occurred.'); |
| 174 | }).then(channels => { |
| 175 | let broadcastMessage = { channels }; |
| 176 | |
| 177 | this.server.metricsManager.markApiMessage(res.params.appId, {}, broadcastMessage); |
| 178 | |
| 179 | this.sendJson(res, broadcastMessage); |
| 180 | }); |
| 181 | }); |
| 182 | } |
| 183 | |
| 184 | channel(res: HttpResponse) { |
| 185 | this.attachMiddleware(res, [ |
no test coverage detected