wss-env
install
npm i wss-env
options
usage
import { join } from 'path';
import { createServer } from 'http';
import { Server } from 'wssio';
import { namespaceAutoload } from 'wss-autoload';
import { namespacePlugin } from 'wss-plugin';
import { namespaceEnv } from 'wss-env';
const server = createServer();
const wssio = new Server({
server,
});
const nsp = wssio.of('/test');
// 注册关闭钩子函数、以达到关闭服务
nsp.register(namespacePlugin((namespace, _opts, done) => {
namespace.addHook('onClose', () => {
wssio.close();
server.close();
});
done();
}, {
name: 'onClose',
}));
nsp.register(namespaceEnv, {
schema: {
type: 'object',
required: ['PORT'],
properties: {
PORT: {
type: 'integer',
default: 888
}
}
}
}).ready((err)=>{
nsp.$log.info('wss ready.....');
nsp.$log.info(b.config.PORT==888);
server.listen(3000, '0.0.0.0');
})