123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389 |
- @extends('layouts.meeting')
- @section('content')
- <div id="meetingComponent">
- <h5 class="bg-dark font-weight-bold text-white m-0 py-3 px-4 d-flex">
- <span>Meeting</span>
- <span class="ml-auto" v-if="!started">
- Connecting...
- </span>
- <span class="ml-auto" v-if="started">
- <i class="fa fa-clock mr-1 text-light"></i>
- @{{ timeDisplay() }}
- </span>
- </h5>
- <div class="d-flex align-items-stretch mt-4 justify-content-center flex-nowrap">
- <div class="tp-bar">
- <div v-for="(guest, index) of guests"
- class="tp-item mb-4"
- :class="activeParticipant && activeType === 'guest' && activeParticipant.id === guest.id ? 'active' : ''"
- v-on:click="setActiveView('guest', guest)">
- <div class="avatar text-white" :style="'background: ' + guest.color">@{{ getInitials(guest.name) }}</div>
- <p class="font-weight-bold text-center mt-1 mb-0 text-single mx-1">@{{ guest.name }}</p>
- </div>
- <div v-if="guest" class="tp-item mb-4">
- <img src="/images/person/guest.png" alt="" class="invite-image">
- <p class="font-weight-bold text-center mt-1">Invite Guest</p>
- </div>
- </div>
- <div class="main-view" style="width: 800px; min-height: 600px;">
- <div class="p-4 w-100 h-100 d-flex align-items-stretch justify-content-end flex-column">
- <p class="font-weight-bold text-center text-white mt-2">Feed from @{{ activeParticipant.name }}</p>
- <button class="btn btn-sm btn-danger px-4 align-self-end mx-auto font-weight-bold"
- v-on:click="leaveCall()">Leave</button>
- </div>
- </div>
- <div class="tp-bar">
- <div v-for="(pro, index) of pros"
- class="tp-item mb-4"
- :class="activeParticipant && activeType === 'pro' && activeParticipant.id === pro.id ? 'active' : ''"
- v-on:click="setActiveView('pro', pro)">
- <div v-if="pro.status === 'active'">
- <div class="avatar text-white" :style="'background: ' + pro.color">@{{ getInitials(pro.name) }}</div>
- <p class="font-weight-bold text-center mt-1 mb-0 text-single mx-1">@{{ pro.name }}</p>
- <p v-if="pro.type" class="font-weight-normal text-center text-single mx-1">@{{ pro.type }}</p>
- </div>
- <div v-if="pro.status === 'connecting'">
- <img src="/images/person/connecting.jpg" alt="" class="w-100">
- <p class="font-weight-normal text-center mt-1 d-flex align-items-center justify-content-center">
- <img src="/images/loading.gif" class="mr-1">
- Connecting
- </p>
- </div>
- </div>
- <div v-if="!guest" class="tp-item mb-4">
- <img src="/images/person/guest.png" alt="" class="invite-image">
- <p class="font-weight-bold text-center mt-1">Invite Pro</p>
- </div>
- </div>
- </div>
- </div>
- <script>
- const allParticipants = {!! json_encode($participants) !!},
- allPros = [],
- allGuests = [];
- for (let i = 0; i < allParticipants.length; i++) {
- if(allParticipants[i].guest_or_pro === 'PRO') {
- allPros.push({
- id: allParticipants[i].uid,
- name: allParticipants[i].proName,
- type: 'Pro',
- image: '',
- color: '', // fill in mounted()
- status: 'active',
- });
- }
- else {
- allGuests.push({
- id: allParticipants[i].uid,
- name: allParticipants[i].guest_name,
- image: '',
- color: '', // fill in mounted()
- status: 'active',
- })
- }
- }
- new Vue({
- el: '#meetingComponent',
- delimiters: ['@{{', '}}'],
- data: {
- meetingID: '<?= $meetingID ?>',
- participantID: '<?= $guest ? $participantID : '' ?>',
- socket: null,
- stompClient: null,
- time: 0,
- startTime: 0,
- started: false,
- guest: <?= $guest ? 'true' : 'false' ?>,
- activeType: false,
- activeParticipant: false,
- exitURL: '<?= $guest ? '/' : '/pro/dashboard' ?>',
- allPastels: [
- '#89cff0',
- '#99c5c4',
- '#9adedb',
- '#aa9499',
- '#aaf0d1',
- '#b2fba5',
- '#b39eb5',
- '#bdb0d0',
- '#bee7a5',
- '#befd73',
- '#c1c6fc',
- '#c6a4a4',
- '#c8ffb0',
- '#cb99c9',
- '#cef0cc',
- '#cfcfc4',
- '#d6fffe',
- '#d8a1c4',
- '#dea5a4',
- '#deece1',
- '#dfd8e1',
- '#e5d9d3',
- '#e9d1bf',
- '#f49ac2',
- '#f4bfff',
- '#fdfd96',
- '#ff6961',
- '#ff964f',
- '#ff9899',
- '#ffb7ce',
- '#ca9bf7'
- ],
- usedPastels: [],
- guests: [
- {
- id: '',
- name: '',
- image: '',
- color: '',
- status: 'connecting',
- },
- ],
- pros: [
- {
- id: '',
- name: '',
- type: '',
- image: '',
- color: '',
- status: '',
- }
- ]
- },
- methods: {
- getUnusedPastel: function() {
- for (let i = 0; i < this.allPastels.length; i++) {
- if(this.usedPastels.indexOf(this.allPastels[i]) === -1) {
- this.usedPastels.push(this.allPastels[i]);
- return this.allPastels[i];
- }
- }
- return '#fff';
- },
- getInitials: function(_name) {
- var parts = _name.split(/\s+/g);
- parts = parts.map(_part => _part[0]);
- return parts.join('');
- },
- setActiveView: function(_type, _participant) {
- if(_participant.status === 'active') {
- this.activeType = _type;
- this.activeParticipant = _participant;
- }
- },
- timeDisplay: function() {
- var seconds = this.time / 1000,
- minutes = parseInt(seconds / 60, 10);
- seconds = parseInt(seconds % 60, 10);
- return minutes + " min, " + seconds + " sec";
- },
- connectToFirstPro: function() {
- console.log('Connecting to first pro ...');
- this.pros = [];
- this.addPro();
- $.post('/api/meeting/request-dial-pro', {
- meetingUid: this.meetingID,
- }, function(_data) {
- console.log('Response to /api/meeting/request-dial-pro');
- console.log(_data);
- }, 'json');
- },
- ifGuestExisting: function(_id) {
- var matching = this.guests.filter(function(_item) {
- return _item.id === _id;
- });
- return !!matching.length;
- },
- addGuest: function() {
- this.guests.push({
- id: '',
- name: '',
- image: '',
- color: this.getUnusedPastel(),
- status: 'active',
- });
- return this.guests[this.guests.length - 1];
- },
- addPro: function() {
- this.pros.push({
- id: '0',
- name: 'Pro',
- type: 'Receptionist',
- image: '/images/person/nancy.jpg',
- color: this.getUnusedPastel(),
- status: 'connecting',
- });
- return this.pros[this.pros.length - 1];
- },
- onProJoined: function(_data) {
- var found = false;
- // find pro with participant id
- var pro = this.pros.filter(function(_pro) {
- return _pro.id === _data.meetingParticipantUid;
- });
- // no pro with id, find first one with id = 0
- if(!pro.length) {
- pro = this.pros.filter(function(_pro) {
- return _pro.id === "0";
- });
- }
- // no pro with id = 0, create one
- if(!pro.length) {
- pro = this.addPro();
- }
- else {
- pro = pro[0];
- }
- pro.id = _data.meetingParticipantUid;
- pro.name = _data.proDisplayName;
- pro.type = _data.hcpCategory;
- pro.status = 'active';
- @if($guest)
- var self = this;
- if(!this.startTime) {
- this.startTime = new Date().getTime();
- window.setInterval(function() {
- self.time = new Date().getTime() - self.startTime;
- }, 1000);
- this.started = true;
- }
- @endif
- // TODO: init pro stream
- },
- onParticipantLeft: function(_id) {
- this.pros = this.pros.filter(function(_row) {
- return _row.id !== _id;
- });
- this.guests = this.guests.filter(function(_row) {
- return _row.id !== _id;
- });
- },
- leaveCall: function() {
- this.stompClient.send("/app/meeting-participant-leave-meeting", {},
- JSON.stringify({
- meetingParticipantUid: this.participantID
- })
- );
- window.location.href = this.exitURL;
- }
- },
- mounted: function() {
- this.guests = allGuests;
- this.pros = allPros;
- for (let i = 0; i < this.guests.length; i++) {
- this.guests[i].color = this.getUnusedPastel();
- }
- for (let i = 0; i < this.pros.length; i++) {
- this.pros[i].color = this.getUnusedPastel();
- }
- var self = this;
- // connect to WS
- self.socket = new SockJS('http://localhost:8080/ws');
- self.stompClient = Stomp.over(self.socket);
- self.stompClient.connect({}, function (frame) {
- console.log('Connected: ' + frame);
- @if($guest)
- // add self and set as active
- if(!self.ifGuestExisting('<?= $participantID ?>')) {
- var guest = self.addGuest();
- guest.id = '<?= $participantID ?>';
- guest.status = 'active';
- guest.name = 'Guest';
- }
- // WS Subscriptions
- self.stompClient.subscribe("/topic/on-pro-join-meeting", function (message) {
- console.log("on-pro-join-meeting:", message);
- self.onProJoined(JSON.parse(message.body));
- });
- self.stompClient.subscribe("/topic/on-meeting-participant-left-meeting", function (message) {
- console.log("/topic/on-meeting-participant-left-meeting", message);
- var parsed = JSON.parse(message.body);
- self.onParticipantLeft(parsed.meetingParticipantUid);
- });
- // join self
- self.stompClient.send("/app/meeting-participant-join-meeting", {},
- JSON.stringify({
- meetingParticipantUid: self.participantID
- })
- );
- // attempt to connect to first pro if "start"
- @if(request('start'))
- self.connectToFirstPro();
- @endif
- @else
- // WS subscriptions
- // self joined confirmation
- self.stompClient.subscribe("/user/topic/on-pro-self-join-meeting", function (message) {
- console.log("/user/topic/on-pro-self-join-meeting:", message);
- var parsed = JSON.parse(message.body);
- self.onProJoined(parsed);
- self.participantID = parsed.meetingParticipantUid;
- });
- self.stompClient.subscribe("/topic/on-meeting-participant-left-meeting", function (message) {
- console.log("/topic/on-meeting-participant-left-meeting", message);
- var parsed = JSON.parse(message.body);
- self.onParticipantLeft(parsed.meetingParticipantUid);
- });
- // join self
- self.stompClient.send("/app/pro-join-meeting", {},
- JSON.stringify({
- sessionKey: "<?= request()->cookie('sessionKey') ?>",
- meetingUid: "<?= $meetingID ?>",
- })
- );
- @if(!$guest)
- if(!self.startTime) {
- self.startTime = new Date().getTime();
- window.setInterval(function() {
- self.time = new Date().getTime() - self.startTime;
- }, 1000);
- self.started = true;
- }
- @endif
- @endif
- // TODO: init own stream
- self.stompClient.subscribe("/topic/on-meeting-participant-connection-status-change", function(message){
- /*
- String messagePartipantUid;
- boolean isConnected;
- */
- console.log(message);
- });
- });
- }
- });
- </script>
- @endsection
|