Congrats, you made your first audio connection from your browser to Twilio! You should have heard a welcome message when you made the call.
twilio-rubyhelper library. If you don't have these yet, please see our post on setting up your environment.
However, as you may have noticed, there was no way to close the connection from your client. For now, you can simply refresh the page, but shouldn't there be a button for that? So, let's add one to the page we created to let you close the audio connection.
The highlighted lines are what we're adding:
And that’s it! Go ahead and make another call. You can now press the hangup button at any time and your connection will close.
Also, the above example added code to register two more callback
handlers. Whenever something interesting happens within Twilio Client,
the registered callbacks will be triggered. The callback registered
Twilio.Device.connect is triggered when the
connection is successfully established, and the callback registered to
Twilio.Device.disconnect is triggered when it is closed.
In the above example, the callbacks simply change the log text, but in your
application they could do anything.
Now that you can hang up calls, let's learn how to receive incoming calls in your browser!