kdeconnect
v1.0.2
Published
KDEConnect bindings for Node
Maintainers
Readme
KDE Connect Bindings for NodeJS
Small script using DBus to allow a NodeJS application to communicate with connected devices via KDE Connect
Requirements
- DBus support
- NodeJS >= 10.8.0
- Linux Desktop with DBus Support
- KDE Connect installed and running
API
The API is written fully in Typescript, so check out the declaration file for additional infos
async getAvailableDevices()
Returns a list of KDEDevices currently known or available
class KDEDevice
Can be manually created or retrieved using getAvailableDevices
Constructor
KDEDevice(id, bus)
| Name | Type | Info |
| ---- | ------------ | ----------------------------------------------------------- |
| id | string | KDE ID, can be stored from old device or retrieved manually |
| bus | MessageBus | optional, DBus-Session to use |
Properties
| Name | Type | Info |
| ------------ | ------------------------------------- | ------------------------------------------------------- |
| id | string | KDE ID |
| name | string | Device Name |
| type | string | smartphone | desktop |
| isReachable | boolean | Is device currently reachable |
| isTrusted | boolean | Is device trusted |
| connectivity | {type: string, strength: number} | cellular data (not wifi) |
| battery | {charge: number, charging: boolean} | battery status |
| media | KDEMediaHandler | Returns a separate handler for media control. See below |
Functions
| Signature | Info |
| ------------------------------------------------------ | --------------------------------------------------------------------------------------------------------- |
| async setup(): Promise<void> | if a device is manually created, using its KDE ID, this must be called befor use |
| async shareFile(filePath: string): Promise<void> | Shares the file from file path with the device (copying it to the previously chosen folder on the device) |
| async shareURL(urL: string): Promise<void> | Shares the url with the device, either as a notification or by directly opening the link |
| async shareText(text: string): Promise<void> | Shares the text with the device, normally copying it into the devices clipboard |
| async ring(): Promise<void> | Lets the device ring |
| async ping(msg?: string): Promise | Sends a notification with an optional message to the device |
|async getNotifications(): Promise<KDENotification[]>| Returns a list of notifications currently present on the device. See below |
|async requestPair(): Promise | Request pairing |
|async unpair(): Promise` | Unpair device |
Events
Every device has an event handler linked to it, accessible by the events Property.
| Event | Values |
| ----------------------- | --------------------------------------- |
| onTrustedChanged | (boolean) |
| onNameChanged | (string) |
| onTypeChanged | (string) |
| onReachableChanged | (boolean) |
| onBatteryChanged | ({charge: number, charging: boolean}) |
| onConnectivityChanged | ({type: string, strength: number}) |
| onConnectivityChanged | ({type: string, strength: number}) |
| onPairingRequest | (KDEPairingRequest) |
class KDENotification
Constructor
Not externally accessible
Properties
| Name | Type | Info | | ----------- | ------- | --------------------------- | | appName | string | App origin name | | dismissable | boolean | Is this message dismissable | | silent | boolean | Is it a silent message | | text | string | Message text | | ticker | string | Message short version | | title | string | Message title |
Functions
| Signature | Info |
| ----------------------------------- | ---------------------------------------------------------------------------------------- |
| async dismiss(): Promise<boolean> | Dismisses message on device. Returns true if message is dismissable, false otherwise |
Events
No events
class KDEMediaHandler
Constructor
Not externally accessible
Properties
| Name | Type | Info | | ---------- | ------- | ---------------------------------------------------- | | length | number | length of currently playing track in ms | | position | number | already passed time of currently playing track in ms | | volume | number | device volume in % | | isPlaying | boolean | is music playing or paused | | player | string | name of currently playing app | | nowPlaying | string | name & artist of track | | title | string | track title | | artist | string | track artist name | | album | string | track album name |
Functions
| Signature | Info |
| ---------------------------------- | ----------------------------------------------------- |
| async Next(): Promise<void> | Play next track |
| async Previous(): Promise<void> | Play previous track / Jump to start of current track |
| async Play(): Promise<void> | Play track |
| async Pause(): Promise<void> | Pause track |
| async PlayPause(): Promise<void> | Switch Between Play/Pause |
| async Stop(): Promise<void> | Stop track |
| async update(): Promise<void> | Manually update data; Use to keep track of position |
Events
| Event | Values | Info |
| ---------------------- | ------ | ---------------------------------------------------------------------------------------------------------- |
| onMediaPlayerUpdated | () | Called when any data changes. Can fire multiple times in succession; Does NOT fire when position changes |
class KDEPairingRequest
Constructor
Not externally accessible
Properties
None
Functions
| Signature | Info |
| ------------------------------- | -------------- |
| async Accept(): Promise<void> | Accept request |
| async Reject(): Promise<void> | Reject request |
Events
None
Do To / Not supported yet
- Multiple Media Players
- SFTP Bindings
- Contacts / SMS / Telephone
- Photo Requesting / Recieving
- Remote Control / Keyboard
- Remote Commands
