Skip to content

Commit 689f894

Browse files
Update README.md
1 parent 2e5ed54 commit 689f894

File tree

1 file changed

+105
-1
lines changed

1 file changed

+105
-1
lines changed

README.md

Lines changed: 105 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,106 @@
1-
# reactnative-xmpp
1+
# ReactNative-XMPP
22
XMPP module for React Native
3+
4+
This module is a work in progress and is a barebones XMPP client module at the moment. It should be enough to get some functional XMPP implementation in React Native started. Our development team intends to continue contributing towards further development of the module in coming days and months. Following is a very high level and a draft roadmap for the lib -
5+
6+
- Add unit tests
7+
- Support SASL and Digest-MD5 based Auth. The lib/module currently supports plain auth.
8+
- Implement handling of use-cases such as MUC Invitation, Subscription IQ etc.
9+
- Fork/branch to implement new template driven design
10+
- Achieve feature complete wrt core XMPP spec and XMPP MUC specs
11+
12+
13+
# Sample Code
14+
15+
```
16+
require('./shim')
17+
18+
import React, { Component } from 'react';
19+
import {
20+
AppRegistry,
21+
StyleSheet,
22+
Text,
23+
View
24+
} from 'react-native';
25+
26+
global.Buffer = global.Buffer || require('buffer').Buffer
27+
28+
var xmpp = require('./reactnative-xmpp.js');
29+
30+
var conf = {login: 'user2',
31+
password: 'Chelsea@100',
32+
domain: 'localhost',
33+
host: 'localhost'};
34+
var client = new xmpp.Client(conf);
35+
36+
37+
client.on('ready', function () {
38+
setTimeout(function () {
39+
for(var i = 0; i < client.roster.length; i++) {
40+
console.log(client.roster[i].getAttribute('jid'));
41+
42+
if(client.roster[i].getAttribute('jid') === 'user3@localhost') {
43+
client.write('<presence to="'+ client.roster[i].getAttribute('jid') +'" type="subscribe" />');
44+
45+
client.subscribe(client.roster[i].getAttribute('jid'), 'Friends', null, function(elt) {
46+
console.log("Subscribe response: " + elt);
47+
})
48+
}
49+
50+
}
51+
}, 1000);
52+
});
53+
54+
client.on('presence.subscribe',function(element) {
55+
client.write('<presence to="'+ element.getAttribute('from') +'" type="subscribed" />');
56+
});
57+
58+
client.on('ready', function() {
59+
client.join('testroom@conference.localhost', 'chetans', function(elem) {
60+
console.log(elem)
61+
});
62+
})
63+
64+
65+
66+
class reactnativexmpp extends Component {
67+
render() {
68+
return (
69+
<View style={styles.container}>
70+
<Text style={styles.welcome}>
71+
Welcome to React Native!
72+
</Text>
73+
<Text style={styles.instructions}>
74+
To get started, edit index.ios.js
75+
</Text>
76+
<Text style={styles.instructions}>
77+
Press Cmd+R to reload,{'\n'}
78+
Cmd+D or shake for dev menu
79+
</Text>
80+
</View>
81+
);
82+
}
83+
}
84+
85+
const styles = StyleSheet.create({
86+
container: {
87+
flex: 1,
88+
justifyContent: 'center',
89+
alignItems: 'center',
90+
backgroundColor: '#F5FCFF',
91+
},
92+
welcome: {
93+
fontSize: 20,
94+
textAlign: 'center',
95+
margin: 10,
96+
},
97+
instructions: {
98+
textAlign: 'center',
99+
color: '#333333',
100+
marginBottom: 5,
101+
},
102+
});
103+
104+
AppRegistry.registerComponent('reactnativexmpp', () => reactnativexmpp);
105+
106+
```

0 commit comments

Comments
 (0)