call.js 829 B

123456789101112131415161718192021222324252627282930313233
  1. $(document).ready(function(){
  2. Twilio.Device.setup("<?php echo $token; ?>");
  3. $("#call").click(function() {
  4. Twilio.Device.connect();
  5. });
  6. $("#hangup").click(function() {
  7. Twilio.Device.disconnectAll();
  8. });
  9. Twilio.Device.ready(function (device) {
  10. $('#status').text('Ready to start call');
  11. });
  12. Twilio.Device.offline(function (device) {
  13. $('#status').text('Offline');
  14. });
  15. Twilio.Device.error(function (error) {
  16. $('#status').text(error);
  17. });
  18. Twilio.Device.connect(function (conn) {
  19. $('#status').text("Successfully established call");
  20. toggleCallStatus();
  21. });
  22. Twilio.Device.disconnect(function (conn) {
  23. $('#status').text("Call ended");
  24. toggleCallStatus();
  25. });
  26. Twilio.Device.incoming(function (conn) {
  27. conn.accept();
  28. });
  29. function toggleCallStatus(){
  30. $('#call').toggle();
  31. $('#hangup').toggle();
  32. }
  33. });