Sfoglia il codice sorgente

Handles transport-replace message

dev1
paweldomas 9 anni fa
parent
commit
9393018041
2 ha cambiato i file con 99 aggiunte e 0 eliminazioni
  1. 85
    0
      modules/xmpp/JingleSessionPC.js
  2. 14
    0
      modules/xmpp/strophe.jingle.js

+ 85
- 0
modules/xmpp/JingleSessionPC.js Vedi File

@@ -425,6 +425,26 @@ JingleSessionPC.prototype.setLocalDescription = function (sdp, success,
425 425
     }
426 426
 };
427 427
 
428
+/**
429
+ * Although it states "replace transport" it does accept full Jingle offer
430
+ * which should contain new ICE transport details.
431
+ * @param jingleOfferElem an element Jingle IQ that contains new offer and
432
+ *        transport info.
433
+ * @param success callback called when we succeed to accept new offer.
434
+ * @param failure function(error) called when we fail to accept new offer.
435
+ */
436
+JingleSessionPC.prototype.replaceTransport = function (jingleOfferElem,
437
+                                                       success,
438
+                                                       failure) {
439
+    // Set offer as RD
440
+    this.setOfferCycle(jingleOfferElem,
441
+        function () {
442
+            // Set local description OK, now localSDP up to date
443
+            this.sendTransportAccept(this.localSDP, success, failure);
444
+        }.bind(this),
445
+        failure);
446
+};
447
+
428 448
 /**
429 449
  * Sends Jingle 'session-accept' message.
430 450
  * @param localSDP the 'SDP' object with local session description
@@ -464,6 +484,71 @@ JingleSessionPC.prototype.sendSessionAccept = function (localSDP,
464 484
         IQ_TIMEOUT);
465 485
 };
466 486
 
487
+/**
488
+ * Sends Jingle 'transport-accept' message which is a response to
489
+ * 'transport-replace'.
490
+ * @param localSDP the 'SDP' object with local session description
491
+ * @param success callback called when we receive 'RESULT' packet for
492
+ *        'transport-replace'
493
+ * @param failure function(error) called when we receive an error response or
494
+ *        when the request has timed out.
495
+ */
496
+JingleSessionPC.prototype.sendTransportAccept = function(localSDP, success,
497
+                                                         failure) {
498
+    var self = this;
499
+    var tAccept = $iq({to: this.peerjid, type: 'set'})
500
+        .c('jingle', {xmlns: 'urn:xmpp:jingle:1',
501
+            action: 'transport-accept',
502
+            initiator: this.initiator,
503
+            sid: this.sid});
504
+
505
+    localSDP.media.forEach(function(medialines, idx){
506
+        var mline = SDPUtil.parse_mline(medialines.split('\r\n')[0]);
507
+        tAccept.c('content',
508
+            { creator: self.initiator == self.me ? 'initiator' : 'responder',
509
+              name: mline.media
510
+            }
511
+        );
512
+        localSDP.transportToJingle(idx, tAccept);
513
+        tAccept.up();
514
+    });
515
+
516
+    // Calling tree() to print something useful to the logger
517
+    tAccept = tAccept.tree();
518
+    console.info("Sending transport-accept: ", tAccept);
519
+
520
+    self.connection.sendIQ(tAccept,
521
+        success,
522
+        self.newJingleErrorHandler(tAccept, failure),
523
+        IQ_TIMEOUT);
524
+};
525
+
526
+/**
527
+ * Sends Jingle 'transport-reject' message which is a response to
528
+ * 'transport-replace'.
529
+ * @param success callback called when we receive 'RESULT' packet for
530
+ *        'transport-replace'
531
+ * @param failure function(error) called when we receive an error response or
532
+ *        when the request has timed out.
533
+ */
534
+JingleSessionPC.prototype.sendTransportReject = function(success, failure) {
535
+    // Send 'transport-reject', so that the focus will
536
+    // know that we've failed
537
+    var tReject = $iq({to: this.peerjid, type: 'set'})
538
+        .c('jingle', {xmlns: 'urn:xmpp:jingle:1',
539
+            action: 'transport-reject',
540
+            initiator: this.initiator,
541
+            sid: this.sid});
542
+
543
+    tReject = tReject.tree();
544
+    logger.info("Sending 'transport-reject", tReject);
545
+
546
+    this.connection.sendIQ(tReject,
547
+        success,
548
+        this.newJingleErrorHandler(tReject, failure),
549
+        IQ_TIMEOUT);
550
+};
551
+
467 552
 JingleSessionPC.prototype.terminate = function (reason,  text,
468 553
                                                 success, failure) {
469 554
     var term = $iq({to: this.peerjid,

+ 14
- 0
modules/xmpp/strophe.jingle.js Vedi File

@@ -139,6 +139,20 @@ module.exports = function(XMPP, eventEmitter) {
139 139
                     }
140 140
                     this.terminate(sess.sid, reasonCondition, reasonText);
141 141
                     break;
142
+                case 'transport-replace':
143
+                    logger.info("(TIME) Start transport replace",
144
+                                window.performance.now());
145
+                    sess.replaceTransport($(iq).find('>jingle'),
146
+                        function () {
147
+                            logger.info(
148
+                                "(TIME) Transport replace success!",
149
+                                window.performance.now());
150
+                        },
151
+                        function(error) {
152
+                            logger.error('Transport replace failed', error);
153
+                            sess.sendTransportReject();
154
+                        });
155
+                    break;
142 156
                 case 'addsource': // FIXME: proprietary, un-jingleish
143 157
                 case 'source-add': // FIXME: proprietary
144 158
                     sess.addSource($(iq).find('>jingle>content'));

Loading…
Annulla
Salva