-
Notifications
You must be signed in to change notification settings - Fork 14
Publish Subscribe on the Web side
Guillaume Gendre edited this page Jun 7, 2019
·
9 revisions
This page is part of the Cobalt Publish/Subscribe pages. Don't miss the others.
- Introduction to Cobalt PubSub messages
- Publish/Subscribe on Android
- Publish/Subscribe on iOS
- Web Lifecycle messages
Publish a JSON message to the specified channel.
-
channel
: (string) The name of the channel in which you want to send your message. -
message
: (JSON object) The message that will be sent in the channel.
cobalt.publish("myChannel",{
myValue : 42,
anotherValue : "foo"
});
Subscribe the current WebView to messages in the specified channel.
-
channel
: (string) The name of the channel you want to subscribe. -
callback
: (function) A javascript function to handle the messages when they'll come. This function receives one parameter : the message sent (JSON object).
cobalt.subscribe("myChannel",function(message){
cobalt.log('received something on myChannel', message);
});
You can only set one listener for your webview. if you subscribe multiple time, only the latest listener will be called.
Unsubscribe the current WebView to messages from the specified channel.
-
channel
: (string) The name of the channel you want to unsubscribe.
cobalt.unsubscribe("myChannel");
Cobalt is an Open-Source Hybrid Mobile Framework. Read more about it on the home page or in the documentation
- Introduction to Cobalt navigation
- The cobalt.json file
- native navigation bars
- Handling the Android back button
- Introduction to Cobalt messages
- Publish/Subscribe on the Web side
- Publish/Subscribe on Android
- Publish/Subscribe on iOS
- Web Lifecycle messages
- Pull-To-Refresh and Infinite Scroll
- Custom alerts and Toasts
- LocalStorage
- OpenExternalUrl
- PlatformInfos
- Ajax
- Removing the top bar
- Adding Cobalt to an existing project
- Customizing your hybrid views
- Handle multiple Cobalt webviews on the same screen (TODO)