Messaging and channels
Moving forward to device-to-device and device-to-mobile communication in Ombori Grid we are introducing a new concept: channels
The idea behind channels is to process messages differently and isolate different client roles from each other (see examples below). Screen and IoT apps and modules can publish/subscribe to messages to/from any channel.
Example, sending a message to the channel names somechannel
in a screen app:
export const App = () => {
const pub = usePublish();
const send = useCallback(() => {
pub('somechannel/Some.MessageType', {payload: "goes here"});
}, [pub]);
...
return <button onClick={send} />
}
As you can see, to send a message to a specific channel, just prefix it message type with channels' name and add slash.
Note that you can still send messages without prefix, they will be sent to the default channel (which is internally called message
) so you don't need to modify any existing code.
Subscribing to messages is done in similar fashion:
export const App = () => {
const [data, setData] = useState<any>(null);
useSubscribe('somechannel/Another.MessageType', (payload) => {
setData(payload);
}, [setData])
return <div>{data}</div>
}
So, to subscribe to a message in somechannel
, just add a prefix to message type when calling useSubscribe
Same rules apply to modules/IoT apps. When communicating with the default channel, don't use the prefix. When talking to a channel, add its name before an event type.
Usage
message
- this is default channel, apps and modules on the same device can communicate with each other thru it. Messages do not leave the device. The channel is always available.localnet
- messages will be automatically send to any GridOS devices in the same local network. This requiresmessaging
module. No internet connection required for this to operate.remote
- messages will be forwarded to a connected mobile remote app. Mobile remote app cannot write to the default channel, it can only useremote
. Requiresmessaging
module, option must be enabled in module settings.mobileapp
- messages will be forwarded to a local mobile app. Local mobile app cannot write to the default channel, it can only usemobileapp
. Requiresmobileapp
module. No internet connection required for this to operate.pubnub
- messages are broadcasted between devices via pubnub service. Requiresmessaging
module. PubKey and SubKey settings should be entered in module settings on each connected device.