Skip to content

Commit eae9172

Browse files
author
Ivan Kudinov
committed
CCS-105439 Add NFC write method
1 parent 754e475 commit eae9172

File tree

4 files changed

+29
-14
lines changed

4 files changed

+29
-14
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@expressms/smartapp-sdk",
3-
"version": "1.12.0-alpha.13",
3+
"version": "1.12.0-alpha.15",
44
"description": "Smartapp SDK",
55
"main": "build/main/index.js",
66
"typings": "build/main/index.d.ts",

src/lib/devices/nfc.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
import bridge from '@expressms/smartapp-bridge'
2-
import {
3-
ERROR_CODES,
4-
METHODS,
5-
NfcReadTagResponse,
6-
} from '../../types'
2+
import { ERROR_CODES, METHODS, NfcMessage, NfcReadTagResponse, StatusResponse } from '../../types'
73

84
/**
9-
* Enable bluetooth
5+
* Read NFC tag
106
* @returns Promise that'll be fullfilled with `payload.nfcTag` on success, otherwise rejected with reason
117
*/
128
export const readTag = (): Promise<NfcReadTagResponse> => {
@@ -19,3 +15,21 @@ export const readTag = (): Promise<NfcReadTagResponse> => {
1915
})
2016
.then(event => event as NfcReadTagResponse)
2117
}
18+
19+
/**
20+
* Write NFC tag
21+
* @param messages List of messages to be wtitten
22+
* @returns Promise that'll be fullfilled on success, otherwise rejected with reason
23+
*/
24+
export const writeTag = (messages: Array<NfcMessage>): Promise<StatusResponse> => {
25+
if (!bridge) return Promise.reject(ERROR_CODES.NO_BRIDGE)
26+
27+
return bridge
28+
.sendClientEvent({
29+
method: METHODS.WRITE_NFC_TAG,
30+
params: {
31+
messages,
32+
},
33+
})
34+
.then(event => event as StatusResponse)
35+
}

src/types/bridge.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export enum METHODS {
5252
DISCOVER_BLE_GATT_SERVICES = 'discover_ble_gatt_services',
5353
READ_BLE_GATT_CHARACTERISTIC = 'read_ble_gatt_characteristic',
5454
READ_NFC_TAG = 'read_nfc_tag',
55+
WRITE_NFC_TAG = 'write_nfc_tag',
5556
}
5657

5758
export enum STATUS {

src/types/devices.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export type BluetoothErrorCode =
88
| 'ble_device_not_connected'
99
| 'ble_gatt_service_not_found'
1010
| 'ble_gatt_characteristic_not_found'
11+
| 'not_enough_memory'
1112
| 'io_error'
1213
| 'error'
1314

@@ -63,15 +64,9 @@ export interface BluetoothReadBleGattCharacteristicResponse extends EmitterEvent
6364
}
6465
}
6566

66-
6767
export type BleDeviceCallback = (device: BleDevice) => {}
6868

69-
export type NfcErrorCode =
70-
| 'permission_denied'
71-
| 'nfc_not_found'
72-
| 'nfc_write_error'
73-
| 'cancelled_by_user'
74-
| 'error'
69+
export type NfcErrorCode = 'permission_denied' | 'nfc_not_found' | 'nfc_write_error' | 'cancelled_by_user' | 'error'
7570

7671
export type NfcMessage = {
7772
bytes: Array<number>
@@ -87,3 +82,8 @@ export interface NfcReadTagResponse extends EmitterEventPayload {
8782
}
8883
}
8984
}
85+
86+
export interface NfcMessage {
87+
mimeType: string
88+
bytes: number[]
89+
}

0 commit comments

Comments
 (0)