Protobject Communication API - bellinux/pcode GitHub Wiki
Protobject Communication API is a designed to facilitate communication between different devices. It allows you to send messages to other devices, and handle incoming messages through callbacks.
JavaScript
Import the API
import Protobject from './js/protobject.js';
Sending a Message
To send a message, use the send
method followed by the to
method to specify the target device (script).
Protobject.send({ key: 'value' }).to('targetDevice.js');
Receiving a Message
To handle incoming messages, use the onReceived method to define a callback function that will be executed when a message is received.
Protobject.onReceived((data) => {
console.log('Message received:' + data.key);
});
Python
Import the API
from protobject import Protobject
Sending a Message
To send a message, use the send
method followed by the to
method to specify the target device (script).
data = {"key": "value"}
Protobject.send(data).to("targetDevice.py")
Receiving a Message
To handle incoming messages, use the onReceived method to define a callback function that will be executed when a message is received.
def handle_message(data):
print("Message received:" + data.key)
Protobject.onReceived(handle_message)