Re-add "message" as event type
This commit is contained in:
		
							parent
							
								
									ad17be1683
								
							
						
					
					
						commit
						4677e724ee
					
				
					 2 changed files with 3 additions and 2 deletions
				
			
		|  | @ -6,6 +6,7 @@ import "time" | ||||||
| const ( | const ( | ||||||
| 	openEvent      = "open" | 	openEvent      = "open" | ||||||
| 	keepaliveEvent = "keepalive" | 	keepaliveEvent = "keepalive" | ||||||
|  | 	messageEvent = "message" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| // message represents a message published to a topic | // message represents a message published to a topic | ||||||
|  | @ -39,5 +40,5 @@ func newKeepaliveMessage() *message { | ||||||
| 
 | 
 | ||||||
| // newDefaultMessage is a convenience method to create a notification message | // newDefaultMessage is a convenience method to create a notification message | ||||||
| func newDefaultMessage(msg string) *message { | func newDefaultMessage(msg string) *message { | ||||||
| 	return newMessage("", msg) | 	return newMessage(messageEvent, msg) | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -219,7 +219,7 @@ func (s *Server) handleSubscribeSSE(w http.ResponseWriter, r *http.Request) erro | ||||||
| 		if err := json.NewEncoder(&buf).Encode(&msg); err != nil { | 		if err := json.NewEncoder(&buf).Encode(&msg); err != nil { | ||||||
| 			return "", err | 			return "", err | ||||||
| 		} | 		} | ||||||
| 		if msg.Event != "" { | 		if msg.Event != messageEvent { | ||||||
| 			return fmt.Sprintf("event: %s\ndata: %s\n", msg.Event, buf.String()), nil // Browser's .onmessage() does not fire on this! | 			return fmt.Sprintf("event: %s\ndata: %s\n", msg.Event, buf.String()), nil // Browser's .onmessage() does not fire on this! | ||||||
| 		} | 		} | ||||||
| 		return fmt.Sprintf("data: %s\n", buf.String()), nil | 		return fmt.Sprintf("data: %s\n", buf.String()), nil | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue