meeting.blade.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  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 text-single mx-1">@{{ 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 text-single mx-1">@{{ pro.name }}</p>
  43. <p v-if="pro.type" class="font-weight-normal text-center text-single mx-1">@{{ 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. const allParticipants = {!! json_encode($participants) !!},
  62. allPros = [],
  63. allGuests = [];
  64. for (let i = 0; i < allParticipants.length; i++) {
  65. if(allParticipants[i].guest_or_pro === 'PRO') {
  66. allPros.push({
  67. id: allParticipants[i].uid,
  68. name: allParticipants[i].proName,
  69. type: 'Pro',
  70. image: '',
  71. color: '', // fill in mounted()
  72. status: 'active',
  73. });
  74. }
  75. else {
  76. allGuests.push({
  77. id: allParticipants[i].uid,
  78. name: allParticipants[i].guest_name,
  79. image: '',
  80. color: '', // fill in mounted()
  81. status: 'active',
  82. })
  83. }
  84. }
  85. new Vue({
  86. el: '#meetingComponent',
  87. delimiters: ['@{{', '}}'],
  88. data: {
  89. meetingID: '<?= $meetingID ?>',
  90. participantID: '<?= $guest ? $participantID : '' ?>',
  91. socket: null,
  92. stompClient: null,
  93. time: 0,
  94. startTime: 0,
  95. started: false,
  96. guest: <?= $guest ? 'true' : 'false' ?>,
  97. activeType: false,
  98. activeParticipant: false,
  99. exitURL: '<?= $guest ? '/' : '/pro/dashboard' ?>',
  100. allPastels: [
  101. '#89cff0',
  102. '#99c5c4',
  103. '#9adedb',
  104. '#aa9499',
  105. '#aaf0d1',
  106. '#b2fba5',
  107. '#b39eb5',
  108. '#bdb0d0',
  109. '#bee7a5',
  110. '#befd73',
  111. '#c1c6fc',
  112. '#c6a4a4',
  113. '#c8ffb0',
  114. '#cb99c9',
  115. '#cef0cc',
  116. '#cfcfc4',
  117. '#d6fffe',
  118. '#d8a1c4',
  119. '#dea5a4',
  120. '#deece1',
  121. '#dfd8e1',
  122. '#e5d9d3',
  123. '#e9d1bf',
  124. '#f49ac2',
  125. '#f4bfff',
  126. '#fdfd96',
  127. '#ff6961',
  128. '#ff964f',
  129. '#ff9899',
  130. '#ffb7ce',
  131. '#ca9bf7'
  132. ],
  133. usedPastels: [],
  134. guests: [
  135. {
  136. id: '',
  137. name: '',
  138. image: '',
  139. color: '',
  140. status: 'connecting',
  141. },
  142. ],
  143. pros: [
  144. {
  145. id: '',
  146. name: '',
  147. type: '',
  148. image: '',
  149. color: '',
  150. status: '',
  151. }
  152. ]
  153. },
  154. methods: {
  155. getUnusedPastel: function() {
  156. for (let i = 0; i < this.allPastels.length; i++) {
  157. if(this.usedPastels.indexOf(this.allPastels[i]) === -1) {
  158. this.usedPastels.push(this.allPastels[i]);
  159. return this.allPastels[i];
  160. }
  161. }
  162. return '#fff';
  163. },
  164. getInitials: function(_name) {
  165. var parts = _name.split(/\s+/g);
  166. parts = parts.map(_part => _part[0]);
  167. return parts.join('');
  168. },
  169. setActiveView: function(_type, _participant) {
  170. if(_participant.status === 'active') {
  171. this.activeType = _type;
  172. this.activeParticipant = _participant;
  173. }
  174. },
  175. timeDisplay: function() {
  176. var seconds = this.time / 1000,
  177. minutes = parseInt(seconds / 60, 10);
  178. seconds = parseInt(seconds % 60, 10);
  179. return minutes + " min, " + seconds + " sec";
  180. },
  181. connectToFirstPro: function() {
  182. console.log('Connecting to first pro ...');
  183. this.pros = [];
  184. this.addPro();
  185. $.post('/api/meeting/request-dial-pro', {
  186. meetingUid: this.meetingID,
  187. }, function(_data) {
  188. console.log('Response to /api/meeting/request-dial-pro');
  189. console.log(_data);
  190. }, 'json');
  191. },
  192. ifGuestExisting: function(_id) {
  193. var matching = this.guests.filter(function(_item) {
  194. return _item.id === _id;
  195. });
  196. return !!matching.length;
  197. },
  198. addGuest: function() {
  199. this.guests.push({
  200. id: '',
  201. name: '',
  202. image: '',
  203. color: this.getUnusedPastel(),
  204. status: 'active',
  205. });
  206. return this.guests[this.guests.length - 1];
  207. },
  208. addPro: function() {
  209. this.pros.push({
  210. id: '0',
  211. name: 'Pro',
  212. type: 'Receptionist',
  213. image: '/images/person/nancy.jpg',
  214. color: this.getUnusedPastel(),
  215. status: 'connecting',
  216. });
  217. return this.pros[this.pros.length - 1];
  218. },
  219. onProJoined: function(_data) {
  220. var found = false;
  221. // find pro with participant id
  222. var pro = this.pros.filter(function(_pro) {
  223. return _pro.id === _data.meetingParticipantUid;
  224. });
  225. // no pro with id, find first one with id = 0
  226. if(!pro.length) {
  227. pro = this.pros.filter(function(_pro) {
  228. return _pro.id === "0";
  229. });
  230. }
  231. // no pro with id = 0, create one
  232. if(!pro.length) {
  233. pro = this.addPro();
  234. }
  235. else {
  236. pro = pro[0];
  237. }
  238. pro.id = _data.meetingParticipantUid;
  239. pro.name = _data.proDisplayName;
  240. pro.type = _data.hcpCategory;
  241. pro.status = 'active';
  242. @if($guest)
  243. var self = this;
  244. if(!this.startTime) {
  245. this.startTime = new Date().getTime();
  246. window.setInterval(function() {
  247. self.time = new Date().getTime() - self.startTime;
  248. }, 1000);
  249. this.started = true;
  250. }
  251. @endif
  252. // TODO: init pro stream
  253. },
  254. onParticipantLeft: function(_id) {
  255. this.pros = this.pros.filter(function(_row) {
  256. return _row.id !== _id;
  257. });
  258. this.guests = this.guests.filter(function(_row) {
  259. return _row.id !== _id;
  260. });
  261. },
  262. leaveCall: function() {
  263. this.stompClient.send("/app/meeting-participant-leave-meeting", {},
  264. JSON.stringify({
  265. meetingParticipantUid: this.participantID
  266. })
  267. );
  268. window.location.href = this.exitURL;
  269. }
  270. },
  271. mounted: function() {
  272. this.guests = allGuests;
  273. this.pros = allPros;
  274. for (let i = 0; i < this.guests.length; i++) {
  275. this.guests[i].color = this.getUnusedPastel();
  276. }
  277. for (let i = 0; i < this.pros.length; i++) {
  278. this.pros[i].color = this.getUnusedPastel();
  279. }
  280. var self = this;
  281. // connect to WS
  282. self.socket = new SockJS('http://localhost:8080/ws');
  283. self.stompClient = Stomp.over(self.socket);
  284. self.stompClient.connect({}, function (frame) {
  285. console.log('Connected: ' + frame);
  286. @if($guest)
  287. // add self and set as active
  288. if(!self.ifGuestExisting('<?= $participantID ?>')) {
  289. var guest = self.addGuest();
  290. guest.id = '<?= $participantID ?>';
  291. guest.status = 'active';
  292. guest.name = 'Guest';
  293. }
  294. // WS Subscriptions
  295. self.stompClient.subscribe("/topic/on-pro-join-meeting", function (message) {
  296. console.log("on-pro-join-meeting:", message);
  297. self.onProJoined(JSON.parse(message.body));
  298. });
  299. self.stompClient.subscribe("/topic/on-meeting-participant-left-meeting", function (message) {
  300. console.log("/topic/on-meeting-participant-left-meeting", message);
  301. var parsed = JSON.parse(message.body);
  302. self.onParticipantLeft(parsed.meetingParticipantUid);
  303. });
  304. // join self
  305. self.stompClient.send("/app/meeting-participant-join-meeting", {},
  306. JSON.stringify({
  307. meetingParticipantUid: self.participantID
  308. })
  309. );
  310. // attempt to connect to first pro if "start"
  311. @if(request('start'))
  312. self.connectToFirstPro();
  313. @endif
  314. @else
  315. // WS subscriptions
  316. // self joined confirmation
  317. self.stompClient.subscribe("/user/topic/on-pro-self-join-meeting", function (message) {
  318. console.log("/user/topic/on-pro-self-join-meeting:", message);
  319. var parsed = JSON.parse(message.body);
  320. self.onProJoined(parsed);
  321. self.participantID = parsed.meetingParticipantUid;
  322. });
  323. self.stompClient.subscribe("/topic/on-meeting-participant-left-meeting", function (message) {
  324. console.log("/topic/on-meeting-participant-left-meeting", message);
  325. var parsed = JSON.parse(message.body);
  326. self.onParticipantLeft(parsed.meetingParticipantUid);
  327. });
  328. // join self
  329. self.stompClient.send("/app/pro-join-meeting", {},
  330. JSON.stringify({
  331. sessionKey: "<?= request()->cookie('sessionKey') ?>",
  332. meetingUid: "<?= $meetingID ?>",
  333. })
  334. );
  335. @if(!$guest)
  336. if(!self.startTime) {
  337. self.startTime = new Date().getTime();
  338. window.setInterval(function() {
  339. self.time = new Date().getTime() - self.startTime;
  340. }, 1000);
  341. self.started = true;
  342. }
  343. @endif
  344. @endif
  345. // TODO: init own stream
  346. self.stompClient.subscribe("/topic/on-meeting-participant-connection-status-change", function(message){
  347. /*
  348. String messagePartipantUid;
  349. boolean isConnected;
  350. */
  351. console.log(message);
  352. });
  353. });
  354. }
  355. });
  356. </script>
  357. @endsection