In order for your client device to be allowed to connect to Twilio so it can make an outgoing call, you need to make sure that the Capability Token you've provided allows for it. To do this, you will need a TwiML App SID and have your server application provide this SID to the outgoing capability of the token generator.
<?xml version="1.0" encoding="UTF-8"?> <Response> <Say>Thanks for calling!</Say> </Response>
See our server application guide for more details on how to set this up.
Once you've created a Device, you can call it's connect() method to connect to Twilio. Twilio will make a request to the voice URL configured on your TwiML App. Since this return the <Say> verb that simply thanks the caller, you should hear the thank you message in your browser or on your device.
Just getting a message played to you in your browser isn't all that interesting. What we really want to do is have the client make a call to a real live phone number. In order to do this, our client needs to pass a parameter to our TwiML App. The parameter can be anything you like, but we'll create a parameter named "To" to indicate the number we want to make a call to.
Once you're on a call, you will probably want a way to hang up. This can be accomplished (albeit with less satisfaction than slamming a real phone handset into the receiver) using the disconnect() method.