mirror of
https://github.com/status-im/status-go.git
synced 2025-02-06 11:56:01 +00:00
Updated Whisper Push Notifications (markdown)
parent
b5afb6dc73
commit
864086c471
@ -232,6 +232,47 @@ Now, we have Chat Session Key, which we can use to register our device id (to be
|
||||
|
||||
Let's see how `registerDevice()` might look like:
|
||||
```js
|
||||
var newDeviceRegistrationTopic = '0x14621a51'; // NEW_DEVICE_REGISTRATION
|
||||
var ackDeviceRegistrationTopic = '0x424358d6'; // ACK_DEVICE_REGISTRATION
|
||||
var registerDevice = function (chatId, chatKey) {
|
||||
console.log('chat session key: ', chatKey)
|
||||
// this obtained from https://status-sandbox-c1b34.firebaseapp.com/
|
||||
var deviceID = 'ca5pRJc6L8s:APA91bHpYFtpxvXx6uOayGmnNVnktA4PEEZdquCCt3fWR5ldLzSy1A37Tsbzk5Gavlmk1d_fvHRVnK7xPAhFFl-erF7O87DnIEstW6DEyhyiKZYA4dXFh6uy323f9A3uw5hEtT_kQVhT';
|
||||
|
||||
// make sure that chat key is loaded
|
||||
var keyname = chatId + 'chatkey'; // there might be many chat keys
|
||||
web3.shh.deleteSymKey(keyname);
|
||||
web3.shh.addSymKey(keyname, chatKey);
|
||||
|
||||
// before sending request, let's start waiting for response
|
||||
var filter = web3.shh.filter({
|
||||
to: identity,
|
||||
topics: [ackDeviceRegistrationTopic]
|
||||
});
|
||||
filter.watch(function (error, result) {
|
||||
if (!error) {
|
||||
console.log("Device Registration ACK received: ", result);
|
||||
// response will be in JSON, e.g. {"server": "0xdeadbeef"}
|
||||
var payload = JSON.parse(web3.toAscii(result.payload));
|
||||
|
||||
// no need to watch for the filter any more
|
||||
filter.stopWatching();
|
||||
}
|
||||
});
|
||||
|
||||
var err = web3.shh.post({
|
||||
from: identity,
|
||||
topics: [newDeviceRegistrationTopic],
|
||||
payload: '{"device": "' + deviceID + '"}',
|
||||
ttl: 20,
|
||||
keyname: keyname
|
||||
});
|
||||
if (err !== null) {
|
||||
console.log("message NOT sent")
|
||||
} else {
|
||||
console.log("message sent OK")
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
### 3. Sharing Chat session key, and allowing notifications
|
||||
|
Loading…
x
Reference in New Issue
Block a user