video.tpl 6.9 KB

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