question

junsuhlee94 avatar image
junsuhlee94 asked David Marginian Deactivated commented

How to implement reconnect logic for remote pay cloud?

I'm using Javascript SDK for remote-pay-cloud and sometimes experiencing the disconnection, which is understandable. I wonder how to implement the reconnect logic so that my app can 'try hard' to maintain the healthy connection.

This is what I've tried. OnDisconnected, I tried calling 'initializeConnection()' again. But I got

error Cannot send message, transport is null: {"id":"4","type":"COMMAND","packageName":"com.clover.remote.protocol.websocket","method":"DISCOVERY_REQUEST","payload":"{\"method\":\"DISCOVERY_REQUEST\",\"version\":0,\"supportsOrderModification\":false}","remoteSourceSDK":"com.clover.cloverconnector.cloud:3.1.0","remoteApplicationID":"17GTAPT6R62MP","version":2}
I also put .setReconnectDelay(3000) as well when initial connection, but looks like it is not really retrying connection when disconnected.

It would be great if you can help me building good reconnection logic!
Remote Pay CloudCloud Pay Display
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

David Marginian avatar image
David Marginian Deactivated answered David Marginian Deactivated commented
Don't do that, the newest version of the SDK will reconnect. Just make sure you set the heartbeatInterval on the connection configuration. This will enable a ping from the SDK to the device and the SDK will retry for you automatically if a pong is not received. Please see our docs and use the builder for creating your connection - https://docs.clover.com/clover-platform/docs/cloud-sdk-v3.
11 comments
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

sergiotr avatar image sergiotr commented ·

Does this applies also for iOS SKD?

0 Likes 0 ·
David Marginian avatar image David Marginian ♦♦ sergiotr commented ·

I don't know much about iOS SDK. I assume that by default it will do what it can to maintain the connection but probably doesn't have the same configuration options (heartbeatInterval). I can get more information from your from the iOS team if you are seeing issues.

0 Likes 0 ·
sergiotr avatar image sergiotr David Marginian ♦♦ commented ·

Thanks for your response David, I would appreciate your help,
Currently on reconnect logic I´m calling initializeConnection, I dont see heartbeatInterval option.

0 Likes 0 ·
Show more comments
junsuhlee94 avatar image
junsuhlee94 answered junsuhlee94 commented
@David Marginian

Thank you so much for quick reply.
I've set heartbeat, however this is what I've been getting it.

First,
onDeviceDisconnected

and then
onDeviceError CloverDeviceErrorEvent { "_class_": [Function CloverDeviceErrorEvent], "cause": null, "code": "NotConnected", "message": "In showWelcomeScreen: Device is not connected.", "type": "COMMUNICATION", }
above is perhaps because my app tried to show some screen, which is fine. And then I think the next is something that SDK do for retry?

error Cannot send message, transport is null: {"id":"8","type":"COMMAND","packageName":"com.clover.remote.protocol.websocket","method":"DISCOVERY_REQUEST","payload":"{\"method\":\"DISCOVERY_REQUEST\",\"version\":0,\"supportsOrderModification\":false}","remoteSourceSDK":"com.clover.cloverconnector.cloud:3.1.0","remoteApplicationID":,"version":2}

Those are what I got when I set the heartbeat

2 comments
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

David Marginian avatar image David Marginian ♦♦ commented ·

Are you still calling initialize connection in the disconnect handler? Don't do that. Also do not call dispose on the connector in an attempt to recover. It looks like you may be doing this in onDeviceError (the only place the transport is nulled out is in dispose). You should only call initialize connection once and dispose once (generally before the browser unloads).

0 Likes 0 ·
junsuhlee94 avatar image junsuhlee94 David Marginian ♦♦ commented ·

You are right! I found the part that I was doing dispose() and removed that

0 Likes 0 ·

Welcome to the
Clover Developer Community