瀏覽代碼

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

j8
hristoterezov 8 年之前
父節點
當前提交
ad5fa13339
共有 1 個檔案被更改,包括 20 行新增7 行删除
  1. 20
    7
      modules/UI/ring_overlay/RingOverlay.js

+ 20
- 7
modules/UI/ring_overlay/RingOverlay.js 查看文件

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

Loading…
取消
儲存