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,7 +90,7 @@ export default class ChatRoom extends Listenable {
90 90
 
91 91
     /**
92 92
      *
93
-     * @param connection
93
+     * @param {XmppConnection} connection - The XMPP connection instance.
94 94
      * @param jid
95 95
      * @param password
96 96
      * @param XMPP
@@ -252,7 +252,7 @@ export default class ChatRoom extends Listenable {
252 252
         // unavailable presence in order to attempt to have it sent as soon as
253 253
         // possible.
254 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 256
         this.connection.send(pres);
257 257
         this.connection.flush();
258 258
     }

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

@@ -98,8 +98,7 @@ export default class JingleSessionPC extends JingleSession {
98 98
      * identifies the session
99 99
      * @param {string} localJid our JID
100 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 102
      * @param mediaConstraints the media constraints object passed to
104 103
      * createOffer/Answer, as defined by the WebRTC standard
105 104
      * @param iceConfig the ICE servers config object as defined by the WebRTC

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

@@ -65,15 +65,6 @@ export default class XmppConnection {
65 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 69
      * Tells if Websocket is used as the transport for the current XMPP connection. Returns true for Websocket or false
79 70
      * for BOSH.
@@ -92,15 +83,6 @@ export default class XmppConnection {
92 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 87
      * FIXME.
106 88
      *
@@ -128,24 +110,6 @@ export default class XmppConnection {
128 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 114
      * FIXME.
151 115
      *
@@ -176,6 +140,18 @@ export default class XmppConnection {
176 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 156
      * FIXME.
181 157
      *

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

@@ -12,7 +12,7 @@ const logger = getLogger(__filename);
12 12
 /**
13 13
  * MUC connection plugin.
14 14
  */
15
-class MucConnectionPlugin extends ConnectionPluginListenable {
15
+export default class MucConnectionPlugin extends ConnectionPluginListenable {
16 16
     /**
17 17
      *
18 18
      * @param xmpp
@@ -175,11 +175,3 @@ class MucConnectionPlugin extends ConnectionPluginListenable {
175 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,7 +25,7 @@ const logger = getLogger(__filename);
25 25
 /**
26 26
  *
27 27
  */
28
-class JingleConnectionPlugin extends ConnectionPlugin {
28
+export default class JingleConnectionPlugin extends ConnectionPlugin {
29 29
     /**
30 30
      * Creates new <tt>JingleConnectionPlugin</tt>
31 31
      * @param {XMPP} xmpp
@@ -404,15 +404,3 @@ class JingleConnectionPlugin extends ConnectionPlugin {
404 404
 }
405 405
 
406 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,7 +35,7 @@ const PING_TIMESTAMPS_TO_KEEP = 120000 / PING_INTERVAL;
35 35
  *
36 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 40
      * Contructs new object
41 41
      * @param {XMPP} xmpp the xmpp module.
@@ -186,11 +186,3 @@ class PingConnectionPlugin extends ConnectionPlugin {
186 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,7 +1,7 @@
1 1
 /* global $ */
2 2
 
3 3
 import { getLogger } from 'jitsi-meet-logger';
4
-import { $iq, Strophe } from 'strophe.js';
4
+import { $iq } from 'strophe.js';
5 5
 
6 6
 import ConnectionPlugin from './ConnectionPlugin';
7 7
 
@@ -12,7 +12,7 @@ const RAYO_XMLNS = 'urn:xmpp:rayo:1';
12 12
 /**
13 13
  *
14 14
  */
15
-class RayoConnectionPlugin extends ConnectionPlugin {
15
+export default class RayoConnectionPlugin extends ConnectionPlugin {
16 16
     /**
17 17
      *
18 18
      * @param connection
@@ -125,10 +125,3 @@ class RayoConnectionPlugin extends ConnectionPlugin {
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,11 +8,11 @@ import RandomUtil from '../util/RandomUtil';
8 8
 import * as JitsiConnectionErrors from '../../JitsiConnectionErrors';
9 9
 import * as JitsiConnectionEvents from '../../JitsiConnectionEvents';
10 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 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 16
 import initStropheLogger from './strophe.logger';
17 17
 import Listenable from '../util/Listenable';
18 18
 import Caps from './Caps';
@@ -40,6 +40,17 @@ function createConnection(xmpp, token, serviceUrl = '/http-bind') {
40 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 54
 // FIXME: remove once we have a default config template. -saghul
44 55
 /**
45 56
  * A list of ice servers to use by default for P2P.
@@ -80,13 +91,16 @@ export default class XMPP extends Listenable {
80 91
         this.options = options;
81 92
         this.token = token;
82 93
         this.authenticatedUser = false;
83
-        this._initStrophePlugins(this);
84 94
 
85 95
         // FIXME remove deprecated bosh option at some point
86 96
         const serviceUrl = options.serviceUrl || options.bosh;
87 97
 
98
+        initStropheNativePlugins();
99
+
88 100
         this.connection = createConnection(this, token, serviceUrl);
89 101
 
102
+        this._initStrophePlugins();
103
+
90 104
         this.caps = new Caps(this.connection, this.options.clientNode);
91 105
 
92 106
         // Initialize features advertised in disco-info
@@ -593,12 +607,10 @@ export default class XMPP extends Listenable {
593 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