Bläddra i källkod

Continues to separate JingleSessionPC.

master
Boris Grozev 10 år sedan
förälder
incheckning
f52b1380ee
3 ändrade filer med 123 tillägg och 30 borttagningar
  1. 118
    2
      modules/xmpp/JingleSession.js
  2. 3
    26
      modules/xmpp/JingleSessionPC.js
  3. 2
    2
      modules/xmpp/strophe.jingle.js

+ 118
- 2
modules/xmpp/JingleSession.js Visa fil

3
  * have different implementations depending on the underlying interface used
3
  * have different implementations depending on the underlying interface used
4
  * (i.e. WebRTC and ORTC) and here we hold the code common to all of them.
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
     this.usedrip = true;
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
 module.exports = JingleSession;
127
 module.exports = JingleSession;

+ 3
- 26
modules/xmpp/JingleSessionPC.js Visa fil

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

+ 2
- 2
modules/xmpp/strophe.jingle.js Visa fil

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

Laddar…
Avbryt
Spara