Merge pull request #157 from thecodingmachine/fixing_long_disconnect
authorDavid NĂ©grier <d.negrier@thecodingmachine.com>
Mon, 8 Jun 2020 16:09:12 +0000 (18:09 +0200)
committerGitHub <noreply@github.com>
Mon, 8 Jun 2020 16:09:12 +0000 (18:09 +0200)
Adding connecting spinner and blinking error to webrtc display

front/dist/resources/style/style.css
front/src/WebRtc/MediaManager.ts
front/src/WebRtc/SimplePeer.ts

index 3f3c2c625d49eda47ee11bb9cc1d824bf91342eb..458dde9c1cbda1776228495c3db21959fc96b12d 100644 (file)
@@ -148,4 +148,62 @@ video{
     top: calc(48px - 37px);
     left: calc(48px - 41px);
     position: relative;
-}
\ No newline at end of file
+}
+
+/* Spinner */
+.connecting-spinner {
+      /*display: inline-block;*/
+      position: absolute;
+      left: calc(50% - 68px);
+      top: calc(50% - 68px);
+
+
+      width: 130px;
+      height: 130px;
+  }
+.connecting-spinner:after {
+    content: " ";
+    display: block;
+    width: 108px;
+    height: 108px;
+    margin: 8px;
+    border-radius: 50%;
+    border: 6px solid #fff;
+    border-color: #fff transparent #fff transparent;
+    animation: connecting-spinner 1.2s linear infinite;
+}
+@keyframes connecting-spinner {
+    0% {
+        transform: rotate(0deg);
+    }
+    100% {
+        transform: rotate(360deg);
+    }
+}
+
+
+.rtc-error {
+    position: absolute;
+    left: calc(50% - 68px);
+    top: calc(50% - 68px);
+
+
+    width: 130px;
+    height: 130px;
+}
+.rtc-error:after {
+    content: " ";
+    display: block;
+    width: 108px;
+    height: 108px;
+    margin: 8px;
+    border-radius: 50%;
+    border: 6px solid #f00;
+    animation: blinker 1s linear infinite;
+}
+
+@keyframes blinker {
+    50% {
+        opacity: 0;
+    }
+}
index bb3f0cb942b43ee97bd10de67e5b93d18b3f2233..359eac67a08ce47bb89f240af5c3cf7fe8262229 100644 (file)
@@ -143,6 +143,8 @@ export class MediaManager {
         let color = this.getColorByString(userName);
         elementRemoteVideo.insertAdjacentHTML('beforeend', `
             <div id="div-${userId}" class="video-container" style="border-color: ${color};">
+                <div class="connecting-spinner"></div>
+                <div class="rtc-error" style="display: none"></div>
                 <i style="background-color: ${color};">${userName}</i>
                 <img id="microphone-${userId}" src="resources/logos/microphone-close.svg">
                 <video id="${userId}" autoplay></video>
@@ -228,6 +230,43 @@ export class MediaManager {
         element.remove();
     }
 
+    isConnecting(userId : string): void {
+        let connectingSpinnerDiv = this.getSpinner(userId);
+        if (connectingSpinnerDiv === null) {
+            return;
+        }
+        connectingSpinnerDiv.style.display = 'block';
+    }
+
+    isConnected(userId : string): void {
+        let connectingSpinnerDiv = this.getSpinner(userId);
+        if (connectingSpinnerDiv === null) {
+            return;
+        }
+        connectingSpinnerDiv.style.display = 'none';
+    }
+
+    isError(userId : string): void {
+        let element = document.getElementById(`div-${userId}`);
+        if(!element){
+            return;
+        }
+        let errorDiv = element.getElementsByClassName('rtc-error').item(0) as HTMLDivElement|null;
+        if (errorDiv === null) {
+            return;
+        }
+        errorDiv.style.display = 'block';
+    }
+
+    private getSpinner(userId : string): HTMLDivElement|null {
+        let element = document.getElementById(`div-${userId}`);
+        if(!element){
+            return null;
+        }
+        let connnectingSpinnerDiv = element.getElementsByClassName('connecting-spinner').item(0) as HTMLDivElement|null;
+        return connnectingSpinnerDiv;
+    }
+
     /**
      *
      * @param str
index 902d316c27d4d06f03bf6e221e857872dd459b3f..da1ae3db27cc6d5bc118bd9f0f70a906fa08cd8f 100644 (file)
@@ -161,9 +161,11 @@ export class SimplePeer {
 
         peer.on('error', (err: any) => {
             console.error(`error => ${user.userId} => ${err.code}`, err);
+            this.MediaManager.isError(user.userId);
         });
 
         peer.on('connect', () => {
+            this.MediaManager.isConnected(user.userId);
             console.info(`connect => ${user.userId}`);
         });