-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
198 lines (183 loc) · 4.6 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
import { Platform, NativeEventEmitter, NativeModules } from "react-native";
import {
Capture,
SktErrors,
CapturePropertyIds,
CapturePropertyTypes,
CaptureProperty,
CaptureEventIds,
CaptureEventTypes,
CaptureEvent,
CaptureDeviceType,
CaptureDataSourceID,
CaptureDataSourceFlags,
CaptureDataSourceStatus,
DataConfirmationMode,
DeviceDataAcknowledgment,
SecurityMode,
Trigger,
DeletePairing,
SoundActionType,
SoundFrequency,
RumbleActionType,
LocalDecodeAction,
DataConfirmationLed,
DataConfirmationBeep,
DataConfirmationRumble,
Flash,
SoftScan,
PowerState,
MonitorDbg,
Counter,
Disconnect,
ProfileSelect,
ProfileConfig,
Notifications,
Timer,
DataFormat,
TriggerMode,
ConnectReason,
StartUpRoleSpp,
ConnectBeepConfig,
StandConfig,
} from "socketmobile-capturejs";
const SocketCamTypes = [CaptureDeviceType.SocketCamC820];
const NFCDeviceTypes = [
CaptureDeviceType.ScannerS370,
CaptureDeviceType.ScannerS550,
];
const { NativeCaptureModule } = NativeModules;
let eventEmitter = new NativeEventEmitter(NativeCaptureModule);
const onCaptureEvent = (e) => {
// maybe need to access handle here but this one doesn't get called in Android.
console.log("index onCaptureEvent: ", e);
if (NativeCaptureModule.logger) {
NativeCaptureModule.logger.log("<= ", e);
}
const event = JSON.parse(e);
if (NativeCaptureModule.onNotification) {
NativeCaptureModule.onNotification(event);
}
};
const subscription = eventEmitter.addListener("onCaptureEvent", onCaptureEvent);
NativeCaptureModule.open = (host, notification) => {
NativeCaptureModule.onNotification = notification;
return NativeCaptureModule.openTransport(host).then(
(result) => result.transport
);
};
NativeCaptureModule.send = (handle, jsonRpc) => {
NativeCaptureModule.logger.log("=> ", jsonRpc);
return NativeCaptureModule.sendTransport(
handle,
JSON.stringify(jsonRpc)
).then((response) => {
NativeCaptureModule.logger.log("<= ", response);
return JSON.parse(response);
});
};
NativeCaptureModule.close = (handle) => {
subscription.remove();
return NativeCaptureModule.closeTransport(handle);
};
const getOptions = (platform, options, logger) => {
const final = options || {};
const noLogger = { log: () => {} };
CaptureAppOS = platform.OS;
if (platform.OS === "ios") {
NativeCaptureModule.logger = logger || noLogger;
final.transport = NativeCaptureModule;
} else {
NativeCaptureModule.startCaptureService();
}
return final;
};
class CaptureRn extends Capture {
constructor(logger) {
super(logger);
}
openForAndroid(tries, appInfo, callback, options) {
const promise = new Promise((resolve, reject) => {
let interval;
const openRetry = () => {
clearInterval(interval);
super
.open(appInfo, callback, options)
.then((result) => resolve(result))
.catch((err) => {
console.log("android retry error: ", err);
if (tries > 0) {
tries -= 1;
interval = setInterval(openRetry, 250);
} else {
reject(err);
}
});
};
interval = setInterval(openRetry, 250);
});
return promise;
}
open(appInfo, callback, options) {
const finalOptions = getOptions(Platform, options, this.logger);
if (Platform.OS === "android") {
var newAppInfo = genAppInfo(appInfo, true);
return this.openForAndroid(10, newAppInfo, callback, options);
}
var newAppInfo = genAppInfo(appInfo);
return super.open(newAppInfo, callback, finalOptions);
}
}
const genAppInfo = (appInfo, isAndroid) => {
var id = isAndroid ? "appIdAndroid" : "appIdIos";
var key = isAndroid ? "appKeyAndroid" : "appKeyIos";
return {
...appInfo,
appId: appInfo[id] || appInfo.appId,
appKey: appInfo[key] || appInfo.appKey,
};
};
export {
CaptureRn,
SktErrors,
CapturePropertyIds,
CapturePropertyTypes,
CaptureProperty,
CaptureEventIds,
CaptureEventTypes,
CaptureEvent,
CaptureDeviceType,
CaptureDataSourceID,
CaptureDataSourceFlags,
CaptureDataSourceStatus,
DataConfirmationMode,
DeviceDataAcknowledgment,
SecurityMode,
Trigger,
DeletePairing,
SoundActionType,
SoundFrequency,
RumbleActionType,
LocalDecodeAction,
DataConfirmationLed,
DataConfirmationBeep,
DataConfirmationRumble,
Flash,
SoftScan,
PowerState,
MonitorDbg,
Counter,
Disconnect,
ProfileSelect,
ProfileConfig,
Notifications,
Timer,
DataFormat,
TriggerMode,
ConnectReason,
StartUpRoleSpp,
ConnectBeepConfig,
StandConfig,
SocketCamTypes,
NFCDeviceTypes,
};