Bladeren bron

Agora V2 [get token via refreshMyMediaServiceToken EP]

Vijayakrishnan 4 jaren geleden
bovenliggende
commit
7e2a3ae3ce
1 gewijzigde bestanden met toevoegingen van 22 en 4 verwijderingen
  1. 22 4
      resources/views/app/video/call-agora-v2.blade.php

+ 22 - 4
resources/views/app/video/call-agora-v2.blade.php

@@ -18,6 +18,7 @@
             integrity="sha512-iKDtgDyTHjAitUDdLljGhenhPwrbBfqTKWO1mkhSFH3A7blITC9MhYon6SjnMhp4o0rADGw9yAC6EW4t5a4K3g=="
             crossorigin="anonymous"></script>
     <script defer src=//download.agora.io/sdk/web/AgoraRTC_N-4.1.0.js></script>
+    <title>Scholar: Meet</title>
 </head>
 
 <body class="p-0 m-0">
@@ -223,7 +224,6 @@
 
                     enterClientRoomAsPro: function() {
                         @if($client)
-
                         $.post('/api/meeting/enterClientRoomAsPro', {clientUid: '{{ $client->uid }}'}, (_data) => {
                             // TODO: check success
                             console.log(_data);
@@ -246,13 +246,20 @@
                                 this.inMeetingForClient.displayName = state.inMeetingForClient.displayName;
                                 this.inMeetingForClient.dob = state.inMeetingForClient.dob;
                                 this.meetingType = state.meetingType;
-                                this.myMediaServiceToken = state.myMediaServiceToken;
+                                // NOTE: this now comes frm its own end-point (see below)
+                                // this.myMediaServiceToken = state.myMediaServiceToken;
                                 this.myMediaServiceIdentifier = state.myMediaServiceIdentifier;
                                 this.otherParticipants = state.otherParticipants;
 
                                 if(_firstRun) {
-                                    this.channel = this.inMeetingForClient.clientMediaServiceRoomIdentifier;
-                                    this.registerSocket();
+                                    $.post('/api/meeting/refreshMyMediaServiceToken', (_data) => {  // get new agora token
+                                        if(!this.hasError(_data)) {
+                                            this.myMediaServiceToken = _data.data;
+                                            this.channel = this.inMeetingForClient.clientMediaServiceRoomIdentifier;
+                                            this.registerSocket();
+                                            debugger;
+                                        }
+                                    }, 'json');
                                 }
 
                                 console.log(this.$data);
@@ -579,6 +586,17 @@
                     },
                     // end: actions that notify participants via socket
 
+                    // utils: start
+                    hasError: function(_data) {     // check and report error if exists via toastr
+                        let msg = 'Unknown error!';
+                        if(_data) {
+                            if(_data.success) return false;
+                            else if(_data.message) msg = _data.message;
+                        }
+                        toastr.error(msg);
+                        return true;
+                    }
+                    // utils: end
                 },
                 mounted: function () {
                     this.enterClientRoomAsPro();