Skip to content

Commit 2e50067

Browse files
fix(bluetooth-classic-serial-port): support multiple simultaneous connections using the same protocol string (#5056)
* fix(bluetooth-classic-serial-port): update plugin * Update src/@awesome-cordova-plugins/plugins/bluetooth-classic-serial-port/index.ts Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> * Update src/@awesome-cordova-plugins/plugins/bluetooth-classic-serial-port/index.ts Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> * Update src/@awesome-cordova-plugins/plugins/bluetooth-classic-serial-port/index.ts Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> * Update src/@awesome-cordova-plugins/plugins/bluetooth-classic-serial-port/index.ts Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> * Update src/@awesome-cordova-plugins/plugins/bluetooth-classic-serial-port/index.ts Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent a2a80d1 commit 2e50067

File tree

1 file changed

+58
-65
lines changed
  • src/@awesome-cordova-plugins/plugins/bluetooth-classic-serial-port

1 file changed

+58
-65
lines changed

src/@awesome-cordova-plugins/plugins/bluetooth-classic-serial-port/index.ts

Lines changed: 58 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,21 @@ export interface BluetoothClassicSerialPortDevice {
2222
*
2323
*
2424
* // Write a string
25-
* this.bluetoothClassicSerialPort.write("00001101-0000-1000-8000-00805F9B34FB", "hello, world", success, failure);
25+
* this.bluetoothClassicSerialPort.write(deviceId, "00001101-0000-1000-8000-00805F9B34FB", "hello, world", success, failure);
2626
*
2727
* // Array of int or bytes
28-
* this.bluetoothClassicSerialPort.write("00001101-0000-1000-8000-00805F9B34FB", [186, 220, 222], success, failure);
28+
* this.bluetoothClassicSerialPort.write(deviceId, "00001101-0000-1000-8000-00805F9B34FB", [186, 220, 222], success, failure);
2929
*
3030
* // Typed Array
3131
* var data = new Uint8Array(4);
3232
* data[0] = 0x41;
3333
* data[1] = 0x42;
3434
* data[2] = 0x43;
3535
* data[3] = 0x44;
36-
* this.bluetoothClassicSerialPort.write(interfaceId, data, success, failure);
36+
* this.bluetoothClassicSerialPort.write(deviceId, interfaceId, data, success, failure);
3737
*
3838
* // Array Buffer
39-
* this.bluetoothClassicSerialPort.write(interfaceId, data.buffer, success, failure);
39+
* this.bluetoothClassicSerialPort.write(deviceId, interfaceId, data.buffer, success, failure);
4040
* ```
4141
*
4242
* // iOS select accessory
@@ -76,61 +76,42 @@ export class BluetoothClassicSerialPort extends AwesomeCordovaNativePlugin {
7676
/**
7777
* Connect to a Bluetooth device
7878
*
79-
* @param {string} deviceId Identifier of the remote device.
80-
* @param {string} deviceId this is the MAC address.
81-
* @param {string|string[]} interfaceId Identifier of the remote device
82-
* @param {string|string[]} interfaceId This identifies the serial port to connect to.
79+
* @param deviceId Identifier of the remote device.
80+
* @param interfaceArray This identifies the serial port to connect to.
8381
* @returns {Observable<any>} Subscribe to connect.
8482
*/
8583
@Cordova({
8684
platforms: ['Android', 'iOS'],
8785
observable: true,
8886
})
89-
connect(deviceId: string | number, interfaceId: string | string[]): Observable<any> {
90-
return;
91-
}
92-
93-
/**
94-
* Connect to a Bluetooth device
95-
*
96-
* @deprecated
97-
* @param {string} deviceId Identifier of the remote device.
98-
* @param {number} deviceId this is the connection ID
99-
* @param {string|string[]} interfaceArray Identifier of the remote device
100-
* @param {string|string[]} interfaceArray this is the Protocol String
101-
* @returns {Promise<any>}
102-
*/
103-
@Cordova({
104-
platforms: ['iOS'],
105-
methodName: 'connect',
106-
})
107-
connectIos(deviceId: string | number, interfaceArray: string | string[]): Promise<any> {
87+
connect(deviceId: string | number, interfaceArray: string[]): Observable<any> {
10888
return;
10989
}
11090

11191
/**
11292
* Connect insecurely to a Bluetooth device
11393
*
114-
* @param {string} deviceId Identifier of the remote device. For Android this is the MAC address
115-
* @param {string | string[]} interfaceArray This identifies the serial port to connect to. For Android this is the SPP_UUID.
94+
* @param deviceId Identifier of the remote device. For Android this is the MAC address
95+
* @param interfaceArray This identifies the serial port to connect to. For Android this is the SPP_UUID.
11696
* @returns {Promise<any>} Subscribe to connect.
11797
*/
11898
@Cordova({
11999
platforms: ['Android'],
120100
observable: true,
121101
})
122-
connectInsecure(deviceId: string, interfaceArray: string | string[]): Promise<any> {
102+
connectInsecure(deviceId: string | number, interfaceArray: string[]): Observable<any> {
123103
return;
124104
}
125105

126106
/**
127107
* Disconnect from the connected device
128108
*
129-
* @param {string} interfaceId The interface to Disconnect
109+
* @param deviceId Identifier of the remote device. For Android this is the MAC address
110+
* @param interfaceId The interface to Disconnect
130111
* @returns {Promise<any>}
131112
*/
132113
@Cordova()
133-
disconnect(interfaceId: string | string[]): Promise<any> {
114+
disconnect(deviceId: string | number, interfaceId: string): Promise<any> {
134115
return;
135116
}
136117

@@ -139,157 +120,169 @@ export class BluetoothClassicSerialPort extends AwesomeCordovaNativePlugin {
139120
*
140121
* @returns {Promise<any>}
141122
*/
142-
@Cordova({
143-
methodName: 'connect',
144-
})
123+
@Cordova()
145124
disconnectAll(): Promise<any> {
146125
return;
147126
}
148127

149128
/**
150129
* Writes data to the serial port
151130
*
152-
* @param {string} interfaceId The interface to send the data to
153-
* @param {ArrayBuffer | string | number[] | Uint8Array} data ArrayBuffer of data
131+
* @param deviceId Identifier of the remote device. For Android this is the MAC address
132+
* @param interfaceId The interface to send the data to
133+
* @param data ArrayBuffer of data
154134
* @returns {Promise<any>} returns a promise when data has been written
155135
*/
156136
@Cordova({
157137
platforms: ['Android', 'iOS', 'Browser'],
158138
})
159-
write(interfaceId: string, data: ArrayBuffer | string | number[] | Uint8Array): Promise<any> {
139+
write(
140+
deviceId: string | number,
141+
interfaceId: string,
142+
data: ArrayBuffer | string | number[] | Uint8Array
143+
): Promise<any> {
160144
return;
161145
}
162146

163147
/**
164148
* Gets the number of bytes of data available
165149
*
166-
* @param {string} interfaceId The interface to check
150+
* @param deviceId Identifier of the remote device. For Android this is the MAC address
151+
* @param interfaceId The interface to check
167152
* @returns {Promise<any>} returns a promise that contains the available bytes
168153
*/
169154
@Cordova({
170155
platforms: ['Android', 'Browser'],
171156
})
172-
available(interfaceId: string): Promise<any> {
157+
available(deviceId: string | number, interfaceId: string): Promise<any> {
173158
return;
174159
}
175160

176161
/**
177162
* Function read reads the data from the buffer. The data is passed to the success callback as a String. Calling read when no data is available will pass an empty String to the callback.
178163
*
179-
* @param {string} interfaceId The interface to read
164+
* @param deviceId Identifier of the remote device. For Android this is the MAC address
165+
* @param interfaceId The interface to read
180166
* @returns {Promise<any>} returns a promise with data from the buffer
181167
*/
182168
@Cordova({
183169
platforms: ['Android', 'iOS', 'Browser'],
184170
})
185-
read(interfaceId: string): Promise<any> {
171+
read(deviceId: string | number, interfaceId: string): Promise<any> {
186172
return;
187173
}
188174

189175
/**
190176
* Reads data from the buffer until it reaches a delimiter
191177
*
192-
* @param {string} interfaceId The interface to read
193-
* @param {string} delimiter string that you want to search until
178+
* @param deviceId Identifier of the remote device. For Android this is the MAC address
179+
* @param interfaceId The interface to read
180+
* @param delimiter string that you want to search until
194181
* @returns {Observable<any>} returns a promise
195182
*/
196183
@Cordova({
197184
platforms: ['Android', 'iOS', 'Browser'],
198185
})
199-
readUntil(interfaceId: string, delimiter: string): Observable<any> {
186+
readUntil(deviceId: string | number, interfaceId: string, delimiter: string): Observable<any> {
200187
return;
201188
}
202189

203190
/**
204191
* Subscribe to be notified when data is received
205192
*
206-
* @param {string | string[]} interfaceId The interface to subscribe to
207-
* @param {string} delimiter the string you want to watch for
193+
* @param deviceId Identifier of the remote device. For Android this is the MAC address
194+
* @param interfaceId The interface to subscribe to
195+
* @param delimiter the string you want to watch for
208196
* @returns {Observable<any>} returns an observable.
209197
*/
210198
@Cordova({
211199
platforms: ['Android', 'iOS', 'Browser'],
212200
observable: true,
213201
})
214-
subscribe(interfaceId: string | string[], delimiter: string): Observable<any> {
202+
subscribe(deviceId: string | number, interfaceId: string, delimiter: string): Observable<any> {
215203
return;
216204
}
217205

218206
/**
219207
* Unsubscribe from a subscription
220208
*
221-
* @param {string | string[]} interfaceId The interface to unsubscribe from
222-
* @returns {Promise<any>} returns an promise.
209+
* @param deviceId Identifier of the remote device. For Android this is the MAC address
210+
* @param interfaceId The interface to unsubscribe from
211+
* @returns {Promise<any>} returns a promise.
223212
*/
224213
@Cordova({
225214
platforms: ['Android', 'iOS', 'Browser'],
226215
})
227-
unsubscribe(interfaceId: string | string[]): Promise<any> {
216+
unsubscribe(deviceId: string | number, interfaceId: string): Promise<any> {
228217
return;
229218
}
230219

231220
/**
232221
* Subscribe to be notified when data is received
233222
*
234-
* @param {string | string[]} interfaceId The interface to subscribe to
223+
* @param deviceId Identifier of the remote device. For Android this is the MAC address
224+
* @param interfaceId The interface to subscribe to
235225
* @returns {Observable<any>} returns an observable
236226
*/
237227
@Cordova({
238228
platforms: ['Android', 'iOS', 'Browser'],
239229
observable: true,
240230
})
241-
subscribeRawData(interfaceId: string | string[]): Observable<any> {
231+
subscribeRawData(deviceId: string | number, interfaceId: string): Observable<any> {
242232
return;
243233
}
244234

245235
/**
246236
* Unsubscribe from a subscription
247237
*
248-
* @param {string | string[]} interfaceId The interface to unsubscribe from
249-
* @returns {Promise<any>} returns an promise.
238+
* @param deviceId Identifier of the remote device. For Android this is the MAC address
239+
* @param interfaceId The interface to unsubscribe from
240+
* @returns {Promise<any>} returns a promise.
250241
*/
251242
@Cordova({
252243
platforms: ['Android', 'iOS', 'Browser'],
253244
})
254-
unsubscribeRawData(interfaceId: string | string[]): Promise<any> {
245+
unsubscribeRawData(deviceId: string | number, interfaceId: string): Promise<any> {
255246
return;
256247
}
257248

258249
/**
259250
* Clears data in buffer
260251
*
261-
* @param {string} interfaceId The interface to clear data
252+
* @param deviceId Identifier of the remote device. For Android this is the MAC address
253+
* @param interfaceId The interface to clear data
262254
* @returns {Promise<any>} returns a promise when completed
263255
*/
264256
@Cordova({
265257
platforms: ['Android', 'iOS', 'Browser'],
266258
})
267-
clear(interfaceId: string): Promise<[]> {
259+
clear(deviceId: string | number, interfaceId: string): Promise<[]> {
268260
return;
269261
}
270262

271263
/**
272-
* Lists bonded devices
264+
* Reports the connection status
273265
*
274-
* @returns {Promise<BluetoothClassicSerialPortDevice>} returns a promise
266+
* @param deviceId Identifier of the remote device. For Android this is the MAC address
267+
* @param interfaceId The interface to check
268+
* @returns {Promise<boolean>} returns a promise
275269
*/
276270
@Cordova({
277271
platforms: ['Android', 'iOS', 'Browser'],
278272
})
279-
list(): Promise<BluetoothClassicSerialPortDevice[]> {
273+
isConnected(deviceId: string | number, interfaceId: string): Promise<boolean> {
280274
return;
281275
}
282276

283277
/**
284-
* Reports the connection status
278+
* Lists bonded devices
285279
*
286-
* @param {string} interfaceId The interface to check
287-
* @returns {Promise<boolean>} returns a promise
280+
* @returns {Promise<BluetoothClassicSerialPortDevice>} returns a promise
288281
*/
289282
@Cordova({
290283
platforms: ['Android', 'iOS', 'Browser'],
291284
})
292-
isConnected(interfaceId: string): Promise<boolean> {
285+
list(): Promise<BluetoothClassicSerialPortDevice[]> {
293286
return;
294287
}
295288

0 commit comments

Comments
 (0)