Browse Source

feat(ringoverlay): Stop ringing after 30s and change the message

j8
hristoterezov 8 years ago
parent
commit
ad5fa13339
1 changed files with 20 additions and 7 deletions
  1. 20
    7
      modules/UI/ring_overlay/RingOverlay.js

+ 20
- 7
modules/UI/ring_overlay/RingOverlay.js View File

@@ -11,25 +11,31 @@ class RingOverlay {
11 11
     constructor(callee) {
12 12
         this._containerId = 'ringOverlay';
13 13
         this._audioContainerId = 'ringOverlayRinging';
14
-
14
+        this.isRinging = true;
15 15
         this.callee = callee;
16 16
         this.render();
17 17
         this.audio = document.getElementById(this._audioContainerId);
18 18
         this.audio.play();
19 19
         this._setAudioTimeout();
20
+        this._timeout = setTimeout(() => {
21
+            this.destroy();
22
+            this.render();
23
+        }, 30000);
20 24
     }
21 25
 
22 26
     /**
23 27
      * Builds and appends the ring overlay to the html document
24 28
      */
25 29
     _getHtmlStr(callee) {
30
+        let callingLabel = this.isRinging? "<p>Calling...</p>" : "";
31
+        let callerStateLabel =  this.isRinging? "" : " isn't available";
26 32
         return `
27 33
             <div id="${this._containerId}" class='ringing' >
28 34
                 <div class='ringing__content'>
29
-                    <p>Calling...</p>
35
+                    ${callingLabel}
30 36
                     <img class='ringing__avatar' src="${callee.getAvatarUrl()}" />
31 37
                     <div class="ringing__caller-info">
32
-                        <p>${callee.getName()}</p>
38
+                        <p>${callee.getName()}${callerStateLabel}</p>
33 39
                     </div>
34 40
                 </div>
35 41
                 <audio id="${this._audioContainerId}" src="/sounds/ring.ogg" />
@@ -49,10 +55,7 @@ class RingOverlay {
49 55
      * related to the ring overlay.
50 56
      */
51 57
     destroy() {
52
-        if (this.interval) {
53
-            clearInterval(this.interval);
54
-        }
55
-
58
+        this._stopAudio();
56 59
         this._detach();
57 60
     }
58 61
 
@@ -64,6 +67,16 @@ class RingOverlay {
64 67
         $(`#${this._containerId}`).remove();
65 68
     }
66 69
 
70
+    _stopAudio() {
71
+        this.isRinging = false;
72
+        if (this.interval) {
73
+            clearInterval(this.interval);
74
+        }
75
+        if(this._timeout) {
76
+            clearTimeout(this._timeout);
77
+        }
78
+    }
79
+
67 80
     /**
68 81
      * Sets the interval that is going to play the ringing sound.
69 82
      */

Loading…
Cancel
Save