O'Reilly logo

Isomorphic Go by Kamesh Balasubramanian

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Setting up event listeners for the WebSocket object

Now that we've set up the event listeners for the user interactions, we must set up event listeners on the WebSocket object, ws. We first add an event listener on the message event:

  ws.AddEventListener("message", false, func(ev *js.Object) {    go HandleOnMessage(env, ev)  })

The message event listener will be triggered when a new message comes across the WebSocket connection. This is indicative of the agent sending a message back to the user. In this situation we call the HandleOnMessage, function, passing in the env object and the event object, ev, to the function.

The other event we have to listen for from the WebSocket object is the close event. This event can be triggered from a normal ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required