26 lines
471 B
JavaScript
26 lines
471 B
JavaScript
/**
|
|
* {}
|
|
* @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
|
|
}
|