Skip to content

Commit

Permalink
Rewrite the jQuery parts to not require this library
Browse files Browse the repository at this point in the history
jQuery is a quite heavy library for the very few places it was used in
this library.
  • Loading branch information
linkmauve committed Nov 29, 2018
1 parent 3c59855 commit dc8ae18
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions strophe.jinglejs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {},
Expand Down Expand Up @@ -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);
});
});

Expand Down Expand Up @@ -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))
Expand All @@ -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) {
Expand Down Expand Up @@ -169,4 +172,4 @@ var IqStanza = jxt.getDefinition('iq', 'jabber:client');
this.manager.config.peerConnectionConstraints = constraints;
}
});
}(jQuery));
}());

0 comments on commit dc8ae18

Please sign in to comment.