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

nodejs support #1

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
122 changes: 88 additions & 34 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 10 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"unpkg": "dist/strophe.umd.min.js",
"scripts": {
"build": "rollup -c",
"lint": "make jshint",
"lint": "make eslint",
"clean": "make clean",
"doc": "make doc",
"prepare": "yarpm run build"
Expand All @@ -69,9 +69,15 @@
"rollup-plugin-node-resolve": "^5.0.0",
"rollup-plugin-uglify": "^6.0.2",
"run-headless-chromium": "^0.1.1",
"sinon": "1.17.7",
"sinon-qunit": "~2.0.0",
"sinon": "^2.4.1",
"sinon-qunit": "^2.0.0",
"yarpm": "^0.2.1"
},
"dependencies": {}
"dependencies": {
"abab": "^2.0.0"
},
"optionalDependencies": {
"ws": "^7.0.0",
"xmldom": "^0.1.27"
}
}
8 changes: 4 additions & 4 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default [
commonjs(),
globals(),
babel({
exclude: ['node_modules/**'],
babelrc: false,
presets: [
['@babel/preset-env', {
targets: {
Expand All @@ -43,7 +43,7 @@ export default [
commonjs(),
globals(),
babel({
exclude: ['node_modules/**'],
babelrc: false,
presets: [
['@babel/preset-env', {
targets: {
Expand All @@ -58,15 +58,15 @@ export default [
// CommonJS (for Node) and ES module (for bundlers) build.
{
input: 'src/strophe.js',
external: ['window', 'md5'],
external: ['window', 'abab'],
output: [
{ file: pkg.main, format: 'cjs' },
{ file: pkg.module, format: 'es' }
],
plugins: [
globals(),
babel({
exclude: ['node_modules/**'],
babelrc: false,
presets: [
['@babel/preset-env']
]
Expand Down
1 change: 1 addition & 0 deletions src/bosh.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

/* global window, setTimeout, clearTimeout, XMLHttpRequest, ActiveXObject */

import { DOMParser } from './shims'
import core from './core';

const Strophe = core.Strophe;
Expand Down
65 changes: 6 additions & 59 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*/
/*global define, document, sessionStorage, setTimeout, clearTimeout, ActiveXObject, DOMParser, btoa, atob, module */

import * as shims from './shims';
import { atob, btoa } from 'abab'
import MD5 from './md5';
import SHA1 from './sha1';
import utils from './utils';
Expand Down Expand Up @@ -330,26 +332,6 @@ const Strophe = {
*/
_xmlGenerator: null,

/** PrivateFunction: _makeGenerator
* _Private_ function that creates a dummy XML DOM document to serve as
* an element and text node generator.
*/
_makeGenerator: function () {
let doc;
// IE9 does implement createDocument(); however, using it will cause the browser to leak memory on page unload.
// Here, we test for presence of createDocument() plus IE's proprietary documentMode attribute, which would be
// less than 10 in the case of IE9 and below.
if (document.implementation.createDocument === undefined ||
document.implementation.createDocument && document.documentMode && document.documentMode < 10) {
doc = this._getIEXmlDom();
doc.appendChild(doc.createElement('strophe'));
} else {
doc = document.implementation
.createDocument('jabber:client', 'strophe', null);
}
return doc;
},

/** Function: xmlGenerator
* Get the DOM document to generate elements.
*
Expand All @@ -358,45 +340,11 @@ const Strophe = {
*/
xmlGenerator: function () {
if (!Strophe._xmlGenerator) {
Strophe._xmlGenerator = Strophe._makeGenerator();
Strophe._xmlGenerator = shims.getDummyXMLDOMDocument()
}
return Strophe._xmlGenerator;
},

/** PrivateFunction: _getIEXmlDom
* Gets IE xml doc object
*
* Returns:
* A Microsoft XML DOM Object
* See Also:
* http://msdn.microsoft.com/en-us/library/ms757837%28VS.85%29.aspx
*/
_getIEXmlDom : function() {
let doc = null;
const docStrings = [
"Msxml2.DOMDocument.6.0",
"Msxml2.DOMDocument.5.0",
"Msxml2.DOMDocument.4.0",
"MSXML2.DOMDocument.3.0",
"MSXML2.DOMDocument",
"MSXML.DOMDocument",
"Microsoft.XMLDOM"
];

for (let d=0; d<docStrings.length; d++) {
if (doc === null) {
try {
doc = new ActiveXObject(docStrings[d]);
} catch (e) {
doc = null;
}
} else {
break;
}
}
return doc;
},

/** Function: xmlElement
* Create an XML DOM element.
*
Expand Down Expand Up @@ -512,8 +460,8 @@ const Strophe = {
xmlHtmlNode: function (html) {
let node;
//ensure text is escaped
if (DOMParser) {
const parser = new DOMParser();
if (shims.DOMParser) {
const parser = new shims.DOMParser();
node = parser.parseFromString(html, "text/xml");
} else {
node = new ActiveXObject("Microsoft.XMLDOM");
Expand Down Expand Up @@ -1160,7 +1108,7 @@ Strophe.Builder.prototype = {
* The Strophe.Builder object.
*/
h: function (html) {
const fragment = document.createElement('body');
const fragment = Strophe.xmlGenerator().createElement('body');
// force the browser to try and fix any invalid HTML tags
fragment.innerHTML = html;
// copy cleaned html into an xml dom
Expand Down Expand Up @@ -3505,7 +3453,6 @@ Strophe.SASLOAuthBearer.prototype = new Strophe.SASLMechanism("OAUTHBEARER", tru
Strophe.SASLOAuthBearer.prototype.test = function(connection) {
return connection.pass !== null;
};

Strophe.SASLOAuthBearer.prototype.onChallenge = function(connection) {
let auth_str = 'n,';
if (connection.authcid !== null) {
Expand Down
Loading