Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CloverConnector connecting to Clover Mini before calling initializeConnection #143

Closed
DyegoCosta opened this issue Apr 23, 2018 · 8 comments

Comments

@DyegoCosta
Copy link

SDK v1.4.2

I just noticed the CloverConnector is establishing a connection with the Clover Mini right after I add any listener to it, before calling ICloverConnector#initializeConnection.

To reproduce:

  1. Instantiate CloverConnector
  2. Add a sales listener to it (e.g)
  3. Wait for the onDeviceReady to be called
  4. Call ICloverConnector#sale
  5. Proceed with the sale normally (no initializeConnection called)

Is this the expected behaviour? If so, what should initializeConnection be used for?

@DyegoCosta DyegoCosta changed the title CloverConnector connecting to Clover Mini before without calling initializeConnection CloverConnector connecting to Clover Mini before calling initializeConnection Apr 23, 2018
@david-clover-com
Copy link
Contributor

@DyegoCosta, no, this is not the expected behavior and I cannot reproduce it. Using the remote-pay-cloud-starter I commented out the line where initializeConnection is called as expected onDeviceReady is never called. There must be something else going on.

@DyegoCosta
Copy link
Author

@david-clover-com Thanks, I found the issue!

I was calling initialize on the connector so I could start listen to it's logger before calling initializeConnection.

const newCloverConnector = (rawDeviceConfig) => {
  const cloverConnectorFactory = buildConnectorFactory()
  const deviceConfig = buildCloverDeviceConfig(rawDeviceConfig)

  const connector = cloverConnectorFactory.createICloverConnector(deviceConfig)
  connector.initialize(deviceConfig)
  connector.device.logger.on('log', logCloverDeviceMessage.bind(this, connector))

  return connector
}

Do you have any tip on how to properly listen to the Connector's logs? Or should it be done like that after initializeConnection?

@david-clover-com
Copy link
Contributor

Does:
clover.DebugConfig.loggingEnabled = true;

work for you?

@DyegoCosta
Copy link
Author

@david-clover-com I already do that, and it works to send logs to the console, but I need a way to listen to the logs so I can redirect them to a log management service provider.

Something like this:

  connector.device.logger.on('log', logCloverDeviceMessage.bind(this, connector))

^ this works but with the side effect of initializing the connection early

@david-clover-com
Copy link
Contributor

david-clover-com commented Apr 23, 2018

I see. The short answer is that because the device is not created until initialize/initializeConnection is called, you cannot cleanly intercept calls to the device's logger before that time. This is probably the approach you want to take as the logging you may miss is likely minimal and not material. The long, ugly, and not recommended answer is that the Logger is publicly exposed and could be intercepted. However this would introduce an ugly dependency on the Connector's inner API. Something like this should work:

  const logCreator = clover.Logger["create"];
        clover.Logger["create"] = () => {
            const log = logCreator();
            log.on("log", () => {
                 // intercept hook, 'arguments' will contain the info being logged.
            });
            return log;
        };

@DyegoCosta
Copy link
Author

Thanks @david-clover-com! I'll weight my options here after some tests.

It would be great if the SDK provided a more straight forward logging API. I see there's a lot of logger instances and took me a while to find the correct one I want to watch. (e.g connector.logger, connector.broadcaster.logger, connector.device.logger.

@david-clover-com
Copy link
Contributor

Thanks for the feedback. I created an internal issue for us to improve our log framework.

@DyegoCosta
Copy link
Author

@david-clover-com I noticed we can use onDeviceConnected and get the same result I had before doing the early initialization. We'll get all the entries of the WS.

screenshot 2018-04-23 17 05 19

david-clover-com pushed a commit that referenced this issue Sep 12, 2018
* Final publish release pipeline
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants