Kaynağa Gözat

Continues to separate JingleSessionPC.

master
Boris Grozev 10 yıl önce
ebeveyn
işleme
f52b1380ee

+ 118
- 2
modules/xmpp/JingleSession.js Dosyayı Görüntüle

@@ -3,9 +3,125 @@
3 3
  * have different implementations depending on the underlying interface used
4 4
  * (i.e. WebRTC and ORTC) and here we hold the code common to all of them.
5 5
  */
6
-function JingleSession() {
7
-    // dripping is sending trickle candidates not one-by-one
6
+function JingleSession(me, sid, connection, service, eventEmitter) {
7
+    /**
8
+     * Our JID.
9
+     */
10
+    this.me = me;
11
+
12
+    /**
13
+     * The Jingle session identifier.
14
+     */
15
+    this.sid = sid;
16
+
17
+    /**
18
+     * The XMPP connection.
19
+     */
20
+    this.connection = connection;
21
+
22
+    /**
23
+     * The XMPP service.
24
+     */
25
+    this.service = service;
26
+
27
+    /**
28
+     * The event emitter.
29
+     */
30
+    this.eventEmitter = eventEmitter;
31
+
32
+    /**
33
+     * Whether to use dripping or not. Dripping is sending trickle candidates
34
+     * not one-by-one.
35
+     * Note: currently we do not support 'false'.
36
+     */
8 37
     this.usedrip = true;
38
+
39
+    /**
40
+     *  When dripping is used, stores ICE candidates which are to be sent.
41
+     */
42
+    this.drip_container = [];
43
+
44
+    // Media constraints. Is this WebRTC only?
45
+    this.media_constraints = null;
46
+
47
+    // ICE servers config (RTCConfiguration?).
48
+    this.ice_config = {};
9 49
 }
10 50
 
51
+/**
52
+ * Prepares this object to initiate a session.
53
+ * @param peerjid the JID of the remote peer.
54
+ * @param isInitiator whether we will be the Jingle initiator.
55
+ * @param media_constraints
56
+ * @param ice_config
57
+ */
58
+JingleSession.prototype.initialize = function(peerjid, isInitiator,
59
+                                              media_constraints, ice_config) {
60
+    this.media_constraints = media_constraints;
61
+    this.ice_config = ice_config;
62
+
63
+    if (this.state !== null) {
64
+        console.error('attempt to initiate on session ' + this.sid +
65
+        'in state ' + this.state);
66
+        return;
67
+    }
68
+    this.state = 'pending';
69
+    this.initiator = isInitiator ? this.me : peerjid;
70
+    this.responder = !isInitiator ? this.me : peerjid;
71
+    this.peerjid = peerjid;
72
+
73
+    this.doInitialize();
74
+};
75
+
76
+/**
77
+ * Finishes initialization.
78
+ */
79
+JingleSession.prototype.doInitialize = function() {};
80
+
81
+/**
82
+ * Adds the ICE candidates found in the 'contents' array as remote candidates?
83
+ * Note: currently only used on transport-info
84
+ */
85
+JingleSession.prototype.addIceCandidates = function(contents) {};
86
+
87
+/**
88
+ * Handles an 'add-source' event.
89
+ *
90
+ * @param contents an array of Jingle 'content' elements.
91
+ */
92
+JingleSession.prototype.addSources = function(contents) {};
93
+
94
+/**
95
+ * Handles a 'remove-source' event.
96
+ *
97
+ * @param contents an array of Jingle 'content' elements.
98
+ */
99
+JingleSession.prototype.removeSources = function(contents) {};
100
+
101
+/**
102
+ * Terminates this Jingle session (stops sending media and closes the streams?)
103
+ */
104
+JingleSession.prototype.terminate = function() {};
105
+
106
+/**
107
+ * Sends a Jingle session-terminate message to the peer and terminates the
108
+ * session.
109
+ * @param reason
110
+ * @param text
111
+ */
112
+JingleSession.prototype.sendTerminate = function(reason, text) {};
113
+
114
+/**
115
+ * Handles an offer from the remote peer (prepares to accept a session).
116
+ * @param jingle the 'jingle' XML element.
117
+ */
118
+JingleSession.prototype.setOffer = function(jingle) {};
119
+
120
+/**
121
+ * Handles an answer from the remote peer (prepares to accept a session).
122
+ * @param jingle the 'jingle' XML element.
123
+ */
124
+JingleSession.prototype.setAnswer = function(jingle) {};
125
+
126
+
11 127
 module.exports = JingleSession;

+ 3
- 26
modules/xmpp/JingleSessionPC.js Dosyayı Görüntüle

@@ -13,25 +13,14 @@ var SSRCReplacement = require("./LocalSSRCReplacement");
13 13
 // Jingle stuff
14 14
 function JingleSessionPC(me, sid, connection, service, eventEmitter) {
15 15
     JingleSession.call(this, me, sid, connection, service, eventEmitter);
16
-    this.me = me;
17
-    this.sid = sid;
18
-    this.connection = connection;
19 16
     this.initiator = null;
20 17
     this.responder = null;
21
-    this.isInitiator = null;
22 18
     this.peerjid = null;
23 19
     this.state = null;
24 20
     this.localSDP = null;
25 21
     this.remoteSDP = null;
26 22
     this.relayedStreams = [];
27
-    this.startTime = null;
28
-    this.stopTime = null;
29
-    this.media_constraints = null;
30 23
     this.pc_constraints = null;
31
-    this.ice_config = {};
32
-    this.drip_container = [];
33
-    this.service = service;
34
-    this.eventEmitter = eventEmitter;
35 24
 
36 25
     this.usetrickle = true;
37 26
     this.usepranswer = false; // early transport warmup -- mind you, this might fail. depends on webrtc issue 1718
@@ -88,25 +77,15 @@ JingleSessionPC.prototype.updateModifySourcesQueue = function() {
88 77
     }
89 78
 };
90 79
 
91
-JingleSessionPC.prototype.initiate = function (peerjid, isInitiator) {
80
+JingleSessionPC.prototype.doInitialize = function () {
92 81
     var self = this;
93
-    if (this.state !== null) {
94
-        console.error('attempt to initiate on session ' + this.sid +
95
-            'in state ' + this.state);
96
-        return;
97
-    }
98
-    this.isInitiator = isInitiator;
99
-    this.state = 'pending';
100
-    this.initiator = isInitiator ? this.me : peerjid;
101
-    this.responder = !isInitiator ? this.me : peerjid;
102
-    this.peerjid = peerjid;
82
+
103 83
     this.hadstuncandidate = false;
104 84
     this.hadturncandidate = false;
105 85
     this.lasticecandidate = false;
106 86
     this.isreconnect = false;
107 87
 
108
-    this.peerconnection
109
-        = new TraceablePeerConnection(
88
+    this.peerconnection = new TraceablePeerConnection(
110 89
             this.connection.jingle.ice_config,
111 90
             this.connection.jingle.pc_constraints,
112 91
             this);
@@ -147,7 +126,6 @@ JingleSessionPC.prototype.initiate = function (peerjid, isInitiator) {
147 126
         self.updateModifySourcesQueue();
148 127
         switch (self.peerconnection.iceConnectionState) {
149 128
             case 'connected':
150
-                self.startTime = new Date();
151 129
 
152 130
                 // Informs interested parties that the connection has been restored.
153 131
                 if (self.peerconnection.signalingState === 'stable' && self.isreconnect)
@@ -157,7 +135,6 @@ JingleSessionPC.prototype.initiate = function (peerjid, isInitiator) {
157 135
                 break;
158 136
             case 'disconnected':
159 137
                 self.isreconnect = true;
160
-                self.stopTime = new Date();
161 138
                 // Informs interested parties that the connection has been interrupted.
162 139
                 if (self.peerconnection.signalingState === 'stable')
163 140
                     self.eventEmitter.emit(XMPPEvents.CONNECTION_INTERRUPTED);

+ 2
- 2
modules/xmpp/strophe.jingle.js Dosyayı Görüntüle

@@ -110,7 +110,7 @@ module.exports = function(XMPP, eventEmitter) {
110 110
                     sess.pc_constraints = this.pc_constraints;
111 111
                     sess.ice_config = this.ice_config;
112 112
 
113
-                    sess.initiate(fromJid, false);
113
+                    sess.initialize(fromJid, false);
114 114
                     // FIXME: setRemoteDescription should only be done when this call is to be accepted
115 115
                     sess.setOffer($(iq).find('>jingle'));
116 116
 
@@ -200,7 +200,7 @@ module.exports = function(XMPP, eventEmitter) {
200 200
             sess.pc_constraints = this.pc_constraints;
201 201
             sess.ice_config = this.ice_config;
202 202
 
203
-            sess.initiate(peerjid, true);
203
+            sess.initialize(peerjid, true);
204 204
             this.sessions[sess.sid] = sess;
205 205
             this.jid2session[sess.peerjid] = sess;
206 206
             sess.sendOffer();

Loading…
İptal
Kaydet