12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- const { Server, WebSocketHandler } = require('../dist');
- class WSHandler0 extends WebSocketHandler {
- constructor() {
- super(...arguments);
- this.onConnect = (ws) => {
- console.log('ws0 connection:', ws);
- }
- this.onMessage = (message) => {
- console.log('ws0 message:', message.toString());
- }
- this.onError = () => {
- console.log('ws0 error');
- }
- this.onClose = (code, reason) => {
- console.log('ws0 closed', code, reason.toString());
- }
- }
- }
- class WSHandler1 extends WebSocketHandler {
- constructor() {
- super(...arguments);
- this.onConnect = (ws) => {
- console.log('ws1 connection:', ws);
- }
- this.onMessage = (message) => {
- console.log('ws1 message:', message.toString());
- }
- this.onError = () => {
- console.log('ws1 error');
- }
- this.onClose = (code, reason) => {
- console.log('ws1 closed', code, reason.toString());
- }
- }
- }
- new Server({ port: 3001, wsHandlers: { '/ws0': new WSHandler0(), '/ws1': new WSHandler1() } }).init().then((server) => {
- server.start();
- });
|