12345678910111213141516171819202122232425262728 |
- 'use strict'
- import { formatLog } from '../functions'
- import { wsLogger } from '../../config'
- /**
- * @typedef {Function} MessageHandler
- * @param {string} data a message received from a client
- */
- /**
- * Treat received message from a WebSocket client
- * @param {object} ws a WebSocket connected client
- * @returns {MessageHandler} the message handler
- */
- const messageHandler = ws => async data => {
- let json
- try {
- json = JSON.parse(data)
- }
- catch (err) {
- throw new Error('Invalid JSON data.')
- }
- wsLogger.info(formatLog(json, 'message'))
- ws.send('ok')
- }
- export default messageHandler
|