meet.blade.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. @extends('layouts.meeting')
  2. @section('content')
  3. <div id="meetComponent">
  4. <h5 class="bg-dark font-weight-bold text-white m-0 py-3 px-4 d-flex">
  5. <span>Meeting</span>
  6. <span class="ml-auto" v-if="!started">
  7. Connecting...
  8. </span>
  9. <span class="ml-auto" v-if="started">
  10. <i class="fa fa-clock mr-1 text-light"></i>
  11. @{{ timeDisplay() }}
  12. </span>
  13. </h5>
  14. <div class="mt-4">
  15. @if($guest)
  16. <div class="py-2 text-center" v-if="!pro">
  17. <h6 class="text--black font-weight-bold">Please wait. Your doctor will be with you shortly...</h6>
  18. </div>
  19. @endif
  20. <div class="main-view mx-auto">
  21. <div id="self-view" class="full-view"></div>
  22. <div id="remote-view" class="thumb-view"></div>
  23. </div>
  24. </div>
  25. </div>
  26. <script>
  27. new Vue({
  28. el: '#meetComponent',
  29. delimiters: ['@{{', '}}'],
  30. data: {
  31. time: 0,
  32. startTime: 0,
  33. started: false,
  34. client: false,
  35. pro: false,
  36. selfName: '',
  37. selfToken: '',
  38. @if($guest)
  39. clientUid: '',
  40. checkInToken: '',
  41. @endif
  42. otSessionId: '',
  43. },
  44. methods: {
  45. getInitials: function(_name) {
  46. var parts = _name.split(/\s+/g);
  47. parts = parts.map(_part => _part[0]);
  48. return parts.join('');
  49. },
  50. timeDisplay: function() {
  51. var seconds = this.time / 1000,
  52. minutes = parseInt(seconds / 60, 10);
  53. seconds = parseInt(seconds % 60, 10);
  54. return minutes + " min, " + seconds + " sec";
  55. },
  56. connectToFirstPro: function() {
  57. console.log('Connecting to first pro ...');
  58. this.pros = [];
  59. this.addPro();
  60. $.post('/api/meeting/request-dial-pro', {
  61. meetingUid: this.meetingID,
  62. }, function(_data) {
  63. console.log('Response to /api/meeting/request-dial-pro');
  64. console.log(_data);
  65. }, 'json');
  66. },
  67. onProJoined: function(_data) {
  68. // TODO:
  69. },
  70. onProLeft: function(_id) {
  71. // TODO:
  72. },
  73. leaveCall: function() {
  74. // TODO:
  75. },
  76. // OT methods
  77. initOpenTok: function() {
  78. /* fake video feed (temp) */
  79. const randomColour = () => {
  80. return Math.round(Math.random() * 255);
  81. };
  82. const canvas = document.createElement('canvas');
  83. canvas.width = 640;
  84. canvas.height = 480;
  85. const ctx = canvas.getContext('2d');
  86. const x = randomColour();
  87. ctx.clearRect(0, 0, canvas.width, canvas.height);
  88. ctx.font = "20px Georgia";
  89. ctx.fillStyle = `rgb(220, 220, 220)`;
  90. var userType = '<?= $guest? "Client" : "Pro" ?>';
  91. ctx.fillText("Video feed from the " + userType, 20, 100);
  92. var self = this;
  93. var apiKey = '46678902';
  94. var sessionId = this.otSessionId;
  95. var token = this.selfToken;
  96. var session = OT.initSession(apiKey, sessionId);
  97. // TODO: Subscribe to remote stream (pro)
  98. session.on('streamCreated', function streamCreated(event) {
  99. console.log(event);
  100. var subscriberOptions = {
  101. insertMode: 'append',
  102. width: '100%',
  103. height: '100%'
  104. };
  105. session.subscribe(event.stream, 'subscriber', subscriberOptions, handleError);
  106. });
  107. session.on('sessionDisconnected', function sessionDisconnected(event) {
  108. console.log('You were disconnected from the session.', event.reason);
  109. });
  110. // initialize the publisher
  111. var publisherOptions = {
  112. videoSource: canvas.captureStream(1).getVideoTracks()[0],
  113. insertMode: 'append',
  114. width: '100%',
  115. height: '100%',
  116. };
  117. var publisher = OT.initPublisher('self-view', publisherOptions, self.handleOpenTokError);
  118. // Connect to the session
  119. session.connect(token, function callback(error) {
  120. if (error) {
  121. self.handleOpenTokError(error);
  122. } else {
  123. // If the connection is successful, publish the publisher to the session
  124. session.publish(publisher, self.handleOpenTokError);
  125. }
  126. });
  127. },
  128. handleOpenTokError: function(e) {
  129. },
  130. getClientCheckinToken: function(_done) {
  131. var self = this;
  132. $.get('/get-client-checkin-token/' + this.clientUid, function(_data) {
  133. console.log(_data);
  134. self.checkInToken = _data.data;
  135. _done();
  136. }, 'json');
  137. },
  138. getOpenTokSessionId: function(_done) {
  139. var self = this;
  140. $.ajax({
  141. type: 'post',
  142. url: '/api/clientVideoVisit/startVideoVisitAsStranger',
  143. headers: {
  144. 'sessionKey': localStorage.sessionKey
  145. },
  146. data: {checkInToken: this.checkInToken},
  147. dataType: 'json'
  148. })
  149. .done(function (_data) {
  150. console.log(_data);
  151. if(_data.success) {
  152. self.otSessionId = _data.data;
  153. _done();
  154. }
  155. else {
  156. alert(_data.message);
  157. }
  158. })
  159. .fail(function (_data) {
  160. console.log(_data);
  161. alert(_data.message);
  162. });
  163. }
  164. },
  165. mounted: function() {
  166. var self = this;
  167. @if($guest)
  168. this.clientUid = localStorage.clientUid;
  169. this.getClientCheckinToken(function() { // get client check-in token
  170. self.getOpenTokSessionId(function() { // get opentok session id
  171. var name = [];
  172. if (localStorage.clientFirstName) name.push(localStorage.clientFirstName);
  173. if (localStorage.clientLastName) name.push(localStorage.clientLastName);
  174. this.selfName = name.join(' ');
  175. $.post('/api/openTok/getClientToken', {
  176. opentokSessionId: self.otSessionId,
  177. name: name.join(' ')
  178. }, function (_data) {
  179. self.selfToken = _data.data;
  180. self.initOpenTok();
  181. });
  182. });
  183. });
  184. @endif
  185. }
  186. });
  187. </script>
  188. @endsection