- connect to WebSocket/STOMP (
/wswith SockJS fallback to/sock) - subscribe to the default topics (
/topic/msm/*and/user/topic/msm/*) - publish SSR render and JSON requests
Setup
Include the bundle and initialize the app:MSM2.App opens the WebSocket connection automatically and registers default listeners for HTML and JSON responses.
Initialize with msm-framework-js
When the library is loaded as a separate browser script, create the client after it has loaded. Pass the WebSocket endpoint of your application:
wss://music.mastermindcms.com with your application’s WebSocket URL. In a bundler, you can add msm-framework-js as a dependency and use the same new MSM2.App(...) call.
Calling APIs
After initialization,MSM2App exposes convenience methods for the two WebSocket request styles:
- render (SSR):
renderPage,renderElement,invokeAndRender,updateBeanAndRender,addToRepositoryAndRender,saveToRepositoryAndRender,removeFromRepositoryAndRender,addDocumentAndRender,removeDocumentAndRender - JSON:
invoke,invokeAndGetJson$,updateBeanAndGetJson$, repository calls, and database document calls
Example: SSR render
Example: call a backend service and get JSON
Example: custom topic subscription
If your backend publishes custom events under/topic/**, you can register an additional listener:
Notes
- For JSON calls, use
actionIdcorrelation if you are building your own request messages. When usinginvokeAndGetJson$and similar helpers, the client generatesactionIdautomatically. - Authorization can be done via session/remember-me cookies or via JWT, depending on your configuration.