如何使用ONLY节点连接到Clover mini设备?

我对Node相当陌生,而且我试图通过使用Clover提供的API的websocket连接到Clover Mini设备。

我已经尝试修改下面的示例代码来使用只有节点,但是当我在节点中打开它没有任何反应。 (没有错误,没有任何反应)

它在Chrome中工作得很好,所以缺less什么?

https://github.com/clover/remote-pay-cloud

var $ = require('jQuery'); var clover = require("remote-pay-cloud"); var log = clover.Logger.create(); var connector = new clover.CloverConnectorFactory().createICloverConnector({ "oauthToken": "1e7a9007-141a-293d-f41d-f603f0842139", "merchantId": "BBFF8NBCXEMDV", "clientId": "3RPTN642FHXTX", "remoteApplicationId": "com.yourname.yourapplication:1.0.0-beta1", "deviceSerialId": "C031UQ52340015", "domain": "https://sandbox.dev.clover.com/" }); var ExampleCloverConnectorListener = function(cloverConnector) { clover.remotepay.ICloverConnectorListener.call(this); this.cloverConnector = cloverConnector; }; ExampleCloverConnectorListener.prototype = Object.create(clover.remotepay.ICloverConnectorListener.prototype); ExampleCloverConnectorListener.prototype.constructor = ExampleCloverConnectorListener; ExampleCloverConnectorListener.prototype.onReady = function (merchantInfo) { var saleRequest = new clover.remotepay.SaleRequest(); saleRequest.setExternalId(clover.CloverID.getNewId()); saleRequest.setAmount(10000); this.cloverConnector.sale(saleRequest); }; ExampleCloverConnectorListener.prototype.onVerifySignatureRequest = function (request) { log.info(request); this.cloverConnector.acceptSignature(request); }; ExampleCloverConnectorListener.prototype.onConfirmPaymentRequest = function (request) { this.cloverConnector.acceptPayment(request.payment); }; ExampleCloverConnectorListener.prototype.onSaleResponse = function (response) { log.info(response); connector.dispose(); if(!response.getIsSale()) { console.error("Response is not an sale!"); console.error(response); } }; var connectorListener = new ExampleCloverConnectorListener(connector); connector.addCloverConnectorListener(connectorListener); connector.initializeConnection(); 

       

网上收集的解决方案 "如何使用ONLY节点连接到Clover mini设备?"

在与三叶草的开发人员接触后,他们的文档有一些错误。 对于其他用户来说,这里是在他们的gitub上的这个问题的链接以及一些示例代码。

链接到github问题

 const endpoint = "ws://yourip:yourport/remote_pay"; var webSocketFactory = function () { let webSocketOverrides = { createWebSocket: function () { // To support self-signed certificates you must pass rejectUnauthorized = false. // https://github.com/websockets/ws/blob/master/examples/ssl.js let sslOptions = { rejectUnauthorized: false }; // Use the ws library by default. return new WebSocket(endpoint, sslOptions); } } return Object.assign(new clover.CloverWebSocketInterface(endpoint), webSocketOverrides); }; var ExampleWebsocketPairedCloverDeviceConfiguration = function () { clover.WebSocketPairedCloverDeviceConfiguration.call(this, endpoint, // endpoint "com.cloverconnector.javascript.simple.sample:1.4", // Application Id "Javascript Simple Sample", // posName "Register_1", // serialNumber null, // authToken().get( webSocketFactory, new clover.ImageUtil()); };