Tutorials ‐ Simple chat - HelloZeroNet/Plugin-PeerMessage GitHub Wiki

This tutorial will help you to create a site using PeerMessage plugin.

  1. Create a new site via ZeroHello

  2. 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.

  3. Add a script test.js and include it to index.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.