You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123 lines
3.2 KiB

9 years ago
9 years ago
  1. // TODO(fancycode): Should load through AMD if possible.
  2. /* global OC, OCA */
  3. (function(OCA, OC, $) {
  4. 'use strict';
  5. OCA.SpreedMe = OCA.SpreedMe || {};
  6. var signaling;
  7. function initCalls(signaling_connection) {
  8. signaling = signaling_connection;
  9. var selectParticipants = $('#select-participants');
  10. selectParticipants.keyup(function () {
  11. selectParticipants.tooltip('hide');
  12. selectParticipants.removeClass('error');
  13. });
  14. OCA.SpreedMe.Calls.leaveAllCalls();
  15. }
  16. var roomsChannel = Backbone.Radio.channel('rooms');
  17. OCA.SpreedMe.Calls = {
  18. showCamera: function() {
  19. $('.videoView').removeClass('hidden');
  20. },
  21. _createCallSuccessHandle: function(ocsResponse) {
  22. var token = ocsResponse.ocs.data.token;
  23. OC.Util.History.pushState({
  24. token: token
  25. }, OC.generateUrl('/call/' + token));
  26. this.join(token);
  27. },
  28. createOneToOneVideoCall: function(recipientUserId) {
  29. console.log("Creating one-to-one video call", recipientUserId);
  30. $.ajax({
  31. url: OC.linkToOCS('apps/spreed/api/v1', 2) + 'room',
  32. type: 'POST',
  33. data: {
  34. invite: recipientUserId,
  35. roomType: 1
  36. },
  37. beforeSend: function (request) {
  38. request.setRequestHeader('Accept', 'application/json');
  39. },
  40. success: _.bind(this._createCallSuccessHandle, this)
  41. });
  42. },
  43. createGroupVideoCall: function(groupId) {
  44. console.log("Creating group video call", groupId);
  45. $.ajax({
  46. url: OC.linkToOCS('apps/spreed/api/v1', 2) + 'room',
  47. type: 'POST',
  48. data: {
  49. invite: groupId,
  50. roomType: 2
  51. },
  52. beforeSend: function (request) {
  53. request.setRequestHeader('Accept', 'application/json');
  54. },
  55. success: _.bind(this._createCallSuccessHandle, this)
  56. });
  57. },
  58. createPublicVideoCall: function() {
  59. console.log("Creating a new public room.");
  60. $.ajax({
  61. url: OC.linkToOCS('apps/spreed/api/v1', 2) + 'room',
  62. type: 'POST',
  63. data: {
  64. roomType: 3
  65. },
  66. beforeSend: function (request) {
  67. request.setRequestHeader('Accept', 'application/json');
  68. },
  69. success: _.bind(this._createCallSuccessHandle, this)
  70. });
  71. },
  72. join: function(token) {
  73. if (signaling.currentCallToken === token) {
  74. return;
  75. }
  76. $('#emptycontent').hide();
  77. $('.videoView').addClass('hidden');
  78. $('#app-content').addClass('icon-loading');
  79. OCA.SpreedMe.webrtc.leaveRoom();
  80. OCA.SpreedMe.webrtc.joinRoom(token);
  81. },
  82. leaveCurrentCall: function(deleter) {
  83. OCA.SpreedMe.webrtc.leaveRoom();
  84. OC.Util.History.pushState({}, OC.generateUrl('/apps/spreed'));
  85. $('#app-content').removeClass('incall');
  86. this.showRoomDeletedMessage(deleter);
  87. roomsChannel.trigger('leaveCurrentCall');
  88. },
  89. leaveAllCalls: function() {
  90. if (signaling) {
  91. // We currently only support a single active call.
  92. signaling.leaveCurrentCall();
  93. }
  94. },
  95. showRoomDeletedMessage: function(deleter) {
  96. if (deleter) {
  97. OCA.SpreedMe.app.setEmptyContentMessage(
  98. 'icon-video',
  99. t('spreed', 'Looking great today! :)'),
  100. t('spreed', 'Time to call your friends')
  101. );
  102. } else {
  103. OCA.SpreedMe.app.setEmptyContentMessage(
  104. 'icon-video-off',
  105. t('spreed', 'This call has ended')
  106. );
  107. }
  108. }
  109. };
  110. OCA.SpreedMe.initCalls = initCalls;
  111. })(OCA, OC, $);