-
Notifications
You must be signed in to change notification settings - Fork 10
Tutorials ‐ Simple chat
Ivanq edited this page May 29, 2018
·
2 revisions
This tutorial will help you to create a site using PeerMessage plugin.
-
Create a new site via ZeroHello
-
Add file
p2p.json
to site root. (more info here: p2p.json). For now, we'll just set"filter"
property, equal to".*"
. This means that regex-validation of messages is disabled. Now, we can use PeerMessage features. -
Add a script
test.js
and include it toindex.html
(don't forget to remove the default script). We'll create a simple chat implementation:
zeroFrame = new ZeroFrame(); // create new ZeroFrame instance
function sendMessage(text) {
zeroFrame.cmd("peerBroadcast", [text]); // send message "text" to everybody
}
zeroFrame.onRequest = function(cmd, message) { // When we receive a message
if(cmd == "peerReceive") { // and it's from PeerMessage plugin
let text = message.params.message;
console.log(text); // show it
zeroFrame.cmd("peerValid", [message.params.hash]); // This message is correct - broadcast to other peers
}
}
Now you can send message from console via sendMessage(message)
and get responses via console as well.