浏览代码

chore: remove usage of `self`

This has become obsolete thanks to ES6 arrow functions
master
Philipp Hancke 5 年前
父节点
当前提交
509740734b
共有 4 个文件被更改,包括 38 次插入49 次删除
  1. 3
    6
      modules/statistics/LocalStatsCollector.js
  2. 15
    17
      modules/statistics/RTPStatsCollector.js
  3. 2
    4
      modules/xmpp/ChatRoom.js
  4. 18
    22
      modules/xmpp/SDP.js

+ 3
- 6
modules/statistics/LocalStatsCollector.js 查看文件

107
 
107
 
108
     source.connect(analyser);
108
     source.connect(analyser);
109
 
109
 
110
-
111
-    const self = this;
112
-
113
     this.intervalId = setInterval(
110
     this.intervalId = setInterval(
114
         () => {
111
         () => {
115
             const array = new Uint8Array(analyser.frequencyBinCount);
112
             const array = new Uint8Array(analyser.frequencyBinCount);
117
             analyser.getByteTimeDomainData(array);
114
             analyser.getByteTimeDomainData(array);
118
             const audioLevel = timeDomainDataToAudioLevel(array);
115
             const audioLevel = timeDomainDataToAudioLevel(array);
119
 
116
 
120
-            if (audioLevel !== self.audioLevel) {
121
-                self.audioLevel = animateLevel(audioLevel, self.audioLevel);
122
-                self.callback(self.audioLevel);
117
+            if (audioLevel !== this.audioLevel) {
118
+                this.audioLevel = animateLevel(audioLevel, this.audioLevel);
119
+                this.callback(this.audioLevel);
123
             }
120
             }
124
         },
121
         },
125
         this.intervalMilis
122
         this.intervalMilis

+ 15
- 17
modules/statistics/RTPStatsCollector.js 查看文件

290
  * Starts stats updates.
290
  * Starts stats updates.
291
  */
291
  */
292
 StatsCollector.prototype.start = function(startAudioLevelStats) {
292
 StatsCollector.prototype.start = function(startAudioLevelStats) {
293
-    const self = this;
294
-
295
     if (startAudioLevelStats) {
293
     if (startAudioLevelStats) {
296
         this.audioLevelsIntervalId = setInterval(
294
         this.audioLevelsIntervalId = setInterval(
297
             () => {
295
             () => {
298
                 // Interval updates
296
                 // Interval updates
299
-                self.peerconnection.getStats(
297
+                this.peerconnection.getStats(
300
                     report => {
298
                     report => {
301
                         let results = null;
299
                         let results = null;
302
 
300
 
306
                         } else {
304
                         } else {
307
                             results = report.result();
305
                             results = report.result();
308
                         }
306
                         }
309
-                        self.currentAudioLevelsReport = results;
307
+                        this.currentAudioLevelsReport = results;
310
                         if (this._usesPromiseGetStats) {
308
                         if (this._usesPromiseGetStats) {
311
-                            self.processNewAudioLevelReport();
309
+                            this.processNewAudioLevelReport();
312
                         } else {
310
                         } else {
313
-                            self.processAudioLevelReport();
311
+                            this.processAudioLevelReport();
314
                         }
312
                         }
315
 
313
 
316
-                        self.baselineAudioLevelsReport
317
-                            = self.currentAudioLevelsReport;
314
+                        this.baselineAudioLevelsReport
315
+                            = this.currentAudioLevelsReport;
318
                     },
316
                     },
319
-                    error => self.errorCallback(error)
317
+                    error => this.errorCallback(error)
320
                 );
318
                 );
321
             },
319
             },
322
-            self.audioLevelsIntervalMilis
320
+            this.audioLevelsIntervalMilis
323
         );
321
         );
324
     }
322
     }
325
 
323
 
326
     this.statsIntervalId = setInterval(
324
     this.statsIntervalId = setInterval(
327
         () => {
325
         () => {
328
             // Interval updates
326
             // Interval updates
329
-            self.peerconnection.getStats(
327
+            this.peerconnection.getStats(
330
                 report => {
328
                 report => {
331
                     let results = null;
329
                     let results = null;
332
 
330
 
339
                         results = report.result();
337
                         results = report.result();
340
                     }
338
                     }
341
 
339
 
342
-                    self.currentStatsReport = results;
340
+                    this.currentStatsReport = results;
343
                     try {
341
                     try {
344
                         if (this._usesPromiseGetStats) {
342
                         if (this._usesPromiseGetStats) {
345
-                            self.processNewStatsReport();
343
+                            this.processNewStatsReport();
346
                         } else {
344
                         } else {
347
-                            self.processStatsReport();
345
+                            this.processStatsReport();
348
                         }
346
                         }
349
                     } catch (e) {
347
                     } catch (e) {
350
                         GlobalOnErrorHandler.callErrorHandler(e);
348
                         GlobalOnErrorHandler.callErrorHandler(e);
351
                         logger.error(`Unsupported key:${e}`, e);
349
                         logger.error(`Unsupported key:${e}`, e);
352
                     }
350
                     }
353
 
351
 
354
-                    self.previousStatsReport = self.currentStatsReport;
352
+                    this.previousStatsReport = this.currentStatsReport;
355
                 },
353
                 },
356
-                error => self.errorCallback(error)
354
+                error => this.errorCallback(error)
357
             );
355
             );
358
         },
356
         },
359
-        self.statsIntervalMilis
357
+        this.statsIntervalMilis
360
     );
358
     );
