echo.gno
1.02 Kb · 28 lines
1// Package echo is gnotif's demo realm: Echo sends a message back to its
2// caller as a browser notification.
3package echo
4
5import (
6 "chain"
7
8 "gno.land/r/g1rzgxl6njyu4c2x89gxvaa9cswrt73rz8mlp7l6/alpha2/gnotif/v0"
9)
10
11// The registry sees this realm as the caller, so the trigger is verified.
12func init(cur realm) {
13 gnotif.Declare(cross(cur), cur.PkgPath(), "Echo", "", "to", "Echo", "{msg}", "/")
14}
15
16// Echo sends msg to the browsers that opted in with the caller's address.
17// The recipient is always the caller, so nobody can notify another address.
18func Echo(cur realm, msg string) {
19 chain.Emit("Echo", "to", cur.Previous().Address().String(), "msg", msg)
20}
21
22// Render serves one page for every path: what Echo does and where to try it.
23func Render(_ string) string {
24 return "# Echo\n\n" +
25 "Call `Echo` with a message, and gnotif shows it as a notification in the browsers " +
26 "that turned on notifications for your own address. Nobody else can send one to you.\n\n" +
27 "Try it on [demo.gnotif.xyz](https://demo.gnotif.xyz).\n"
28}