/** * {} * @author yutent * @date 2023/01/17 17:32:51 */ import { WebSocketServer } from 'ws' function defer() { var o = {} o.promise = new Promise((resolve, reject) => { o.resolve = resolve o.reject = reject }) return o } export default function (server) { var _ = defer() var conn = new WebSocketServer({ server, path: '/ws-vue-live' }) conn.on('connection', client => { _.resolve(client) }) return _.promise }