361
 };
359
 };
362
 
360
 

+ 2
- 4
modules/xmpp/ChatRoom.js 查看文件

328
             .c('x', { xmlns: 'jabber:x:data',
328
             .c('x', { xmlns: 'jabber:x:data',
329
                 type: 'submit' });
329
                 type: 'submit' });
330
 
330
 
331
-        const self = this;
332
-
333
         this.connection.sendIQ(getForm, form => {
331
         this.connection.sendIQ(getForm, form => {
334
             if (!$(form).find(
332
             if (!$(form).find(
335
                     '>query>x[xmlns="jabber:x:data"]'
333
                     '>query>x[xmlns="jabber:x:data"]'
342
                 return;
340
                 return;
343
             }
341
             }
344
 
342
 
345
-            const formSubmit = $iq({ to: self.roomjid,
343
+            const formSubmit = $iq({ to: this.roomjid,
346
                 type: 'set' })
344
                 type: 'set' })
347
                 .c('query', { xmlns: 'http://jabber.org/protocol/muc#owner' });
345
                 .c('query', { xmlns: 'http://jabber.org/protocol/muc#owner' });
348
 
346
 
356
             formSubmit.c('field', { 'var': 'muc#roomconfig_whois' })
354
             formSubmit.c('field', { 'var': 'muc#roomconfig_whois' })
357
                 .c('value').t('anyone').up().up();
355
                 .c('value').t('anyone').up().up();
358
 
356
 
359
-            self.connection.sendIQ(formSubmit);
357
+            this.connection.sendIQ(formSubmit);
360
 
358
 
361
         }, error => {
359
         }, error => {
362
             GlobalOnErrorHandler.callErrorHandler(error);
360
             GlobalOnErrorHandler.callErrorHandler(error);

+ 18
- 22
modules/xmpp/SDP.js 查看文件

49
  * Returns map of MediaChannel mapped per channel idx.
49
  * Returns map of MediaChannel mapped per channel idx.
50
  */
50
  */
51
 SDP.prototype.getMediaSsrcMap = function() {
51
 SDP.prototype.getMediaSsrcMap = function() {
52
-    const self = this;
53
     const mediaSSRCs = {};
52
     const mediaSSRCs = {};
54
     let tmp;
53
     let tmp;
55
 
54
 
56
-    for (let mediaindex = 0; mediaindex < self.media.length; mediaindex++) {
57
-        tmp = SDPUtil.findLines(self.media[mediaindex], 'a=ssrc:');
55
+    for (let mediaindex = 0; mediaindex < this.media.length; mediaindex++) {
56
+        tmp = SDPUtil.findLines(this.media[mediaindex], 'a=ssrc:');
58
         const mid
57
         const mid
59
             = SDPUtil.parseMID(
58
             = SDPUtil.parseMID(
60
-                SDPUtil.findLine(self.media[mediaindex], 'a=mid:'));
59
+                SDPUtil.findLine(this.media[mediaindex], 'a=mid:'));
61
         const media = {
60
         const media = {
62
             mediaindex,
61
             mediaindex,
63
             mid,
62
             mid,
79
             }
78
             }
80
             media.ssrcs[linessrc].lines.push(line);
79
             media.ssrcs[linessrc].lines.push(line);
81
         });
80
         });
82
-        tmp = SDPUtil.findLines(self.media[mediaindex], 'a=ssrc-group:');
81
+        tmp = SDPUtil.findLines(this.media[mediaindex], 'a=ssrc-group:');
83
         tmp.forEach(line => {
82
         tmp.forEach(line => {
84
             const idx = line.indexOf(' ');
83
             const idx = line.indexOf(' ');
85
             const semantics = line.substr(0, idx).substr(13);
84
             const semantics = line.substr(0, idx).substr(13);
395
 
394
 
396
 SDP.prototype.transportToJingle = function(mediaindex, elem) {
395
 SDP.prototype.transportToJingle = function(mediaindex, elem) {
397
     let tmp;
396
     let tmp;
398
-    const self = this;
399
 
397
 
400
     elem.c('transport');
398
     elem.c('transport');
401
 
399
 
402
     // XEP-0343 DTLS/SCTP
400
     // XEP-0343 DTLS/SCTP
403
     const sctpmap
401
     const sctpmap
404
-        = SDPUtil.findLine(this.media[mediaindex], 'a=sctpmap:', self.session);
402
+        = SDPUtil.findLine(this.media[mediaindex], 'a=sctpmap:', this.session);
405
 
403
 
406
     if (sctpmap) {
404
     if (sctpmap) {
407
         const sctpAttrs = SDPUtil.parseSCTPMap(sctpmap);
405
         const sctpAttrs = SDPUtil.parseSCTPMap(sctpmap);
435
         // eslint-disable-next-line no-param-reassign
433
         // eslint-disable-next-line no-param-reassign
436
         line
434
         line
437
             = SDPUtil.findLine(
435
             = SDPUtil.findLine(
438
-                self.media[mediaindex],
436
+                this.media[mediaindex],
439
                 'a=setup:',
437
                 'a=setup:',
440
-                self.session);
438
+                this.session);
441
         if (line) {
439
         if (line) {
442
             tmp.setup = line.substr(8);
440
             tmp.setup = line.substr(8);
443
         }
441
         }
460
             lines.forEach(line => {
458
             lines.forEach(line => {
461
                 const candidate = SDPUtil.candidateToJingle(line);
459
                 const candidate = SDPUtil.candidateToJingle(line);
462
 
460
 
463
-                if (self.failICE) {
461
+                if (this.failICE) {
464
                     candidate.ip = '1.1.1.1';
462
                     candidate.ip = '1.1.1.1';
465
                 }
463
                 }
466
                 const protocol
464
                 const protocol
468
                         ? candidate.protocol.toLowerCase()
466
                         ? candidate.protocol.toLowerCase()
469
                         : '';
467
                         : '';
470
 
468
 
471
-                if ((self.removeTcpCandidates
469
+                if ((this.removeTcpCandidates
472
                         && (protocol === 'tcp' || protocol === 'ssltcp'))
470
                         && (protocol === 'tcp' || protocol === 'ssltcp'))
473
-                    || (self.removeUdpCandidates && protocol === 'udp')) {
471
+                    || (this.removeUdpCandidates && protocol === 'udp')) {
474
                     return;
472
                     return;
475
                 }
473
                 }
476
                 elem.c('candidate', candidate).up();
474
                 elem.c('candidate', candidate).up();
538
 
536
 
539
 // construct an SDP from a jingle stanza
537
 // construct an SDP from a jingle stanza
540
 SDP.prototype.fromJingle = function(jingle) {
538
 SDP.prototype.fromJingle = function(jingle) {
541
-    const self = this;
542
     const sessionId = Date.now();
539
     const sessionId = Date.now();
543
 
540
 
544
     // Use a unique session id for every TPC.
541
     // Use a unique session id for every TPC.
561
                     .get();
558
                     .get();
562
 
559
 
563
             if (contents.length > 0) {
560
             if (contents.length > 0) {
564
-                self.raw
561
+                this.raw
565
                     += `a=group:${
562
                     += `a=group:${
566
                         group.getAttribute('semantics')
563
                         group.getAttribute('semantics')
567
                             || group.getAttribute('type')} ${
564
                             || group.getAttribute('type')} ${
572
 
569
 
573
     this.session = this.raw;
570
     this.session = this.raw;
574
     jingle.find('>content').each((_, content) => {
571
     jingle.find('>content').each((_, content) => {
575
-        const m = self.jingle2media($(content));
572
+        const m = this.jingle2media($(content));
576
 
573
 
577
-        self.media.push(m);
574
+        this.media.push(m);
578
     });
575
     });
579
 
576
 
580
     // reconstruct msid-semantic -- apparently not necessary
577
     // reconstruct msid-semantic -- apparently not necessary
592
 SDP.prototype.jingle2media = function(content) {
589
 SDP.prototype.jingle2media = function(content) {
593
     const desc = content.find('description');
590
     const desc = content.find('description');
594
     let media = '';
591
     let media = '';
595
-    const self = this;
596
     const sctp = content.find(
592
     const sctp = content.find(
597
         '>transport>sctpmap[xmlns="urn:xmpp:jingle:transports:dtls-sctp:1"]');
593
         '>transport>sctpmap[xmlns="urn:xmpp:jingle:transports:dtls-sctp:1"]');
598
 
594
 
709
         }
705
         }
710
 
706
 
711
         // xep-0293
707
         // xep-0293
712
-        media += self.rtcpFbFromJingle($(payloadType), payloadType.getAttribute('id'));
708
+        media += this.rtcpFbFromJingle($(payloadType), payloadType.getAttribute('id'));
713
     });
709
     });
714
 
710
 
715
     // xep-0293
711
     // xep-0293
716
-    media += self.rtcpFbFromJingle(desc, '*');
712
+    media += this.rtcpFbFromJingle(desc, '*');
717
 
713
 
718
     // xep-0294
714
     // xep-0294
719
     tmp
715
     tmp
735
             protocol
731
             protocol
736
                 = typeof protocol === 'string' ? protocol.toLowerCase() : '';
732
                 = typeof protocol === 'string' ? protocol.toLowerCase() : '';
737
 
733
 
738
-            if ((self.removeTcpCandidates
734
+            if ((this.removeTcpCandidates
739
                     && (protocol === 'tcp' || protocol === 'ssltcp'))
735
                     && (protocol === 'tcp' || protocol === 'ssltcp'))
740
-                || (self.removeUdpCandidates && protocol === 'udp')) {
736
+                || (this.removeUdpCandidates && protocol === 'udp')) {
741
                 return;
737
                 return;
742
-            } else if (self.failICE) {
738
+            } else if (this.failICE) {
743
                 transport.setAttribute('ip', '1.1.1.1');
739
                 transport.setAttribute('ip', '1.1.1.1');
744
             }
740
             }
745
 
741
 

正在加载...
取消
保存