123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325 |
- @extends('layouts.meeting')
- @section('content')
- <div id="meetComponent">
- {{--<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>--}}
- @if(!$guest)
- <div v-if="!started" class="d-flex align-items-center justify-content-center py-2">
- <button class="btn btn-sm btn-primary px-4 font-weight-bold"
- v-on:click.prevent="nextPatient()"
- :disabled="client || checkingForNextPatient">Next Patient</button>
- </div>
- <div v-if="!started && noNextPatient" class="bg-light rounded text-center py-1 font-weight-bold text-sm">@{{ noNextPatient }}</div>
- @endif
- <div class="">
- <div class="py-3 text-center" v-if="started">
- <h6 class="text-black font-weight-bold m-0">Call in progress: @{{ timeDisplay() }}</h6>
- </div>
- @if($guest)
- <div class="py-3 text-center" v-if="!pro || !started">
- <h6 class="text-black font-weight-bold m-0">Please wait. Your doctor will be with you shortly...</h6>
- </div>
- @endif
- <div class="main-view mx-auto">
- <div id="self-view" class="<?= $guest ? 'full-view' : 'd-none' ?>"></div>
- <div <?= !$guest ? 'v-show="!!client"' : '' ?> id="remote-view" class="<?= $guest ? 'thumb-view' : 'full-view' ?>"></div>
- <button class="btn btn-danger rounded-circle hang-up"
- v-if="started"
- v-on:click.prevent="hangUp()">
- <i class="fa fa-phone"></i>
- </button>
- </div>
- </div>
- </div>
- <script>
- new Vue({
- el: '#meetComponent',
- delimiters: ['@{{', '}}'],
- data: {
- time: 0,
- startTime: 0,
- started: false,
- client: false,
- pro: false,
- selfName: '',
- selfToken: '',
- @if($guest)
- clientUid: '',
- checkInToken: '',
- @endif
- otSessionId: '',
- @if(!$guest)
- checkingForNextPatient: false,
- noNextPatient: false,
- @endif
- otSession: false,
- },
- methods: {
- nextPatient: function() {
- var self = this;
- this.checkingForNextPatient = true;
- $.post('/api/client/getNextClientForVideoVisit', {}, function(_data) {
- self.checkingForNextPatient = false;
- if(!_data.success) {
- self.noNextPatient = _data.message;
- window.setTimeout(function() {
- self.noNextPatient = false;
- }, 2000);
- }
- else {
- // get ot session key from client record
- self.client = true;
- self.clientUid = _data.data;
- self.getOpenTokSessionId(function() {
- self.selfName = 'Pro'; // TODO: replace with name of authed pro
- $.post('/api/openTok/getClientToken', {
- opentokSessionId: self.otSessionId,
- name: self.selfName
- }, function (_data) {
- self.selfToken = _data.data;
- self.initOpenTok();
- });
- });
- }
- }, 'json');
- },
- getInitials: function(_name) {
- var parts = _name.split(/\s+/g);
- parts = parts.map(_part => _part[0]);
- return parts.join('');
- },
- timeDisplay: function() {
- var seconds = this.time / 1000,
- minutes = parseInt(seconds / 60, 10);
- seconds = parseInt(seconds % 60, 10);
- return minutes + " min, " + seconds + " sec";
- },
- hangUp: function() {
- if(this.otSession) {
- this.otSession.disconnect();
- this.otSession = false;
- this.otSessionId = '';
- this.started = false;
- this.startTime = false;
- @if(!$guest)
- this.client = false;
- @else
- window.location = '/join';
- @endif
- }
- },
- // OT methods
- initOpenTok: function() {
- /* fake video feed (temp) */
- const randomColour = () => {
- return Math.round(Math.random() * 255);
- };
- const canvas = document.createElement('canvas');
- canvas.width = 640;
- canvas.height = 480;
- const ctx = canvas.getContext('2d');
- var pos = 100;
- window.setInterval(function() {
- ctx.clearRect(0, 0, canvas.width, canvas.height);
- ctx.font = "20px Georgia";
- ctx.fillStyle = `rgb(220, 220, 220)`;
- var userType = '<?= $guest? "Client" : "Pro" ?>';
- ctx.fillText("Video feed from the " + userType, 20, pos);
- pos += 5;
- if(pos > canvas.height) pos = 100;
- }, 1000);
- var self = this;
- var apiKey = '<?= env('TOKBOX_API_KEY', '46678902') ?>';
- var sessionId = this.otSessionId;
- var token = this.selfToken;
- // destroy if existing
- self.hangUp();
- self.otSession = OT.initSession(apiKey, sessionId);
- self.otSession.on('streamCreated', function streamCreated(event) {
- var subscriberOptions = {
- insertMode: 'append',
- width: '100%',
- height: '100%'
- };
- self.otSession.subscribe(event.stream, 'remote-view', subscriberOptions, self.handleOpenTokError);
- @if($guest)
- $('#self-view').removeClass('full-view').addClass('thumb-view');
- $('#remote-view').removeClass('thumb-view').addClass('full-view');
- self.pro = true;
- @else
- self.joinMeetingAsPro();
- self.client = true;
- @endif
- if(!self.startTime) {
- self.startTime = new Date().getTime();
- window.setInterval(function() {
- self.time = new Date().getTime() - self.startTime;
- }, 1000);
- self.started = true;
- }
- });
- self.otSession.on("streamDestroyed", function(event) {
- @if($guest)
- $('#remote-view').removeClass('full-view').addClass('thumb-view');
- $('#self-view').removeClass('thumb-view').addClass('full-view');
- self.pro = false;
- @else
- self.client = false;
- @endif
- self.started = false;
- self.startTime = false;
- self.hangUp();
- });
- self.otSession.on('sessionDisconnected', function sessionDisconnected(event) {
- console.log('You were disconnected from the session.', event.reason);
- });
- // initialize the publisher
- var publisherOptions = {
- videoSource: canvas.captureStream(1).getVideoTracks()[0],
- insertMode: 'append',
- width: '100%',
- height: '100%',
- };
- var publisher = OT.initPublisher('self-view', publisherOptions, self.handleOpenTokError);
- // Connect to the session
- self.otSession.connect(token, function callback(error) {
- if (error) {
- self.handleOpenTokError(error);
- } else {
- // If the connection is successful, publish the publisher to the session
- self.otSession.publish(publisher, self.handleOpenTokError);
- }
- });
- },
- handleOpenTokError: function(e) {
- },
- getClientCheckinToken: function(_done) {
- var self = this;
- $.get('/get-client-checkin-token/' + this.clientUid, function(_data) {
- console.log(_data);
- self.checkInToken = _data.data;
- _done();
- }, 'json');
- },
- getOpenTokSessionId: function(_done) {
- var self = this;
- @if($guest)
- $.ajax({
- type: 'post',
- url: '/api/clientVideoVisit/startVideoVisitAsStranger',
- headers: {
- 'sessionKey': localStorage.sessionKey
- },
- data: {checkInToken: this.checkInToken},
- dataType: 'json'
- })
- .done(function (_data) {
- console.log(_data);
- if(_data.success) {
- self.otSessionId = _data.data;
- _done();
- }
- else {
- alert(_data.message);
- }
- })
- .fail(function (_data) {
- console.log(_data);
- alert(_data.message);
- });
- @else
- $.get('/pro/get-opentok-session-key/' + self.clientUid, function(_data) {
- self.otSessionId = _data.data;
- _done();
- }, 'json');
- @endif
- },
- joinMeetingAsPro: function() {
- var self = this;
- $.ajax({
- type: 'post',
- url: '/api/clientVideoVisit/joinVideoVisitAsMcpPro',
- headers: {
- 'sessionKey': localStorage.sessionKey
- },
- data: {uid: self.clientUid},
- dataType: 'json'
- })
- .done(function (_data) {
- console.log(_data);
- })
- .fail(function (_data) {
- console.warn(_data);
- alert(_data.message);
- });
- }
- },
- mounted: function() {
- var self = this;
- @if($guest)
- this.clientUid = localStorage.clientUid;
- this.getClientCheckinToken(function() { // get client check-in token
- self.getOpenTokSessionId(function() { // get opentok session id
- var name = [];
- if (localStorage.clientFirstName) name.push(localStorage.clientFirstName);
- if (localStorage.clientLastName) name.push(localStorage.clientLastName);
- this.selfName = name.join(' ');
- $.post('/api/openTok/getClientToken', {
- opentokSessionId: self.otSessionId,
- name: name.join(' ')
- }, function (_data) {
- self.selfToken = _data.data;
- self.initOpenTok();
- });
- });
- });
- @endif
- }
- });
- </script>
- @endsection
|