fite/lib/ws.js

26 lines
471 B
JavaScript
Raw Normal View History

2023-01-17 18:43:05 +08:00
/**
* {}
* @author yutent<yutent.io@gmail.com>
* @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
}