Skip to content

Commit

Permalink
client: session-establishment (#369)
Browse files Browse the repository at this point in the history
  • Loading branch information
sonnyp committed Feb 22, 2017
1 parent ee57b93 commit f42dfd9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/client/lib/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
'tcp',
'reconnect',
'starttls',
'session-establishment',
].forEach((pkg) => {
module.exports[pkg] = require('@xmpp/plugins/' + pkg)
})
36 changes: 36 additions & 0 deletions packages/plugins/session-establishment/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use strict'

const xml = require('@xmpp/xml')
const streamfeatures = require('../stream-features')
const iqCaller = require('../iq-caller')

/*
* References
* https://tools.ietf.org/html/draft-cridland-xmpp-session-01
*/

const NS = 'urn:ietf:params:xml:ns:xmpp-session'

function match (features) {
const session = features.getChild('session', NS)
return session && !session.getChild('optional')
}

module.exports.name = 'session-establishment'
module.exports.plugin = function plugin (entity) {
const caller = entity.plugin(iqCaller)

const streamFeature = {
priority: 2000,
match,
run: (entity) => {
return caller.set(null, xml`<session xmlns='${NS}'/>`)
}
}

const streamFeatures = entity.plugin(streamfeatures)
streamFeatures.add(streamFeature)
return {
entity
}
}

0 comments on commit f42dfd9

Please sign in to comment.