video.tpl 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <div id="chat-video-panel">
  2. <div class="alert alert-warning alert-dismissible fade in">
  3. <button type="button" class="close" data-dismiss="alert" aria-label="{{ 'Close'|get_lang }}">
  4. <span aria-hidden="true">&times;</span>
  5. </button>
  6. <h4>{{ 'Warning'|get_lang }}</h4>
  7. <p>
  8. <em class="fa fa-warning"></em> {{ 'AvoidChangingPageAsThisWillCutYourCurrentVideoChatSession'|get_lang }}
  9. </p>
  10. </div>
  11. <div class="row">
  12. <div class="col-md-8 col-sm-7">
  13. <div class="thumbnail video-chat-user">
  14. <div id="chat-remote-video"></div>
  15. <div class="caption">
  16. <p class="text-muted text-center">{{ "ChatWithXUser"|get_lang|format(chat_user.complete_name) }}</p>
  17. </div>
  18. </div>
  19. </div>
  20. <div class="col-md-4 col-sm-5">
  21. <div class="thumbnail">
  22. <div id="chat-local-video"></div>
  23. <div class="caption">
  24. <p class="text-muted text-center">{{ user_local.complete_name }}</p>
  25. </div>
  26. </div>
  27. <div id="connection-status"></div>
  28. <div class="chat-friends">
  29. <div class="panel-group" id="blocklistFriends" role="tablist" aria-multiselectable="true">
  30. <div class="panel panel-default">
  31. <div class="panel-heading" role="tab" id="headingOne">
  32. <h4 class="panel-title">
  33. <a role="button" data-toggle="collapse" data-parent="#blocklistFriends" href="#listFriends" aria-expanded="true" aria-controls="listFriends">
  34. {{ "SocialFriend" | get_lang }}
  35. </a>
  36. </h4>
  37. </div>
  38. <div id="listFriends" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingOne">
  39. {{ block_friends }}
  40. </div>
  41. </div>
  42. </div>
  43. </div>
  44. </div>
  45. </div>
  46. </div>
  47. <script>
  48. (function () {
  49. var VideoChat = {
  50. init: function () {
  51. var isCompatible = !!Modernizr.prefixed('RTCPeerConnection', window);
  52. var notifyNotSupport = function () {
  53. $.get('{{ _p.web_ajax }}chat.ajax.php', {
  54. action: 'notify_not_support',
  55. to:{{ chat_user.id }}
  56. });
  57. };
  58. var startVideoChat = function () {
  59. var webRTC = new SimpleWebRTC({
  60. localVideoEl: 'chat-local-video',
  61. remoteVideosEl: '',
  62. autoRequestMedia: true
  63. });
  64. webRTC.on('readyToCall', function () {
  65. webRTC.joinRoom('{{ room_name }}');
  66. });
  67. webRTC.on('videoAdded', function (video, peer) {
  68. $(video).addClass('skip');
  69. $('#chat-remote-video').html(video);
  70. if (peer && peer.pc) {
  71. peer.pc.on('iceConnectionStateChange', function () {
  72. var alertDiv = $('<div>')
  73. .addClass('alert');
  74. switch (peer.pc.iceConnectionState) {
  75. case 'checking':
  76. alertDiv
  77. .addClass('alert-info')
  78. .html('<em class="fa fa-spinner fa-spin"></em> ' + "{{ 'ConnectingToPeer'|get_lang }}");
  79. break;
  80. case 'connected':
  81. //no break
  82. case 'completed':
  83. alertDiv
  84. .addClass('alert-success')
  85. .html('<em class="fa fa-commenting"></em> ' + "{{ 'ConnectionEstablished'|get_lang }}");
  86. break;
  87. case 'disconnected':
  88. alertDiv
  89. .addClass('alert-info')
  90. .html('<em class="fa fa-frown-o"></em> ' + "{{ 'Disconnected'|get_lang }}");
  91. break;
  92. case 'failed':
  93. alertDiv
  94. .addClass('alert-danger')
  95. .html('<em class="fa fa-times"></em> ' + "{{ 'ConnectionFailed'|get_lang }}");
  96. break;
  97. case 'closed':
  98. alertDiv
  99. .addClass('alert-danger')
  100. .html('<em class="fa fa-close"></em> ' + "{{ 'ConnectionClosed'|get_lang }}");
  101. break;
  102. }
  103. $('#connection-status').html(alertDiv);
  104. });
  105. }
  106. });
  107. webRTC.on('videoRemoved', function (video, peer) {
  108. video.src = '';
  109. });
  110. webRTC.on('iceFailed', function (peer) {
  111. var alertDiv = $('<div>')
  112. .addClass('alert-danger')
  113. .html('<em class="fa fa-close"></em> ' + "{{ 'LocalConnectionFailed'|get_lang }}");
  114. $('#connection-status').html(alertDiv);
  115. });
  116. webRTC.on('connectivityError', function (peer) {
  117. var alertDiv = $('<div>')
  118. .addClass('alert-danger')
  119. .html('<em class="fa fa-close"></em> ' + "{{ 'RemoteConnectionFailed'|get_lang }}");
  120. $('#connection-status').html(alertDiv);
  121. });
  122. };
  123. if (!isCompatible) {
  124. notifyNotSupport();
  125. $('#chat-video-panel').remove();
  126. return;
  127. }
  128. $('#messages').remove();
  129. startVideoChat();
  130. window.onbeforeunload = function () {
  131. return "{{ 'AvoidChangingPageAsThisWillCutYourCurrentVideoChatSession'|get_lang }}";
  132. };
  133. }
  134. };
  135. $(document).on('ready', function () {
  136. VideoChat.init();
  137. });
  138. })();
  139. </script>