meeting.blade.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. @extends('layouts.meeting')
  2. @section('content')
  3. <div id="meetingComponent">
  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="d-flex align-items-stretch mt-4 justify-content-center flex-nowrap">
  15. <div class="tp-bar">
  16. <div v-for="(guest, index) of guests"
  17. class="tp-item mb-4"
  18. :class="activeParticipant && activeType === 'guest' && activeParticipant.id === guest.id ? 'active' : ''"
  19. v-on:click="setActiveView('guest', guest)">
  20. <div class="avatar text-white" :style="'background: ' + guest.color">@{{ getInitials(guest.name) }}</div>
  21. <p class="font-weight-bold text-center mt-1 mb-0">@{{ guest.name }}</p>
  22. </div>
  23. <div v-if="guest" class="tp-item mb-4">
  24. <img src="/images/person/guest.png" alt="" class="invite-image">
  25. <p class="font-weight-bold text-center mt-1">Invite Guest</p>
  26. </div>
  27. </div>
  28. <div class="main-view" style="width: 800px; min-height: 600px;">
  29. <div class="p-4 w-100 h-100 d-flex align-items-stretch justify-content-end flex-column">
  30. <p class="font-weight-bold text-center text-white mt-2">Feed from @{{ activeParticipant.name }}</p>
  31. <button class="btn btn-sm btn-danger px-4 align-self-end mx-auto font-weight-bold"
  32. v-on:click="leaveCall()">Leave</button>
  33. </div>
  34. </div>
  35. <div class="tp-bar">
  36. <div v-for="(pro, index) of pros"
  37. class="tp-item mb-4"
  38. :class="activeParticipant && activeType === 'pro' && activeParticipant.id === pro.id ? 'active' : ''"
  39. v-on:click="setActiveView('pro', pro)">
  40. <div v-if="pro.status === 'active'">
  41. <div class="avatar text-white" :style="'background: ' + pro.color">@{{ getInitials(pro.name) }}</div>
  42. <p class="font-weight-bold text-center mt-1 mb-0">@{{ pro.name }}</p>
  43. <p v-if="pro.type" class="font-weight-normal text-center">@{{ pro.type }}</p>
  44. </div>
  45. <div v-if="pro.status === 'connecting'">
  46. <img src="/images/person/connecting.jpg" alt="" class="w-100">
  47. <p class="font-weight-normal text-center mt-1 d-flex align-items-center justify-content-center">
  48. <img src="/images/loading.gif" class="mr-1">
  49. Connecting
  50. </p>
  51. </div>
  52. </div>
  53. <div v-if="!guest" class="tp-item mb-4">
  54. <img src="/images/person/guest.png" alt="" class="invite-image">
  55. <p class="font-weight-bold text-center mt-1">Invite Pro</p>
  56. </div>
  57. </div>
  58. </div>
  59. </div>
  60. <script>
  61. new Vue({
  62. el: '#meetingComponent',
  63. delimiters: ['@{{', '}}'],
  64. data: {
  65. meetingID: '<?= $meetingID ?>',
  66. participantID: '<?= $participantID ?>',
  67. socket: null,
  68. stompClient: null,
  69. time: 0,
  70. startTime: 0,
  71. started: false,
  72. guest: <?= $guest ? 'true' : 'false' ?>,
  73. activeType: false,
  74. activeParticipant: false,
  75. exitURL: '<?= $guest ? '/' : '/pro/dashboard' ?>',
  76. allPastels: [
  77. '#89cff0',
  78. '#99c5c4',
  79. '#9adedb',
  80. '#aa9499',
  81. '#aaf0d1',
  82. '#b2fba5',
  83. '#b39eb5',
  84. '#bdb0d0',
  85. '#bee7a5',
  86. '#befd73',
  87. '#c1c6fc',
  88. '#c6a4a4',
  89. '#c8ffb0',
  90. '#cb99c9',
  91. '#cef0cc',
  92. '#cfcfc4',
  93. '#d6fffe',
  94. '#d8a1c4',
  95. '#dea5a4',
  96. '#deece1',
  97. '#dfd8e1',
  98. '#e5d9d3',
  99. '#e9d1bf',
  100. '#f49ac2',
  101. '#f4bfff',
  102. '#fdfd96',
  103. '#ff6961',
  104. '#ff964f',
  105. '#ff9899',
  106. '#ffb7ce',
  107. '#ca9bf7'
  108. ],
  109. usedPastels: [],
  110. guests: [
  111. {
  112. id: '',
  113. name: '',
  114. image: '',
  115. color: '',
  116. status: 'connecting',
  117. },
  118. ],
  119. pros: [
  120. {
  121. id: '',
  122. name: '',
  123. type: '',
  124. image: '',
  125. color: '',
  126. status: '',
  127. }
  128. ]
  129. },
  130. methods: {
  131. getUnusedPastel: function() {
  132. for (let i = 0; i < this.allPastels.length; i++) {
  133. if(this.usedPastels.indexOf(this.allPastels[i]) === -1) {
  134. this.usedPastels.push(this.allPastels[i]);
  135. return this.allPastels[i];
  136. }
  137. }
  138. return '#fff';
  139. },
  140. getInitials: function(_name) {
  141. var parts = _name.split(/\s+/g);
  142. parts = parts.map(_part => _part[0]);
  143. return parts.join('');
  144. },
  145. setActiveView: function(_type, _participant) {
  146. if(_participant.status === 'active') {
  147. this.activeType = _type;
  148. this.activeParticipant = _participant;
  149. }
  150. },
  151. timeDisplay: function() {
  152. var seconds = this.time / 1000,
  153. minutes = parseInt(seconds / 60, 10);
  154. seconds = parseInt(seconds % 60, 10);
  155. return minutes + " min, " + seconds + " sec";
  156. },
  157. connectToFirstPro: function() {
  158. console.log('Connecting to first pro ...');
  159. this.pros = [];
  160. this.addPro();
  161. $.post('/api/meeting/request-dial-pro', {
  162. meetingUid: this.meetingID,
  163. }, function(_data) {
  164. console.log('Response to /api/meeting/request-dial-pro');
  165. console.log(_data);
  166. }, 'json');
  167. },
  168. addGuest: function() {
  169. this.guests.push({
  170. id: '',
  171. name: '',
  172. image: '',
  173. color: this.getUnusedPastel(),
  174. status: 'active',
  175. });
  176. return this.guests[this.guests.length - 1];
  177. },
  178. addPro: function() {
  179. this.pros.push({
  180. id: '0',
  181. name: 'Pro',
  182. type: 'Receptionist',
  183. image: '/images/person/nancy.jpg',
  184. color: this.getUnusedPastel(),
  185. status: 'connecting',
  186. });
  187. return this.pros[this.pros.length - 1];
  188. },
  189. onProJoined: function(_data) {
  190. var found = false;
  191. // find pro with participant id
  192. var pro = this.pros.filter(function(_pro) {
  193. return _pro.id === _data.meetingParticipantUid;
  194. });
  195. // no pro with id, find first one with id = 0
  196. if(!pro.length) {
  197. pro = this.pros.filter(function(_pro) {
  198. return _pro.id === "0";
  199. });
  200. }
  201. // no pro with id = 0, create one
  202. if(!pro.length) {
  203. pro = this.addPro();
  204. }
  205. else {
  206. pro = pro[0];
  207. }
  208. pro.id = _data.meetingParticipantUid;
  209. pro.name = _data.proDisplayName;
  210. pro.type = _data.hcpCategory;
  211. pro.status = 'active';
  212. @if($guest)
  213. var self = this;
  214. if(!this.startTime) {
  215. this.startTime = new Date().getTime();
  216. window.setInterval(function() {
  217. self.time = new Date().getTime() - self.startTime;
  218. }, 1000);
  219. this.started = true;
  220. }
  221. @endif
  222. // TODO: init pro stream
  223. },
  224. leaveCall: function() {
  225. this.stompClient.send("/app/meeting-participant-leave-meeting", {},
  226. JSON.stringify({
  227. meetingParticipantUid: this.participantID
  228. })
  229. );
  230. window.location.href = this.exitURL;
  231. }
  232. },
  233. mounted: function() {
  234. this.guests = [];
  235. this.pros = [];
  236. var self = this;
  237. // connect to WS
  238. self.socket = new SockJS('http://localhost:8080/ws');
  239. self.stompClient = Stomp.over(self.socket);
  240. self.stompClient.connect({}, function (frame) {
  241. console.log('Connected: ' + frame);
  242. @if($guest)
  243. // add self and set as active
  244. var guest = self.addGuest();
  245. guest.id = '<?= $participantID ?>';
  246. guest.status = 'active';
  247. guest.name = 'Guest';
  248. // WS Subscriptions
  249. self.stompClient.subscribe("/topic/on-pro-join-meeting", function (message) {
  250. console.log("on-pro-join-meeting:", message);
  251. self.onProJoined(JSON.parse(message.body));
  252. });
  253. // join self
  254. self.stompClient.send("/app/meeting-participant-join-meeting", {},
  255. JSON.stringify({
  256. meetingParticipantUid: self.participantID
  257. })
  258. );
  259. // attempt to connect to first pro if "start"
  260. @if(request('start'))
  261. self.connectToFirstPro();
  262. @endif
  263. @else
  264. // WS subscriptions
  265. // self joined confirmation
  266. self.stompClient.subscribe("/user/topic/on-pro-self-join-meeting", function (message) {
  267. console.log("/user/topic/on-pro-self-join-meeting:", message);
  268. var parsed = JSON.parse(message.body);
  269. self.onProJoined(parsed);
  270. self.participantID = parsed.meetingParticipantUid;
  271. });
  272. // join self
  273. self.stompClient.send("/app/pro-join-meeting", {},
  274. JSON.stringify({
  275. sessionKey: "<?= request()->cookie('sessionKey') ?>",
  276. meetingUid: "<?= $meetingID ?>",
  277. })
  278. );
  279. @if(!$guest)
  280. if(!self.startTime) {
  281. self.startTime = new Date().getTime();
  282. window.setInterval(function() {
  283. self.time = new Date().getTime() - self.startTime;
  284. }, 1000);
  285. self.started = true;
  286. }
  287. @endif
  288. @endif
  289. // TODO: init own stream
  290. self.stompClient.subscribe("/topic/on-meeting-participant-connection-status-change", function(message){
  291. /*
  292. String messagePartipantUid;
  293. boolean isConnected;
  294. */
  295. console.log(message);
  296. });
  297. });
  298. }
  299. });
  300. </script>
  301. @endsection