From dc8ae18dafe5b20e9838ddf65098c3c3012f3a71 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Wed, 14 Nov 2018 21:38:04 +0100 Subject: [PATCH] Rewrite the jQuery parts to not require this library jQuery is a quite heavy library for the very few places it was used in this library. --- strophe.jinglejs.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/strophe.jinglejs.js b/strophe.jinglejs.js index f156654..337ae3b 100644 --- a/strophe.jinglejs.js +++ b/strophe.jinglejs.js @@ -12,7 +12,7 @@ jxt.use(require('jxt-xmpp')); var IqStanza = jxt.getDefinition('iq', 'jabber:client'); -(function($) { +(function() { Strophe.addConnectionPlugin('jingle', { connection: null, peer_constraints: {}, @@ -71,15 +71,17 @@ var IqStanza = jxt.getDefinition('iq', 'jabber:client'); 'log:error': 'error.jingle' }; - $.each(events, function(key, val) { + Object.entries(events).forEach(function(key, val) { self.manager.on(key, function() { - $(document).trigger(val, arguments); + var evt = new CustomEvent(val, arguments); + document.dispatchEvent(evt); }); }); self.manager.on('incoming', function(session) { session.on('change:connectionState', function(session, state) { - $(document).trigger('iceconnectionstatechange.jingle', [session.sid, session, state]); + var evt = new CustomEvent('iceconnectionstatechange.jingle', [session.sid, session, state]); + document.dispatchEvent(evt); }); }); @@ -116,7 +118,7 @@ var IqStanza = jxt.getDefinition('iq', 'jabber:client'); iq.id = self.connection.getUniqueId('sendIQ'); } - self.connection.send($.parseXML(iq.toString()).getElementsByTagName('iq')[0]); + self.connection.send((new DOMParser()).parseFromString(iq.toString(), 'text/xml').getElementsByTagName('iq')[0]); }); //@TODO add on client unavilable (this.manager.endPeerSessions(peer_jid_full, true)) @@ -132,7 +134,8 @@ var IqStanza = jxt.getDefinition('iq', 'jabber:client'); var session = this.manager.createMediaSession(peerjid); session.on('change:connectionState', function(session, state) { - $(document).trigger('iceconnectionstatechange.jingle', [session.sid, session, state]); + var evt = new CustomEvent('iceconnectionstatechange.jingle', [session.sid, session, state]); + document.dispatchEvent(evt); }); if (stream) { @@ -169,4 +172,4 @@ var IqStanza = jxt.getDefinition('iq', 'jabber:client'); this.manager.config.peerConnectionConstraints = constraints; } }); -}(jQuery)); +}());