Moving forward to device-to-device and device-to-mobile communication in Ombori Grid we are introducing a new concept: spacesA space is a separate communication channel for deviceschannels
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 spacechannel.
Example, sending a message to the space channel names somespace
somechannel
in a screen app:
Code Block |
---|
export const App = () => { const pub = usePublish(); const send = useCallback(() => { pub('somespacesomechannel/Some.MessageType', {payload: "goes here"}); }, [pub]); ... return <button onClick={send} /> } |
As you can see, to send a message to a spacespecific channel, just prefix it message type with the channels' name of the space and add slash.
Note that you can still send messages without prefix, they will be sent to the default space channel (which is internally called message
) so you don't need to modify any existing code.
Subscribing to messages is done in similar fashion:
Code Block |
---|
export const App = () => { const [data, setData] = useState<any>(null); useSubscribe('somespacesomechannel/Another.MessageType', (payload) => { setData(payload); }, [setData]) return <div>{data}</div> } |
So, to subscribe to a message in somespace
somechannel
, just add a prefix to message type when calling useSubscribe
Same rules apply to modules/IoT apps. When communicating with the default spacechannel, don't use the prefix. When talking to a spacechannel, add space its name before an event type.
Usage
...
message
- this is default spacechannel, 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.remote
- messages will be forwarded to a connected mobile remote app. Mobile remote app cannot write to the default spacechannel, 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 spacechannel, it can only usemobileapp
. Requiresmobileapp
module.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.