Browse Source

ref(xmpp): pass XmppConnection wrapper to LJM Strophe plugins

All calls to connection.send should go through the wrapper in order to
prevent breaking the connection by calling it in the not connected
state.
release-8443
paweldomas 5 years ago
parent
commit
1da55ed82a

+ 2
- 2
modules/xmpp/ChatRoom.js View File

90
 
90
 
91
     /**
91
     /**
92
      *
92
      *
93
-     * @param connection
93
+     * @param {XmppConnection} connection - The XMPP connection instance.
94
      * @param jid
94
      * @param jid
95
      * @param password
95
      * @param password
96
      * @param XMPP
96
      * @param XMPP
252
         // unavailable presence in order to attempt to have it sent as soon as
252
         // unavailable presence in order to attempt to have it sent as soon as
253
         // possible.
253
         // possible.
254
         // FIXME do not use Strophe.Connection in the ChatRoom directly
254
         // FIXME do not use Strophe.Connection in the ChatRoom directly
255
-        !this.xmpp.connection.isUsingWebSocket && this.connection.flush();
255
+        !this.connection.isUsingWebSocket && this.connection.flush();
256
         this.connection.send(pres);
256
         this.connection.send(pres);
257
         this.connection.flush();
257
         this.connection.flush();
258
     }
258
     }

+ 1
- 2
modules/xmpp/JingleSessionPC.js View File

98
      * identifies the session
98
      * identifies the session
99
      * @param {string} localJid our JID
99
      * @param {string} localJid our JID
100
      * @param {string} remoteJid remote peer JID
100
      * @param {string} remoteJid remote peer JID
101
-     * @param {Strophe.Connection} connection Strophe XMPP connection instance
102
-     * used to send packets.
101
+     * @param {XmppConnection} connection - The XMPP connection instance.
103
      * @param mediaConstraints the media constraints object passed to
102
      * @param mediaConstraints the media constraints object passed to
104
      * createOffer/Answer, as defined by the WebRTC standard
103
      * createOffer/Answer, as defined by the WebRTC standard
105
      * @param iceConfig the ICE servers config object as defined by the WebRTC
104
      * @param iceConfig the ICE servers config object as defined by the WebRTC

+ 12
- 36
modules/xmpp/XmppConnection.js View File

65
         return this._stropheConn.domain;
65
         return this._stropheConn.domain;
66
     }
66
     }
67
 
67
 
68
-    /**
69
-     * FIXME.
70
-     *
71
-     * @returns {*}
72
-     */
73
-    get emuc() {
74
-        return this._stropheConn.emuc;
75
-    }
76
-
77
     /**
68
     /**
78
      * Tells if Websocket is used as the transport for the current XMPP connection. Returns true for Websocket or false
69
      * Tells if Websocket is used as the transport for the current XMPP connection. Returns true for Websocket or false
79
      * for BOSH.
70
      * for BOSH.
92
         return this._stropheConn.jid;
83
         return this._stropheConn.jid;
93
     }
84
     }
94
 
85
 
95
-    /**
96
-     * FIXME.
97
-     *
98
-     * @returns {*}
99
-     */
100
-    get jingle() {
101
-        return this._stropheConn.jingle;
102
-    }
103
-
104
     /**
86
     /**
105
      * FIXME.
87
      * FIXME.
106
      *
88
      *
128
         return this._stropheConn.options;
110
         return this._stropheConn.options;
129
     }
111
     }
130
 
112
 
131
-    /**
132
-     * FIXME.
133
-     *
134
-     * @returns {PingConnectionPlugin}
135
-     */
136
-    get ping() {
137
-        return this._stropheConn.ping;
138
-    }
139
-
140
-    /**
141
-     * FIXME.
142
-     *
143
-     * @returns {*}
144
-     */
145
-    get rayo() {
146
-        return this._stropheConn.rayo;
147
-    }
148
-
149
     /**
113
     /**
150
      * FIXME.
114
      * FIXME.
151
      *
115
      *
176
         this._stropheConn.service = _service;
140
         this._stropheConn.service = _service;
177
     }
141
     }
178
 
142
 
143
+    /**
144
+     * Adds a connection plugin to this instance.
145
+     *
146
+     * @param {string} name - The name of the plugin or rather a key under which it will be stored on this connection
147
+     * instance.
148
+     * @param {ConnectionPluginListenable} plugin - The plugin to add.
149
+     */
150
+    addConnectionPlugin(name, plugin) {
151
+        this[name] = plugin;
152
+        plugin.init(this);
153
+    }
154
+
179
     /**
155
     /**
180
      * FIXME.
156
      * FIXME.
181
      *
157
      *

+ 1
- 9
modules/xmpp/strophe.emuc.js View File

12
 /**
12
 /**
13
  * MUC connection plugin.
13
  * MUC connection plugin.
14
  */
