Browse Source

Added new method for backed call.
Added support for meeting: leave, close, kick.

Kain_Stropov 5 years ago
parent
commit
46e9075779

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

@@ -95,4 +95,35 @@ class AppSessionController extends Controller
         return redirect($request->input('_success'));
         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);
+    }
 }
 }

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

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

+ 15 - 15
resources/js/components/pages/ClientEntrance.vue

@@ -210,7 +210,7 @@ export default {
             this.meetingName = `${this.user.firstName} ${this.user.lastName} ${this.user.dateOfBirth}`;
             this.meetingName = `${this.user.firstName} ${this.user.lastName} ${this.user.dateOfBirth}`;
 
 
             $.ajax({
             $.ajax({
-                url: "/post-to-api",
+                url: "/post-to-api-ajax",
                 method: "POST",
                 method: "POST",
                 headers: {
                 headers: {
                     "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content")
                     "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content")
@@ -307,18 +307,17 @@ export default {
                 cont.el.appendChild(cont.obj.element);
                 cont.el.appendChild(cont.obj.element);
                 this.getToken();
                 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 */
         /* Copied */
         disconnect() {
         disconnect() {
@@ -342,7 +341,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?")))
             // if (this.meeting.scheduledDate && !this.meeting.startedAt && this.meeting.scheduledDate > new Date() && (this.user.type === "guest" || !confirm("Meeting not started. Start it now?")))
             //     return;
             //     return;
             $.ajax({
             $.ajax({
-                url: "/post-to-api",
+                url: "/post-to-api-ajax",
                 method: "POST",
                 method: "POST",
                 headers: {
                 headers: {
                     "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content")
                     "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content")
@@ -483,6 +482,7 @@ export default {
                 sessionDisconnected: event => {
                 sessionDisconnected: event => {
                     if (event.reason === "forceDisconnected") {
                     if (event.reason === "forceDisconnected") {
                         alert("You were kicked.");
                         alert("You were kicked.");
+                        window.location.reload();
                         //TODO: Kicked
                         //TODO: Kicked
                         // if (this.user.type === "associate") {
                         // if (this.user.type === "associate") {
                         //     this.disconnect();
                         //     this.disconnect();
@@ -671,7 +671,7 @@ export default {
 
 
         this.$eventBus.$on("leaveMeeting", () => {
         this.$eventBus.$on("leaveMeeting", () => {
             $.ajax({
             $.ajax({
-                url: "/associate/meeting/leave",
+                url: "/post-to-api-ajax",
                 method: "POST",
                 method: "POST",
                 headers: {
                 headers: {
                     "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content")
                     "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content")

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

@@ -100,7 +100,7 @@ export default {
         joinMeeting(lobby) {
         joinMeeting(lobby) {
             this.loading = true;
             this.loading = true;
             $.ajax({
             $.ajax({
-                url: "/post-to-api",
+                url: "/post-to-api-ajax",
                 method: "POST",
                 method: "POST",
                 headers: {
                 headers: {
                     "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content")
                     "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content")
@@ -115,7 +115,7 @@ export default {
                         this.$eventBus.$emit("meetingRejoin");
                         this.$eventBus.$emit("meetingRejoin");
                     } else {
                     } else {
                         lobby.selected_meeting.lobby = lobby;
                         lobby.selected_meeting.lobby = lobby;
-                        this.$store.commit("setMeeting", {lobby_uid: lobby.uid, ...lobby.selected_meeting});
+                        this.$store.commit("setMeeting", { lobby_uid: lobby.uid, ...lobby.selected_meeting });
                     }
                     }
                 },
                 },
                 error: jXhr => {},
                 error: jXhr => {},
@@ -123,6 +123,27 @@ export default {
                     this.loading = false;
                     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 => {
+                // },
+                error: jXhr => {},
+                complete: () => {
+                    this.loading = false;
+                }
+            });
         }
         }
     }
     }
 };
 };

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

@@ -90,7 +90,7 @@ export default {
         },
         },
         getToken() {
         getToken() {
             $.ajax({
             $.ajax({
-                url: "/post-to-api",
+                url: "/post-to-api-ajax",
                 method: "POST",
                 method: "POST",
                 headers: {
                 headers: {
                     "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content")
                     "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content")
@@ -224,12 +224,7 @@ export default {
                 sessionDisconnected: event => {
                 sessionDisconnected: event => {
                     if (event.reason === "forceDisconnected") {
                     if (event.reason === "forceDisconnected") {
                         alert("You were kicked.");
                         alert("You were kicked.");
-                        if (this.user.type === "associate") {
-                            this.disconnect();
-                            this.$store.dispatch("leaveMeeting");
-                        } else {
-                            window.location = "/";
-                        }
+                        this.$store.dispatch("leaveMeeting");
                     }
                     }
                 }
                 }
             });
             });
@@ -416,20 +411,21 @@ export default {
         },
         },
         kickParcitipantContinue(participant) {
         kickParcitipantContinue(participant) {
             const connection = participant.video.obj.stream.connection;
             const connection = participant.video.obj.stream.connection;
-            const [type, id] = connection.data.split(":");
+            const id = connection.data;
             this.openTokSession.forceDisconnect(connection, error => {
             this.openTokSession.forceDisconnect(connection, error => {
                 if (error) {
                 if (error) {
                     console.error(error);
                     console.error(error);
                 } else {
                 } else {
                     $.ajax({
                     $.ajax({
-                        url: `/associate/meeting/${this.meeting.id}/kick`,
+                        url: "/post-to-api-ajax",
                         method: "POST",
                         method: "POST",
                         headers: {
                         headers: {
                             "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content")
                             "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content")
                         },
                         },
                         data: {
                         data: {
-                            type,
-                            id
+                            _api: "/api/meeting/kick",
+                            uid: this.meeting.uid,
+                            participantUid: id
                         },
                         },
                         error: jXhr => {
                         error: jXhr => {
                             console.error(getSingleError(jXhr));
                             console.error(getSingleError(jXhr));
@@ -440,6 +436,22 @@ export default {
         },
         },
         kickParcitipant(participant) {
         kickParcitipant(participant) {
             if (confirm("Are you sure want to kick this person out of meeting?")) this.kickParcitipantContinue(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"
+                },
+                error: jXhr => {
+                    console.error(getSingleError(jXhr));
+                }
+            });
+            this.$store.dispatch("leaveMeeting");
         }
         }
     },
     },
     watch: {
     watch: {
@@ -462,6 +474,7 @@ export default {
             if (val) {
             if (val) {
                 this.getToken();
                 this.getToken();
             } else {
             } else {
+                this.disconnect();
                 this.loadingInProgress = false;
                 this.loadingInProgress = false;
             }
             }
         },
         },
@@ -498,20 +511,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) {
         if (this.meeting.uid) {
             this.getToken();
             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', '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');
 Route::get('/client/{url_slug}', 'ClientController@entrance')->name('client-entrance');