43 lines
1.1 KiB
JavaScript
43 lines
1.1 KiB
JavaScript
// Send newly generated message via a MiNode process running in background
|
|
|
|
const objects = require('bitmessage').objects,
|
|
Address = require('bitmessage').Address;
|
|
|
|
const { spawn } = require('child_process');
|
|
const zmq = require('zeromq');
|
|
|
|
(async () => {
|
|
const sock = zmq.socket('pub');
|
|
|
|
sock.bindSync('tcp://127.0.0.1:5566');
|
|
console.log('Publisher bound to port 5566');
|
|
|
|
spawn(
|
|
'minode', ['--request-queue', 'tcp://127.0.0.1:5566'],
|
|
{timeout: 100000, killSignal: 'SIGTERM', detached: true, stdio: 'inherit'}
|
|
).on('exit', (c, s) => {
|
|
sock.close();
|
|
});
|
|
|
|
const sender = Address.fromRandom(),
|
|
recipient = Address.fromPassphrase('test');
|
|
console.log('sender:', sender.encode());
|
|
console.log('recipient:', recipient.encode());
|
|
|
|
objects.msg.encodePayloadAsync({
|
|
ttl: 1800,
|
|
from: sender,
|
|
to: recipient,
|
|
message: 'The quick brown fox jumps over the lazy dog.',
|
|
subject: 'hello',
|
|
encoding: 2
|
|
}).then(function (msg) {
|
|
console.log('msg:', msg.toString('hex'));
|
|
console.log('Sending the msg...');
|
|
sock.send(Buffer.concat([
|
|
Buffer.from('msg', 'ascii'), Buffer.from('00', 'hex'), msg
|
|
]));
|
|
});
|
|
|
|
})();
|