14
  */
15
-class MucConnectionPlugin extends ConnectionPluginListenable {
15
+export default class MucConnectionPlugin extends ConnectionPluginListenable {
16
     /**
16
     /**
17
      *
17
      *
18
      * @param xmpp
18
      * @param xmpp
175
         return true;
175
         return true;
176
     }
176
     }
177
 }
177
 }
178
-
179
-/**
180
- *
181
- * @param XMPP
182
- */
183
-export default function(XMPP) {
184
-    Strophe.addConnectionPlugin('emuc', new MucConnectionPlugin(XMPP));
185
-}

+ 1
- 13
modules/xmpp/strophe.jingle.js View File

25
 /**
25
 /**
26
  *
26
  *
27
  */
27
  */
28
-class JingleConnectionPlugin extends ConnectionPlugin {
28
+export default class JingleConnectionPlugin extends ConnectionPlugin {
29
     /**
29
     /**
30
      * Creates new <tt>JingleConnectionPlugin</tt>
30
      * Creates new <tt>JingleConnectionPlugin</tt>
31
      * @param {XMPP} xmpp
31
      * @param {XMPP} xmpp
404
 }
404
 }
405
 
405
 
406
 /* eslint-enable newline-per-chained-call */
406
 /* eslint-enable newline-per-chained-call */
407
-
408
-/**
409
- *
410
- * @param XMPP
411
- * @param eventEmitter
412
- * @param iceConfig
413
- */
414
-export default function initJingle(XMPP, eventEmitter, iceConfig) {
415
-    Strophe.addConnectionPlugin(
416
-        'jingle',
417
-        new JingleConnectionPlugin(XMPP, eventEmitter, iceConfig));
418
-}

+ 1
- 9
modules/xmpp/strophe.ping.js View File

35
  *
35
  *
36
  * Registers "urn:xmpp:ping" namespace under Strophe.NS.PING.
36
  * Registers "urn:xmpp:ping" namespace under Strophe.NS.PING.
37
  */
37
  */
38
-class PingConnectionPlugin extends ConnectionPlugin {
38
+export default class PingConnectionPlugin extends ConnectionPlugin {
39
     /**
39
     /**
40
      * Contructs new object
40
      * Contructs new object
41
      * @param {XMPP} xmpp the xmpp module.
41
      * @param {XMPP} xmpp the xmpp module.
186
         return Math.max(maxInterval, 0);
186
         return Math.max(maxInterval, 0);
187
     }
187
     }
188
 }
188
 }
189
-
190
-/**
191
- *
192
- * @param xmpp
193
- */
194
-export default function(xmpp) {
195
-    Strophe.addConnectionPlugin('ping', new PingConnectionPlugin(xmpp));
196
-}

+ 2
- 9
modules/xmpp/strophe.rayo.js View File

1
 /* global $ */
1
 /* global $ */
2
 
2
 
3
 import { getLogger } from 'jitsi-meet-logger';
3
 import { getLogger } from 'jitsi-meet-logger';
4
-import { $iq, Strophe } from 'strophe.js';
4
+import { $iq } from 'strophe.js';
5
 
5
 
6
 import ConnectionPlugin from './ConnectionPlugin';
6
 import ConnectionPlugin from './ConnectionPlugin';
7
 
7
 
12
 /**
12
 /**
13
  *
13
  *
14
  */
14
  */
15
-class RayoConnectionPlugin extends ConnectionPlugin {
15
+export default class RayoConnectionPlugin extends ConnectionPlugin {
16
     /**
16
     /**
17
      *
17
      *
18
      * @param connection
18
      * @param connection
125
         });
125
         });
126
     }
126
     }
127
 }
127
 }
128
-
129
-/**
130
- *
131
- */
132
-export default function() {
133
-    Strophe.addConnectionPlugin('rayo', new RayoConnectionPlugin());
134
-}

+ 23
- 11
modules/xmpp/xmpp.js View File

8
 import * as JitsiConnectionErrors from '../../JitsiConnectionErrors';
8
 import * as JitsiConnectionErrors from '../../JitsiConnectionErrors';
9
 import * as JitsiConnectionEvents from '../../JitsiConnectionEvents';
9
 import * as JitsiConnectionEvents from '../../JitsiConnectionEvents';
10
 import browser from '../browser';
10
 import browser from '../browser';
11
-import initEmuc from './strophe.emuc';
12
-import initJingle from './strophe.jingle';
11
+import MucConnectionPlugin from './strophe.emuc';
12
+import JingleConnectionPlugin from './strophe.jingle';
13
 import initStropheUtil from './strophe.util';
13
 import initStropheUtil from './strophe.util';
14
-import initPing from './strophe.ping';
15
-import initRayo from './strophe.rayo';
14
+import PingConnectionPlugin from './strophe.ping';
15
+import RayoConnectionPlugin from './strophe.rayo';
16
 import initStropheLogger from './strophe.logger';
16
 import initStropheLogger from './strophe.logger';
17
 import Listenable from '../util/Listenable';
17
 import Listenable from '../util/Listenable';
18
 import Caps from './Caps';
18
 import Caps from './Caps';
40
     return new XmppConnection(xmpp, serviceUrl);
40
     return new XmppConnection(xmpp, serviceUrl);
41
 }
41
 }
42
 
42
 
43
+/**
44
+ * Initializes Strophe plugins that need to work with Strophe.Connection directly rather than the lib-jitsi-meet's
45
+ * {@link XmppConnection} wrapper.
46
+ *
47
+ * @returns {void}
48
+ */
49
+function initStropheNativePlugins() {
50
+    initStropheUtil();
51
+    initStropheLogger();
52
+}
53
+
43
 // FIXME: remove once we have a default config template. -saghul
54
 // FIXME: remove once we have a default config template. -saghul
44
 /**
55
 /**
45
  * A list of ice servers to use by default for P2P.
56
  * A list of ice servers to use by default for P2P.
80
         this.options = options;
91
         this.options = options;
81
         this.token = token;
92
         this.token = token;
82
         this.authenticatedUser = false;
93
         this.authenticatedUser = false;
83
-        this._initStrophePlugins(this);
84
 
94
 
85
         // FIXME remove deprecated bosh option at some point
95
         // FIXME remove deprecated bosh option at some point
86
         const serviceUrl = options.serviceUrl || options.bosh;
96
         const serviceUrl = options.serviceUrl || options.bosh;
87
 
97
 
98
+        initStropheNativePlugins();
99
+
88
         this.connection = createConnection(this, token, serviceUrl);
100
         this.connection = createConnection(this, token, serviceUrl);
89
 
101
 
102
+        this._initStrophePlugins();
103
+
90
         this.caps = new Caps(this.connection, this.options.clientNode);
104
         this.caps = new Caps(this.connection, this.options.clientNode);
91
 
105
 
92
         // Initialize features advertised in disco-info
106
         // Initialize features advertised in disco-info
593
                 = this.options.p2p.iceTransportPolicy;
607
                 = this.options.p2p.iceTransportPolicy;
594
         }
608
         }
595
 
609
 
596
-        initEmuc(this);
597
-        initJingle(this, this.eventEmitter, iceConfig);
598
-        initStropheUtil();
599
-        initPing(this);
600
-        initRayo();
601
-        initStropheLogger();
610
+        this.connection.addConnectionPlugin('emuc', new MucConnectionPlugin(this));
611
+        this.connection.addConnectionPlugin('jingle', new JingleConnectionPlugin(this, this.eventEmitter, iceConfig));
612
+        this.connection.addConnectionPlugin('ping', new PingConnectionPlugin(this));
613
+        this.connection.addConnectionPlugin('rayo', new RayoConnectionPlugin());
602
     }
614
     }
603
 
615
 
604
     /**
616
     /**

Loading…
Cancel
Save