-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
client: Add support for unejected React Native apps
- Loading branch information
Showing
16 changed files
with
176 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
'use strict' | ||
|
||
const {xml, jid, Client} = require('@xmpp/client-core') | ||
const getDomain = require('./lib/getDomain') | ||
|
||
const _reconnect = require('@xmpp/reconnect') | ||
const _websocket = require('@xmpp/websocket') | ||
const _middleware = require('@xmpp/middleware') | ||
const _streamFeatures = require('@xmpp/stream-features') | ||
const _iqCaller = require('@xmpp/iq/caller') | ||
const _iqCallee = require('@xmpp/iq/callee') | ||
const _resolve = require('@xmpp/resolve') | ||
|
||
// Stream features - order matters and define priority | ||
const _sasl = require('@xmpp/sasl') | ||
const _resourceBinding = require('@xmpp/resource-binding') | ||
const _sessionEstablishment = require('@xmpp/session-establishment') | ||
|
||
// SASL mechanisms - order matters and define priority | ||
const anonymous = require('@xmpp/sasl-anonymous') | ||
const plain = require('@xmpp/sasl-plain') | ||
|
||
function client(options = {}) { | ||
const {resource, credentials, username, password, ...params} = options | ||
|
||
const {domain, service} = params | ||
if (!domain && service) { | ||
params.domain = getDomain(service) | ||
} | ||
|
||
const entity = new Client(params) | ||
|
||
const reconnect = _reconnect({entity}) | ||
const websocket = _websocket({entity}) | ||
|
||
const middleware = _middleware({entity}) | ||
const streamFeatures = _streamFeatures({middleware}) | ||
const iqCaller = _iqCaller({middleware, entity}) | ||
const iqCallee = _iqCallee({middleware, entity}) | ||
const resolve = _resolve({entity}) | ||
// Stream features - order matters and define priority | ||
const sasl = _sasl({streamFeatures}, credentials || {username, password}) | ||
const resourceBinding = _resourceBinding({iqCaller, streamFeatures}, resource) | ||
const sessionEstablishment = _sessionEstablishment({iqCaller, streamFeatures}) | ||
// SASL mechanisms - order matters and define priority | ||
const mechanisms = Object.entries({anonymous, plain}) | ||
.map(([k, v]) => ({[k]: v(sasl)})) | ||
|
||
return Object.assign(entity, { | ||
entity, | ||
reconnect, | ||
websocket, | ||
middleware, | ||
streamFeatures, | ||
iqCaller, | ||
iqCallee, | ||
resolve, | ||
sasl, | ||
resourceBinding, | ||
sessionEstablishment, | ||
mechanisms, | ||
}) | ||
} | ||
|
||
module.exports.xml = xml | ||
module.exports.jid = jid | ||
module.exports.client = client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
'use strict' | ||
|
||
module.exports = function getDomain(service) { | ||
const domain = service.split('://')[1] || service | ||
return domain.split(':')[0].split('/')[0] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,5 +18,8 @@ | |
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"dependencies": { | ||
"events": "^3.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,27 @@ | ||
'use strict' | ||
|
||
const {Base64} = require('js-base64') | ||
|
||
module.exports.encode = function encode(string) { | ||
if (!global.Buffer) { | ||
if (global.btoa) { | ||
return global.btoa(string) | ||
} | ||
return Buffer.from(string, 'utf8').toString('base64') | ||
|
||
if (global.Buffer) { | ||
return Buffer.from(string, 'utf8').toString('base64') | ||
} | ||
|
||
return Base64.btoa(string) | ||
} | ||
|
||
module.exports.decode = function decode(string) { | ||
if (!global.Buffer) { | ||
if (global.atob) { | ||
return global.atob(string) | ||
} | ||
return Buffer.from(string, 'base64').toString('utf8') | ||
|
||
if (global.Buffer) { | ||
return Buffer.from(string, 'base64').toString('utf8') | ||
} | ||
|
||
return Base64.btoa(string) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# TCP | ||
|
||
TCP transport for `@xmpp/client`. | ||
|
||
Included and enabled in `@xmpp/client` for Node.js. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# TLS | ||
|
||
TLS transport for `@xmpp/client`. | ||
|
||
Included and enabled in `@xmpp/client` for Node.js. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# WebSocket | ||
|
||
WebSocket transport for `@xmpp/client`. | ||
|
||
Included and enabled in `@xmpp/client`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters