Creatio mobile - websocket

Hi, is there any method to establish a WebSocket connection between the Creatio server and the Creatio mobile app (exactly as in the browser version)? At a minimum, the mobile app could poll the server in a loop, but unfortunately there is a problem with that too, since neither setTimeout nor setInterval are available (as I described in this post: https://community.creatio.com/questions/creatio-mobile-app-use-settimeout-or-setinterval).

Like 0

Like

2 comments

Hello,

This can be implemented using the MessageChannelService. To proceed, please import the Creatio DevKit SDK, choose the appropriate location in your code to handle subscription and unsubscription, and utilize the sdk.MessageChannelService accordingly.

Please note that this approach is supported starting from version 8.2.0 and later.

Basic subscription example:

handlers: /**SCHEMA_HANDLERS*/[
	{
		request: "crt.HandleViewModelResumeRequest",
		handler: async function (request, next) {
			const messageChannelService = new sdk.MessageChannelService();

			request.$context.MySubscription = await messageChannelService.subscribe(
				"TestSender",
				(message) => console.log(message.body)
			);

			return next?.handle(request);
		}
	},
	{
		request: "crt.HandleViewModelPauseRequest",
		handler: async function (request, next) {
			const subscription = await request.$context.MySubscription;
			subscription.unsubscribe();

			return next?.handle(request);
		}
	}
]/**SCHEMA_HANDLERS*/

Basic sending example:

handlers: /**SCHEMA_HANDLERS*/[
	{
		request: "crt.HandleViewModelInitRequest",
		handler: async (request, next) => {
			const messageChannelService = new sdk.MessageChannelService();

			const body = {
				// Some data
			};

			await messageChannelService.sendMessage(
				"TestSender",
				body,
				sdk.MessageChannelType.PTP
			);

			return next?.handle(request);
		}
	}
]/**SCHEMA_HANDLERS*/

Hi, thanks for the reply, but I believe your example is for the Web Creatio, while my question was about the mobile app :)

Show all comments