modules/json/docs/transport.md
The Transport base class is intended to abstract a number of client-host communication mechanisms.
The basic pattern is that the application registers callbacks to listen for connections, messages and disconnections. Note that the application should not assume that there is only a single connection. There can be multiple remote connections at one time (i.e. multiple cells in a Jupyter Notebook, or multiple UIWebWidgets in an iOS app), which can be tracked by listening to the onInitialize and onFinalize events.
Some examples of communication mechanisms that could be managed via the Transport API:
postMessage based communication between tabs and iframesWebView componentUIWebView componentListening to transport connections, disconnections and messages
Transport.setCallbacks({
onInitialize: (message) => console.log('A new transport connected'),
onFinalize: (message) => console.log('A transport disconnected'),
onMessage: (message) => console.log('A message arrived on a connection')
});
The following callbacks can be set:
callbacks.onInitializecallbacks.onMessagecallbacks.onFinalizeNote: The
Transportclass should not be instantiated explicitly by JavaScript applications.Transportinstances are automatically created.
Longer term goals:
WebSocket based transport