'use strict'; const moment = require('moment') module.exports = async function factory (app, opts) { app.socket.on('connection', async (socket) => { console.info('WEB_SOCKET token:' + socket.handshake.query.token + ' 已连接:id ' + socket.id + ' 时间:' + moment(socket.handshake.time).format()); socket.on('disconnecting', async (reason) => { const connectSeconds = moment().diff(moment(socket.handshake.time), 'seconds') console.info('WEB_SOCKET token:' + socket.handshake.query.token + ' 已断开连接:' + reason + ' 连接时长:' + connectSeconds + 's'); }) }) }