add sendJsonMessage
This commit is contained in:
parent
bdc22cbbd4
commit
8bccb22c20
25
src/index.js
25
src/index.js
|
@ -6,12 +6,12 @@ const POW_TIME = 1;
|
|||
const TTL = 10;
|
||||
const POW_TARGET = 0.002;
|
||||
|
||||
function createStatusPayload(msg) {
|
||||
function createStatusPayload(msg, isJson) {
|
||||
let tag = '~#c4';
|
||||
let content = msg;
|
||||
let messageType = '~:public-group-user-message';
|
||||
let clockValue = (new Date().getTime()) * 100;
|
||||
let contentType = 'text/plain';
|
||||
let contentType = (isJson ? 'content/json' : 'text/plain');
|
||||
let timestamp = new Date().getTime();
|
||||
return asciiToHex(
|
||||
JSON.stringify([
|
||||
|
@ -91,6 +91,27 @@ class StatusJS {
|
|||
});
|
||||
}
|
||||
|
||||
sendJsonMessage(channelName, msg, cb) {
|
||||
if (!this.channels[channelName]) {
|
||||
return cb("unknown channel: " + channelName);
|
||||
}
|
||||
this.shh.post({
|
||||
symKeyID: this.channels[channelName].channelKey,
|
||||
sig: this.sig,
|
||||
ttl: TTL,
|
||||
topic: this.channels[channelName].channelCode,
|
||||
payload: createStatusPayload(JSON.stringify(msg), true),
|
||||
powTime: POW_TIME,
|
||||
powTarget: POW_TARGET
|
||||
}).then(() => {
|
||||
if (!cb) return;
|
||||
cb(null, true);
|
||||
}).catch((e) => {
|
||||
if (!cb) return;
|
||||
cb(e, false);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = StatusJS;
|
||||
|
|
Loading…
Reference in New Issue