gotron icon indicating copy to clipboard operation
gotron copied to clipboard

ws.onmessage not called

Open DatStorm opened this issue 6 years ago • 1 comments

Hey

Been testing the example and the function

ws.onmessage = function(e) { console.log("Message received: " + e.data);
}

will not be called in my javascript file. I can not see the mistake?

DatStorm avatar Feb 27 '19 20:02 DatStorm

Solved! Problem is if you have code like this the send event will not happen quickly enough. For the frontend to receive. So fix was to add a callback function :D window.Send(&event)

window.On(&gotron.Event{Event: "event-name"}, func(bin []byte) { var event2 CustomEvent json.Unmarshal(bin, &event2) fmt.Println("EVENT Name:", event2.Event.Event) fmt.Println("EVENT AtrNameInFrontend:", event2.AtrNameInFrontend) callEvent(window) })

DatStorm avatar Feb 27 '19 20:02 DatStorm