Flavionel 5 gadi atpakaļ
vecāks
revīzija
f06a6419ea

+ 31 - 0
app/Http/Controllers/AppSessionController.php

@@ -95,4 +95,35 @@ class AppSessionController extends Controller
         return redirect($request->input('_success'));
 
     }
+
+    public function postToAPIAjax(Request $request) {
+
+        session()->remove('message');
+
+        // call java api
+
+        $data = [];
+        $fields = $request->all();
+        foreach ($fields as $key => $value) {
+            if($key[0] !== '_') {
+                $data[$key] = $value;
+            }
+        }
+
+        if(!isset($data['uid']) && isset($fields['_uid'])) {
+            $data['uid'] = $fields['_uid'];
+        }
+
+        $url = env('BACKEND_URL', 'http://localhost:8080') . $request->input('_api');
+        // dd($url);
+
+        $response = Http::asForm()
+            ->withHeaders(['sessionKey'=>$request->cookie('sessionKey')])
+            ->post($url, $data)
+            ->json();
+
+        // dd($response);
+
+        return response()->json($response);
+    }
 }

+ 5 - 0
app/Http/Controllers/ClientController.php

@@ -17,6 +17,11 @@ class ClientController extends Controller
 
 	// GET /care_months
 	public function entrance(Request $request, Lobby $lobby) {
+        if (!$lobby->id) {
+            \abort(404);
+            return;
+        }
+
         $sessionKey = Cookie::get('sessionKey');
 
         $lobbyModel = new ClientLobbyModel($lobby);

+ 1 - 1
app/Http/Controllers/MeetingCenterController.php

@@ -24,7 +24,7 @@ class MeetingCenterController extends Controller
         $appSession = AppSession::where("session_key",$sessionKey)->first();
         $user = new ProModel($appSession->pro);
         $meeting = null;
-        if ($appSession->meetingParticipant) {
+        if ($appSession->is_currently_meeting_participant) {
             $meeting = new MeetingWithLobbyModel($appSession->meetingParticipant->meeting);
         }
 

+ 37 - 17
resources/js/components/pages/ClientEntrance.vue

@@ -24,7 +24,7 @@
                 <v-stepper-content step="1">
                     <v-card class="mb-12" color="grey lighten-1" height="200px">
                         <div class="checkin-form d-flex justify-content-center align-items-center">
-                            <div>
+                            <form ref="baseForm">
                                 <!-- <input type="hidden" name="lobbyUid" value />
                                 <input type="hidden" name="_api" value="/api/meeting/createAsStrangerPerformer" />
                                 <input type="hidden" name="_success" value="/pro/login" />
@@ -42,7 +42,7 @@
                                 <div class="input-group mb-3">
                                     <input type="date" name="strangerDob" class="form-control" placeholder="Date of Birth" v-model="user.dateOfBirth" required />
                                 </div>
-                            </div>
+                            </form>
                         </div>
                     </v-card>
 
@@ -203,9 +203,13 @@ export default {
         checkIn() {
             this.loading = true;
             this.meetingName = `${this.user.firstName} ${this.user.lastName} ${this.user.dateOfBirth}`;
+            if (!this.$refs.baseForm.reportValidity()) {
+                this.loading = false;
+                return;
+            }
 
             $.ajax({
-                url: "/post-to-api",
+                url: "/post-to-api-ajax",
                 method: "POST",
                 headers: {
                     "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content")
@@ -220,6 +224,10 @@ export default {
                     strangerDob: this.user.dateOfBirth
                 },
                 success: data => {
+                    if (!data.success) {
+                        alert(data.message);
+                        return;
+                    }
                     this.stepper = 2;
                     this.meetingUid = data.data;
 
@@ -303,18 +311,17 @@ export default {
                 cont.el.appendChild(cont.obj.element);
                 this.getToken();
 
-                this.$socket.emit('meetingJoined',
-                    {
-                        lobby_uid: this.lobbyProp.uid,
-                        meeting_name: this.meetingName,
-                        meeting_uid: this.meetingUid,
-                        user: {
-                            name: `${this.firstName} ${this.lastName}`,
-                            type: 'STRANGER',
-                            uid: this.clientUid
-                        }
-                    })
-            })
+                this.$socket.emit("meetingJoined", {
+                    lobby_uid: this.lobbyProp.uid,
+                    meeting_name: this.meetingName,
+                    meeting_uid: this.meetingUid,
+                    user: {
+                        name: `${this.firstName} ${this.lastName}`,
+                        type: "STRANGER",
+                        uid: this.clientUid
+                    }
+                });
+            });
         },
         /* Copied */
         disconnect() {
@@ -337,7 +344,7 @@ export default {
             // if (this.meeting.scheduledDate && !this.meeting.startedAt && this.meeting.scheduledDate > new Date() && (this.user.type === "guest" || !confirm("Meeting not started. Start it now?")))
             //     return;
             $.ajax({
-                url: "/post-to-api",
+                url: "/post-to-api-ajax",
                 method: "POST",
                 headers: {
                     "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content")
@@ -347,6 +354,18 @@ export default {
                     uid: this.meetingUid
                 },
                 success: data => {
+                    if (!data.success) {
+                        alert(data.message);
+                        return;
+                    }
+                    // this.$refs.initialModal.hide();
+                    // if (!isAssociate) {
+                    //     const user = Object.assign({}, this.user);
+                    //     user.id = data.participantId;
+                    //     user.name = data.participantName;
+                    //     user.pin = data.participantPin;
+                    //     this.$store.commit("setUser", user);
+                    // }
                     this.initializeOpenTok(data.data.apiKey, data.data.sessionId, data.data.token);
                 },
                 error: jXhr => {
@@ -470,6 +489,7 @@ export default {
                 sessionDisconnected: event => {
                     if (event.reason === "forceDisconnected") {
                         alert("You were kicked.");
+                        window.location.reload();
                         //TODO: Kicked
                         // if (this.user.type === "associate") {
                         //     this.disconnect();
@@ -659,7 +679,7 @@ export default {
 
         this.$eventBus.$on("leaveMeeting", () => {
             $.ajax({
-                url: "/associate/meeting/leave",
+                url: "/post-to-api-ajax",
                 method: "POST",
                 headers: {
                     "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content")

+ 31 - 2
resources/js/components/partials/LobbyList.vue

@@ -100,7 +100,7 @@ export default {
         joinMeeting(lobby) {
             this.loading = true;
             $.ajax({
-                url: "/post-to-api",
+                url: "/post-to-api-ajax",
                 method: "POST",
                 headers: {
                     "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content")
@@ -111,11 +111,40 @@ export default {
                     uid: lobby.selected_meeting.uid
                 },
                 success: data => {
+                    if (!data.success) {
+                        alert(data.message);
+                        return;
+                    }
                     if (this.meeting.uid === lobby.selected_meeting.uid) {
                         this.$eventBus.$emit("meetingRejoin");
                     } else {
                         lobby.selected_meeting.lobby = lobby;
-                        this.$store.commit("setCurrentMeeting", {lobby_uid: lobby.uid, ...lobby.selected_meeting});
+                        this.$store.commit("setCurrentMeeting", { lobby_uid: lobby.uid, ...lobby.selected_meeting });
+                    }
+                },
+                error: jXhr => {},
+                complete: () => {
+                    this.loading = false;
+                }
+            });
+        },
+        closeMeeting(lobby) {
+            this.loading = true;
+            $.ajax({
+                url: "/post-to-api-ajax",
+                method: "POST",
+                headers: {
+                    "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content")
+                },
+                dataType: "json",
+                data: {
+                    _api: "/api/meeting/close",
+                    uid: lobby.selected_meeting.uid
+                },
+                success: data => {
+                    if (!data.success) {
+                        alert(data.message);
+                        return;
                     }
                 },
                 error: jXhr => {},

+ 42 - 25
resources/js/components/partials/MeetingRoom.vue

@@ -89,7 +89,7 @@ export default {
         },
         getToken() {
             $.ajax({
-                url: "/post-to-api",
+                url: "/post-to-api-ajax",
                 method: "POST",
                 headers: {
                     "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content")
@@ -99,6 +99,10 @@ export default {
                     uid: this.meeting.uid
                 },
                 success: data => {
+                    if (!data.success) {
+                        alert(data.message);
+                        return;
+                    }
                     this.initializeOpenTok(data.data.apiKey, data.data.sessionId, data.data.token);
                 },
                 error: jXhr => {
@@ -223,12 +227,7 @@ export default {
                 sessionDisconnected: event => {
                     if (event.reason === "forceDisconnected") {
                         alert("You were kicked.");
-                        if (this.user.type === "associate") {
-                            this.disconnect();
-                            this.$store.dispatch("leaveMeeting");
-                        } else {
-                            window.location = "/";
-                        }
+                        this.$store.dispatch("leaveMeeting");
                     }
                 }
             });
@@ -365,20 +364,27 @@ export default {
         },
         kickParcitipantContinue(participant) {
             const connection = participant.video.obj.stream.connection;
-            const [type, id] = connection.data.split(":");
+            const id = connection.data;
             this.openTokSession.forceDisconnect(connection, error => {
                 if (error) {
                     console.error(error);
                 } else {
                     $.ajax({
-                        url: `/associate/meeting/${this.meeting.id}/kick`,
+                        url: "/post-to-api-ajax",
                         method: "POST",
                         headers: {
                             "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content")
                         },
                         data: {
-                            type,
-                            id
+                            _api: "/api/meeting/kick",
+                            uid: this.meeting.uid,
+                            participantUid: id
+                        },
+                        success: data => {
+                            if (!data.success) {
+                                alert(data.message);
+                                return;
+                            }
                         },
                         error: jXhr => {
                             console.error(getSingleError(jXhr));
@@ -389,6 +395,29 @@ export default {
         },
         kickParcitipant(participant) {
             if (confirm("Are you sure want to kick this person out of meeting?")) this.kickParcitipantContinue(participant);
+        },
+        leaveMeeting() {
+            $.ajax({
+                url: "/post-to-api-ajax",
+                method: "POST",
+                headers: {
+                    "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content")
+                },
+                data: {
+                    _api: "/api/meeting/leave"
+                },
+                success: data => {
+                    if (!data.success) {
+                        alert(data.message);
+                        return;
+                    }
+                    this.$store.dispatch("leaveMeeting");
+                },
+                error: jXhr => {
+                    console.error(getSingleError(jXhr));
+                }
+            });
+            this.$store.dispatch("leaveMeeting");
         }
     },
     watch: {
@@ -411,6 +440,7 @@ export default {
             if (val) {
                 this.getToken();
             } else {
+                this.disconnect();
                 this.loadingInProgress = false;
             }
         }
@@ -437,20 +467,7 @@ export default {
             }
         });
 
-        this.$eventBus.$on("leaveMeeting", () => {
-            // $.ajax({
-            //     url: "/associate/meeting/leave",
-            //     method: "POST",
-            //     headers: {
-            //         "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content")
-            //     },
-            //     error: jXhr => {
-            //         console.error(getSingleError(jXhr));
-            //     }
-            // });
-            this.$store.dispatch("leaveMeeting");
-            this.disconnect();
-        });
+        this.$eventBus.$on("leaveMeeting", this.leaveMeeting);
 
         if (this.meeting.uid) {
             this.getToken();

+ 1 - 0
routes/web.php

@@ -58,6 +58,7 @@ Route::middleware('ensureValidSession')->group(function(){
 });
 
 Route::post('/post-to-api', 'AppSessionController@postToAPI')->name('post-to-api');
+Route::post('/post-to-api-ajax', 'AppSessionController@postToAPIAjax')->name('post-to-api-ajax');
 
 Route::get('/client/{url_slug}', 'ClientController@entrance')->name('client-entrance');