Open farfromrefug opened 5 years ago
@farfromrefug that is awesome
! I will write something up in the next days, ok?
@LukasBombach Whenever you have the time. I have something working already.
@LukasBombach any news on this? Would still like to go and test the integration with your package for Nativescript
@farfromrefug oh sht sorry, I did not get to this. So:
Any adapter must expose this public API:
type PUUID = string;
type SUUID = BluetoothServiceUUID;
type CUUID = BluetoothCharacteristicUUID;
/*
Params<"discover">
is an array that has the following fields:
[
peripheralUuid: string,
address: string,
addressType: AddressType,
connectable: boolean,
advertisement: Advertisement,
rssi: number
];
you can read about the Events and Listeners here
https://gist.github.com/LukasBombach/55bdc0593c79138d6df5763b9ebb33b8
The keys are the event names, the values are the listeners that are expected for this event, by which I mean the params you see in a function next to the event are the params an event listener will receive for that event.
*/
class SblendidAdapter {
public static powerOn(): Promise<void> {}
public static powerOff(): Promise<void> {}
public startScanning(): void {}
public stopScanning(): void {}
public find(condition: FindCondition): Promise<Params<"discover">> {}
public connect(pUUID: PUUID): Promise<void> {}
public disconnect(pUUID: PUUID): Promise<void> {}
public getServices(pUUID: PUUID): Promise<SUUID[]> {}
public getRssi(pUUID: PUUID): Promise<number> {}
public on<E extends Event>(event: E, listener: Listener<E>): void {}
public off<E extends Event>(event: E, listener: Listener<E>): void {}
public getCharacteristics(
pUUID: PUUID,
sUUID: SUUID,
): Promise<CharacteristicData[]> {}
public read(pUUID: PUUID, sUUID: SUUID, cUUID: CUUID): Promise<Buffer> {}
public write(
pUUID: PUUID,
sUUID: SUUID,
cUUID: CUUID,
value: Buffer,
withoutResponse = false,
): Promise<void> {}
public notify(
pUUID: PUUID,
sUUID: SUUID,
cUUID: CUUID,
notify: boolean,
): Promise<boolean> {}
}
See https://github.com/LukasBombach/sblendid/blob/master/packages/adapter-node/src/index.ts#L15
This definition is TypeScript, but of course you can write this in JavaScript, it just shows you what to return and which types of parameters to expect. I know this is a bit much and I hope you are comfortable with this notation, but I am happy to take questions. I definitely want to rework this at some point, which is the first reason why I was so reluctant to answer your question.
The second reason is because I have no API for integrating 3rd party adapters into sblendid, but I definitely intend to.
I was thinking maybe it should be possible to do this
import Sblendid from "@sblendid/sblendid";
import NativeScriptAdapter from "your-native-script-adapter";
Sblendid.setAdapter(NativeScriptAdapter);
What do you think?
@LukasBombach seems perfect. need to find time to work on this. One thought though. I am a little bit worried about what would be included (webpack wise) in my mobile app. I see that the node adapter is always required here which means that it would get included in my mobile app. I don't want that ;)
don't worry, that is only there because there are no other platforms yet. The reason I split sblendid into multiple modules like
@sblendid/sblendid
@sblendid/node-adapter
is exactly for that reason.
In the end I want to have a package structure like this:
@sblendid/sblendid
@sblendid/adapter-node
@sblendid/adapter-web
@sblendid/adapter-ios
@sblendid/adapter-android
and because this will be annoying for users I'd like to only have those as internal packages and for users provide packages like
sblendid
sblendid-web
sblendid-react-native
sblendid-native-script
which are just wrappers and combinations of the @sblendid
packages
and to achieve all this I need to provide a solid API to connect sblendid (the library) with adapters, which i don't have yet. And this is quite crucial because with noble
you can see that as time goes by there is a big need for 3rd party adapters from the community.
If you have any ideas how you would like to integrate your adapter with sblendid please shoot
Ok I am OK with 2 packages: @sblendid/adapter-nativescript sblendid-nativescript Need to find time to write it now ;)
👌
Very interested by your project! I already have a plugin for the Nativescript cross-platform framework (kind of like React Native but so much better :P) I would love to try and write an adapter for your plugin. Could you guide me a bit?
PS: I only need to write JS, no need for ObjC or Java code.