Update README with content and format - pt 3

This commit is contained in:
Richard Ramos 2019-02-10 21:25:14 -04:00
parent 8bca5fbd06
commit 07e19f0dde
2 changed files with 112 additions and 21 deletions

112
README.md
View File

@ -296,7 +296,7 @@ status.addContact("0x1122...9900");
Arguments Arguments
* _pubKey_ - public key to add as a contact. * _pubKey_ - public key to add as a contact.
* _cb_ - a callback that will be called, possibly with an error, when the contact is added. If there is no error, the first argument will be null. Optional. * _cb_ - a callback that will be called, possibly with an error, when the contact is added. If there is no error, the first argument will be null. Optional.
@ -316,19 +316,117 @@ Arguments
## TODO: Create documentation for sending messages
## TODO
* sendUserMessage(contactCode, msg, [cb]) * sendUserMessage(contactCode, msg, [cb])
* sendGroupMessage(channelName, msg, [cb]) * sendGroupMessage(channelName, msg, [cb])
* sendJsonMessage(destination, msg, [cb]) * sendJsonMessage(destination, msg, [cb])
* sendMessage(destination, msg, [cb]) * sendMessage(destination, msg, [cb])
* mailservers.useMailserver(enode, [cb])
* mailservers.requestUserMessages(options, cb)
* mailservers.requestChannelMessages(topic, options, cb)
See the examples for usage in the meantime ### mailservers.useMailserver
Use a specific mailserver to obtain old messages. Active mailservers from Status.im can be found [here](https://fleets.status.im/)
```javascript
status.mailservers.useMailserver(enode, [cb]);
```
```javascript
const enode = "enode://0011...aabb@111.222.33.44:30303";
status.mailservers.useMailserver(enode, (err, res) => {
if (err) {
console.err("Error: " + err);
return;
}
// Do something
});
```
Arguments
* _enode_ - Mailserver enode address.
* _cb_ - a callback that will be called, possibly with an error, when the mailserver is selected successfully. If there is no error, the first argument will be null. Optional.
### mailservers.requestUserMessages
Once a mailserver is selected, request old private messages. Messages will be received in the `onMessage` or `onUserMessage` handler.
```javascript
* mailservers.requestUserMessages(options, [cb])
```
```javascript
const enode = "enode://0011...aabb@111.222.33.44:30303";
status.mailservers.useMailserver(enode, (err, res) => {
if (err) {
console.err("Error: " + err);
return;
}
const from = parseInt((new Date()).getTime() / 1000 - 86400, 10);
const to = parseInt((new Date()).getTime() / 1000, 10);
// User messages
status.mailservers.requestUserMessages({from, to}, (err, res) => {
if(err)
console.log(err);
// Do something
});
});
```
Arguments
* _options_ - an object containing parameters .
* _cb_ - a callback that will be called, possibly with an error, when the old private messages are requested successfully. If there is no error, the first argument will be null. Optional.
Options
* _from_ - lower bound of time range as unix timestamp, default is 24 hours back from now.
* _to_ - upper bound of time range as unix timestamp, default is now
* _timeout_ - TODO: research this in `status-go`, default is 30
* _limit_ - TODO: research this in `status-go`, default is 0
### mailservers.requestChannelMessages
Once a mailserver is selected, request old public messages for a channel. Messages will be received in the `onMessage` or `onChannelMessage` handler.
```javascript
* mailservers.requestChannelMessages(channel, [cb])
```
```javascript
const enode = "enode://0011...aabb@111.222.33.44:30303";
status.mailservers.useMailserver(enode, (err, res) => {
if (err) {
console.err("Error: " + err);
return;
}
const from = parseInt((new Date()).getTime() / 1000 - 86400, 10);
const to = parseInt((new Date()).getTime() / 1000, 10);
// Channel messages
status.mailservers.requestChannelMessages("mytest", {from, to}, (err, res) => {
if(err)
console.log(err);
// Do something
});
});
```
Arguments
* _channel_ - channel name to obtain messages from. A 4 bytes hex topic can be used too.
* _options_ - an object containing parameters .
* _cb_ - a callback that will be called, possibly with an error, when the old private messages are requested successfully. If there is no error, the first argument will be null. Optional.
Options
* _from_ - lower bound of time range as unix timestamp, default is 24 hours back from now.
* _to_ - upper bound of time range as unix timestamp, default is now
* _timeout_ - TODO: research this in `status-go`, default is 30
* _limit_ - TODO: research this in `status-go`, default is 0

View File

@ -3,48 +3,41 @@ var StatusJS = require('../dist/index.js');
(async () => { (async () => {
var status = new StatusJS(); var status = new StatusJS();
await status.connect("ws://localhost:8546", "0x0011223344556677889900112233445566778899001122334455667788990011"); await status.connect("ws://localhost:8546", "0x0011223344556677889900112233445566778899001122334455667788990011");
// await status.connect("/home/richard/.statusd/geth.ipc", "0x0011223344556677889900112233445566778899001122334455667788990011");
console.log(await status.getPublicKey()); console.log(await status.getPublicKey());
const channel = "mytest"; const channel = "mytest";
await status.joinChat(channel); await status.joinChat(channel);
status.onMessage(channel, (err, data) => { status.onMessage(channel, (err, data) => {
if(!err) console.log("PubMessage: " + data.payload); if(!err)
console.log("PubMessage: " + data.payload);
}); });
status.onMessage((err, data) => { status.onMessage((err, data) => {
if(!err) console.log("PrivMessage: " + data.payload); if(!err)
console.log("PrivMessage: " + data.payload);
}); });
// mail-02.gc-us-central1-a.eth.beta // mail-02.gc-us-central1-a.eth.beta
const enode = "enode://015e22f6cd2b44c8a51bd7a23555e271e0759c7d7f52432719665a74966f2da456d28e154e836bee6092b4d686fe67e331655586c57b718be3997c1629d24167@35.226.21.19:30504"; const enode = "enode://015e22f6cd2b44c8a51bd7a23555e271e0759c7d7f52432719665a74966f2da456d28e154e836bee6092b4d686fe67e331655586c57b718be3997c1629d24167@35.226.21.19:30504";
status.mailservers.useMailserver(enode, (err, res) => { status.mailservers.useMailserver(enode, (err, res) => {
// Group chats
let from = parseInt((new Date()).getTime() / 1000 - 86400, 10); let from = parseInt((new Date()).getTime() / 1000 - 86400, 10);
let to = parseInt((new Date()).getTime() / 1000, 10); let to = parseInt((new Date()).getTime() / 1000, 10);
// Public channel messages
status.mailservers.requestChannelMessages(channel, {from, to}, (err, res) => { status.mailservers.requestChannelMessages(channel, {from, to}, (err, res) => {
if(err) console.log(err); if(err) console.log(err);
}); });
// User messages // Private user messages
status.mailservers.requestUserMessages({from, to}, (err, res) => { status.mailservers.requestUserMessages({from, to}, (err, res) => {
if(err) console.log(err); if(err) console.log(err);
}); });
}); });
setInterval(() => { }, 3000); setInterval(() => { }, 3000);
})(); })();