ニジカ投稿局 https://tv.nizika.tv
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536
  1. const WebSocketServer = require('ws').WebSocketServer
  2. async function register ({
  3. registerWebSocketRoute
  4. }) {
  5. const wss = new WebSocketServer({ noServer: true })
  6. wss.on('connection', function connection(ws) {
  7. ws.on('message', function message(data) {
  8. if (data.toString() === 'ping') {
  9. ws.send('pong')
  10. }
  11. })
  12. })
  13. registerWebSocketRoute({
  14. route: '/toto',
  15. handler: (request, socket, head) => {
  16. wss.handleUpgrade(request, socket, head, ws => {
  17. wss.emit('connection', ws, request)
  18. })
  19. }
  20. })
  21. }
  22. async function unregister () {
  23. return
  24. }
  25. module.exports = {
  26. register,
  27. unregister
  28. }
  29. // ###########################################################################