diff --git a/lib/reactnative-xmpp.js b/lib/reactnative-xmpp.js
index 28a3af5..5054a96 100644
--- a/lib/reactnative-xmpp.js
+++ b/lib/reactnative-xmpp.js
@@ -109,7 +109,7 @@ Client = function (conf) {
+ 'version="1.0" >');
}
- function resourceBindings () {
+ function resourceBindings () {
self.sendIq({type: 'set'}, '' + conf.resource + "", function(elt) {
sessionBindings();
});
@@ -118,16 +118,17 @@ Client = function (conf) {
function sessionBindings () {
console.log("In session bindings");
self.sendIq({type: 'set'}, '', function(elt) {
- sendPresenceInformation();
- });
+ sendPresenceInformation();
+ });
}
function sendPresenceInformation () {
console.log("In send presence information");
- self.getRoster(function () {
- self.setStatus('chat', conf.status);
- self.emit('ready');
- });
+ self.emit('ready');
+ // self.getRoster(function () {
+ // self.setStatus('chat', conf.status);
+ //
+ // });
}
function onMessageReceive (attrs) {
@@ -140,13 +141,14 @@ Client = function (conf) {
self.emit('html.message', element.parent);
}
- function onMessageReceived () {
- stream_events_manager.removeListener('end|body|' + NS_XHTML, onHtmlBodyReceived);
- stream_events_manager.removeListener('end|body|' + NS_CLIENT, onBodyReceived);
+ function onMessageReceived (element) {
+ self.emit('message', element);
+ // stream_events_manager.removeListener('end|body|' + NS_XHTML, onHtmlBodyReceived);
+ // stream_events_manager.removeListener('end|body|' + NS_CLIENT, onBodyReceived);
}
- stream_events_manager.once('end|body|' + NS_XHTML, onHtmlBodyReceived);
- stream_events_manager.once('end|body|' + NS_CLIENT, onBodyReceived);
+ // stream_events_manager.once('end|body|' + NS_XHTML, onHtmlBodyReceived);
+ // stream_events_manager.once('end|body|' + NS_CLIENT, onBodyReceived);
stream_events_manager.once('end|message|' + NS_CLIENT, onMessageReceived);
}
@@ -166,9 +168,9 @@ Client = function (conf) {
function presenceReceived (element) {
if(element.getAttribute('type') !== null && element.getAttribute('type') !== '') {
- self.emit('presence.'+ element.getAttribute('type'), element);
+ self.emit('presence.'+ element.getAttribute('type'), element);
}
-
+
self.emit('presence.receive', element);
}
@@ -224,20 +226,21 @@ Client = function (conf) {
}
function init () {
- //
self.jid = conf.login + '@' + conf.domain + '/' + conf.resource;
conn = tcp.createConnection(conf.port || 5222, conf.host);
conn.on("disconnect", function (error) {
- if (error) {
- throw "disconnected server in error";
- }
+ self.emit('disconnect');
+ // if (error) {
+ // throw "disconnected server in error";
+ // }
});
conn.on("connect", function () {
this.setTimeout(0);
this.setEncoding("utf8");
initiateSession();
+ self.emit('connecting');
});
conn.on("data", function (data) {
@@ -256,32 +259,36 @@ Client = function (conf) {
});
conn.on("error", function (error) {
- console.error(error);
- var timeout = Math.round(Math.random() * 10 + 5) * 1000;
+ // console.error(error);
+ self.emit('error');
+ var timeout = Math.round(5) * 1000;
setTimeout(init, timeout);
- console.log(timeout);
+ // console.log(timeout);
});
conn.on("close", function (error) {
- if (error) {
- throw 'connection close with error';
- }
+ self.emit('close');
+ // var timeout = 5 * 1000;
+ // setTimeout(init, timeout);
+ // if (error) {
+ // throw 'connection close with error';
+ // }
});
conn.on("end", function () {
this.write('');
-
+
});
}
stream_events_manager = (new events)
- .once('start|stream|' + NS_STREAMS, setID)
- .once('start|success|' + NS_SASL, initiateSession)
- .once('start|bind|' + NS_BIND, resourceBindings)
- .once('start|presence|' + NS_CLIENT, onPresenceReceive)
- .once('end|mechanism|' + NS_CLIENT, setMechanism)
- .once('end|mechanisms|' + NS_SASL, sasl)
+ .on('start|stream|' + NS_STREAMS, setID)
+ .on('start|success|' + NS_SASL, initiateSession)
+ .on('start|bind|' + NS_BIND, resourceBindings)
+ .on('start|presence|' + NS_CLIENT, onPresenceReceive)
+ .on('end|mechanism|' + NS_CLIENT, setMechanism)
+ .on('end|mechanisms|' + NS_SASL, sasl)
.on('start|message|' + NS_CLIENT, onMessageReceive)
.on('start|query|' + NS_SOFT_VERSION, sendSoftVersion)
.on('start|query|' + NS_LAST_SRV_RCV, sendLastServerResponse)
@@ -327,8 +334,8 @@ Client = function (conf) {
value = '';
current_node.cdata = cdata;
cdata = '';
- stream_events_manager.emit('end|' + elem + '|' + uri, current_node);
- current_node = parent_node = current_node.parent;
+ stream_events_manager.emit('end|' + elem + '|' + uri, current_node);
+ current_node = parent_node = current_node.parent;
});
cb.onCharacters(function(chars) {
value += chars;
@@ -459,11 +466,9 @@ Client.prototype.getVCard = function (to, cb) {
*
* Send instant message.
**/
-Client.prototype.push = function (to, str, type, data = undefined) {
- if (type === "groupchat") {
- to = this.getBareJid(to);
- }
+Client.prototype.push = function (id, to, str, type, data = undefined) {
var raw = '' + (data ? data : "") + '';
this.write(raw);
@@ -608,12 +613,12 @@ Client.prototype.subscribe = function (to, group, name, cb) {
*
* Add somebody to your roster
**/
-Client.prototype.join = function (room, nick, cb) {
+Client.prototype.join = function (room, nick, history, cb) {
if (!(typeof cb === "function")) {
cb = function () {};
}
- return this.write(' ');
+ return this.write(' ');
};
/**
@@ -628,6 +633,11 @@ Client.prototype.write = function (data) {
return this;
};
+Client.prototype.disconnect = function () {
+ conn.removeAllListeners()
+ conn.destroy()
+};
+
exports.Client = Client;
exports.NS_SASL = NS_SASL;
exports.NS_BIND = NS_BIND;
diff --git a/package.json b/package.json
index b54a3e5..6b00305 100644
--- a/package.json
+++ b/package.json
@@ -34,11 +34,11 @@
"querystring-es3": "^0.2.1",
"react": "15.2.1",
"react-native-crypto": "^2.0.1",
- "react-native-fs": "^1.5.1",
+ "react-native-fs": "^2.3.2",
"react-native-http": "github:tradle/react-native-http#834492d",
"react-native-level-fs": "^2.0.1",
"react-native-randombytes": "^2.1.0",
- "react-native-tcp": "^1.0.1",
+ "react-native-tcp": "git+https://github.com/srijan02420/react-native-tcp.git",
"react-native-udp": "^1.2.4",
"react-native-util": "^1.0.2",
"readable-stream": "^1.0.33",