An open API service indexing awesome lists of open source software.

https://github.com/advplyr/abs-socket-client-demo

Demo of setting up an authenticated socket connection for audiobookshelf
https://github.com/advplyr/abs-socket-client-demo

Last synced: 3 months ago
JSON representation

Demo of setting up an authenticated socket connection for audiobookshelf

Awesome Lists containing this project

README

        

# Audiobookshelf Socket Client Demo

This is just an example of establishing an authenticated socket connection for audiobookshelf.

On the server a user can have many socket clients. This means you can login as the same user in multiple browser windows and they will all receive events for that user.

The demo works like this:

1. Initialize the socket client
2. Login to the server using the audiobookshelf API
3. Emit a socket event 'auth' with the users API token

Once that is done the user will be linked to that socket connection and all events emitted from the server intended for that user will be received by the client.

**Note: if the socket gets disconnected and re-connects it will have a new socket id and needs to emit the 'auth' event again.**

## Installation

Node v16 or higher is required.

```bash
git clone https://github.com/advplyr/abs-socket-client-demo.git
cd abs-socket-client-demo
npm install
```

## Usage

First update the `config.json` with your server info.

For example if your server is running `https://abs.example.com` then your config would look like:
```json
{
"protocol": "https",
"hostname": "abs.example.com",
"port": 443,
"username": "root",
"password": ""
}
```
Replace username/password with yours.

To run the demo make sure you are in the `abs-socket-client-demo` folder then..

```bash
npm run start
```

If you leave this running and login to the same user in a browser then you will see in the console all the events being sent for that user.

To test this you can update a library item in the browser and you should see an `item_updated` event in the console with the full library item object.