-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: webxdc notify & privacy preserving selfAddr (#90)
Add API for notifications and refined `selfAddr` and based on discussions with r10s, adb, hocuri, link2xt and others.
- Loading branch information
Showing
5 changed files
with
119 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,76 @@ | ||
# selfAddr & selfName | ||
|
||
## selfName | ||
|
||
```js | ||
window.webxdc.selfName | ||
``` | ||
|
||
`selfName` is the nick or display name for the user | ||
which can be displayed in the user interface of the webxdc application. | ||
|
||
|
||
## selfAddr | ||
|
||
```js | ||
window.webxdc.selfAddr | ||
``` | ||
|
||
A string with an unique ID identifying the user in the current webxdc. | ||
Every user of an webxdc must get a different ID | ||
and that ID must be the same if the webxdc is started again later for the same user. | ||
The same user in different webxdc, however, may have different IDs. | ||
`selfAddr` is a unique string within a webxdc application that | ||
|
||
Especially useful if you want to differentiate between different peers - | ||
just send the ID along with the payload, | ||
and, if needed, compare the payload addresses against `selfAddr` later on. | ||
- has no meaning outside the webxdc app, | ||
|
||
## selfName | ||
- can be used in other webxdc APIs, | ||
|
||
- should not be shown in the user interface of the webxdc application, | ||
|
||
- is identical across multiple invocations of the same webxdc application, | ||
|
||
- is identical on multiple devices of the user using the same webxdc application. | ||
|
||
- is not linkable to addresses in other webxdc apps: | ||
even if a web app manipulates users to share addresses via copy+paste with another web app, | ||
addresses between the two web apps can not be correlated. | ||
|
||
|
||
## Example using selfAddr and selfName | ||
|
||
Here is a simple chat app that sends out a reply using the display names | ||
but uses the addresses for notifications. | ||
|
||
```js | ||
window.webxdc.selfName | ||
``` | ||
|
||
Name of the current account, as defined in settings. | ||
If empty, this defaults to the peer's address. | ||
// Receive a message from anyone in the chat | ||
let users = new Set(); | ||
|
||
setUpdateListener((update) => { | ||
const prompt = `${update.payload.senderName} (${update.payload.senderAddr}):`; | ||
users.add(update.payload.senderAddr); | ||
console.log(`${prompt} ${update.message}`); | ||
}) | ||
|
||
// start some user interface which calls the following function for | ||
// message sending | ||
|
||
sendMessage(text) => { | ||
let payload = { | ||
senderAddr: webxdc.selfAddr, | ||
senderName: webxdc.selfName, | ||
message: text | ||
}; | ||
|
||
// notify all users who ever sent a message in the chat app | ||
let notify = {}; | ||
for (const addr of users) { | ||
notify[addr] = `new message from ${webxdc.selfName}`; | ||
} | ||
|
||
sendUpdate({ | ||
payload: payload, | ||
notify: notify | ||
}) | ||
}) | ||
``` | ||
|
||
|
||
[`sendUpdate()`]: ./sendUpdate.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters