-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnfc.ts
More file actions
50 lines (44 loc) · 1.42 KB
/
nfc.ts
File metadata and controls
50 lines (44 loc) · 1.42 KB
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
import bridge from '@expressms/smartapp-bridge'
import { ERROR_CODES, METHODS, NfcReadTagResponse, NfcStatusResponse, NfcWriteMessage, StatusResponse } from '../../types'
/**
* Read NFC tag
* @returns Promise that'll be fullfilled with `payload.nfcTag` on success, otherwise rejected with reason
*/
export const readTag = (): Promise<NfcReadTagResponse> => {
if (!bridge) return Promise.reject(ERROR_CODES.NO_BRIDGE)
return bridge
.sendClientEvent({
method: METHODS.READ_NFC_TAG,
params: {},
})
.then(event => event as NfcReadTagResponse)
}
/**
* Write NFC tag
* @param messages List of messages to be wtitten
* @returns Promise that'll be fullfilled on success, otherwise rejected with reason
*/
export const writeTag = (messages: Array<NfcWriteMessage>): Promise<StatusResponse> => {
if (!bridge) return Promise.reject(ERROR_CODES.NO_BRIDGE)
return bridge
.sendClientEvent({
method: METHODS.WRITE_NFC_TAG,
params: {
messages,
},
})
.then(event => event as StatusResponse)
}
/**
* Check NFC reader status
* @returns Promise that'll be fullfilled on success, otherwise rejected with reason
*/
export const getStatus = (): Promise<NfcStatusResponse> => {
if (!bridge) return Promise.reject(ERROR_CODES.NO_BRIDGE)
return bridge
.sendClientEvent({
method: METHODS.GET_NFC_STATUS,
params: {},
})
.then(event => event as NfcStatusResponse)
}