Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite the jQuery parts to not require this library #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 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,19 @@ var IqStanza = jxt.getDefinition('iq', 'jabber:client');
'log:error': 'error.jingle'
};

$.each(events, function(key, val) {
Object.entries(events).forEach(function(item) {
var key = item[0];
var val = item[1];
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]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to MDN the second parameter has to be a dictionary with a key detail.

It's not compatible with Safari, but I think this is ok, because they not even support WebRTC. Maybe we should handle this case more gracefully.

Anyway this would be a breaking change, because it's not compatible with the previous jquery. Maybe we can use this as fallback if jquery is not available. What do you think?

document.dispatchEvent(evt);
});
});

Expand Down Expand Up @@ -116,7 +120,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]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should split this line to make it more readable

});

//@TODO add on client unavilable (this.manager.endPeerSessions(peer_jid_full, true))
Expand All @@ -132,7 +136,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 +174,4 @@ var IqStanza = jxt.getDefinition('iq', 'jabber:client');
this.manager.config.peerConnectionConstraints = constraints;
}
});
}(jQuery));
}());