uNetworking / uWebSockets.js

μWebSockets for Node.js back-ends :metal:
Apache License 2.0
7.86k stars 569 forks source link

Subscribing to a topic occurs multiple times #749

Closed youfeed closed 2 years ago

youfeed commented 2 years ago

wss subscribe

message:(ws, message, isBinary)=>{
   let msg = new TextDecoder('utf-8').decode(message)
  if(msg =='subscribe'){
    ws.subscribe('uuid')
  }
})

trigger notification

.get('/*',(res, req)=>{
  app.publish('uuid', 'IsExample'+new Date())
  res.writeStatus('200 OK').writeHeader('IsExample', 'Yes').end('Hello there!');
})

result

<!--StartFragment-->
IsExampleThu Jun 02 2022 13:24:11 GMT+0800 (China Standard Time)
IsExampleThu Jun 02 2022 13:24:11 GMT+0800 (China Standard Time)
<!--EndFragment-->

I pushed it once, but the subscriber will get the second message

Did I do something wrong

youfeed commented 2 years ago

I found the reason, I typed in the browser /address, the browser will also send a /favicon.ico The request causes a secondary trigger