Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Moving forward to device-to-device and device-to-mobile communication in Ombori Grid we are introducing a new concept: spaces

A space is a separate communication channel for devices. Screen and IoT apps and modules can publish/subscribe to messages to/from any space.

Example, sending a message to the space names somespace in a screen app:

export const App = () => {
  const pub = usePublish();

  const send = useCallback(() => {
    pub('somespace/Some.MessageType', {payload: "goes here"});
  }, [pub]);
  ...
  return <button onClick={send} />
}

As you can see, to send a message to a space, just prefix it with the name of the space and add slash.
Note that you can still send messages without prefix, they will be sent to the default space (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('somespace/Another.MessageType', (payload) => {
    setData(payload);
  }, [setData])

  return <div>{data}</div>
} 

So, to subscribe to a message in somespace, just add a prefix to message type when calling useSubscribe

Same rules apply to modules/IoT apps. When communicating with the default space, don't use the prefix. When talking to a space, add space name before an event type.

Usage

The idea behind spaces is messages are processed differently in different spaces:

  • message - this is default space, apps and modules on the same device can communicate with each other thru it. Messages do not leave the device.

  • localnet - messages will be automatically send to any GridOS devices in the same local network. This requires messaging module.

  • remote - messages will be forwarded to a connected mobile remote app. Mobile remote app cannot write to the default space, it can only use remote. Requires messaging 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 space, it can only use mobileapp. Requires mobileapp module.

  • pubnub - messages are broadcasted between devices via pubnub service. Requires messaging module. PubKey and SubKey settings should be entered in module settings on each connected device.

  • No labels