constKoa=require('koa');constroute=require('koa-route');constwebsockify=require('koa-websocket');constapp=websockify(newKoa());app.ws.use(function(ctx,next){ctx.websocket.send('connection succeeded!');returnnext(ctx);});app.ws.use(route.all('/test',function(ctx){// ctx.websocket.send('Hello World');ctx.websocket.on('message',function(message){// do something with the message from clientif(message!=='ping'){letdata=JSON.stringify({id:Math.ceil(Math.random()*1000),time:newDate().getTime(),res:`${message}`,});ctx.websocket.send(data);}console.log(message);});}));app.listen(3380,()=>{console.log('websocket server is listen in: '+3380);});