Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement ONEVENT_COMMAND and ONEVENT_POST_ENDPOINT config options #92

Merged
merged 4 commits into from
Nov 16, 2024

Conversation

QuadratClown
Copy link
Contributor

@QuadratClown QuadratClown commented Nov 16, 2024

librespot supports executing custom scripts when events occur, such as a session_connect event. This can be configured via the --onevent flag,

Description

  • Add ONEVENT_COMMAND config option
    • Specifies the name of a user defined script/executable that will be executed whenever a player event occurs
    • User defined scripts must be mounted to the /userscripts/ folder and be made executable via chmod u+x
  • Add ONEVENT_POST_ENDPOINT
    • Send a POST request with event data to the specified endpoint URL whenever a player event occurs
    • Request body is json encoded and contains all available fields specified by the librespot's player event handler
    • Will be ignored if ONEVENT_COMMAND is set.

Related Issue

#91

Motivation and Context

onevent scripts can be extremely useful, especially when integrating a librespot solution into an external system, such as homeassistant, because it allows triggering other events dependent on the state of the Spotify connect reciever. The most common usecase of the onevent callback is to post the current state of the librespot instance to an external server, which is why this case is implemented directly and get's it's own config option.

How Has This Been Tested?

  • container was built with debian:bookworm-slim base image
  • container was executed with the following docker compose file. Onevent related config options were selectively commented:
services:
  librespot:
    image: quadrat/librespot
    build:
      context: librespot-docker
      dockerfile: ./Dockerfile
      args:
        BASE_IMAGE: debian:bookworm-slim
    container_name: librespot
    network_mode: host
    devices:
      - /dev/snd:/dev/snd
    environment:
      - DEVICE=plughw:CARD=iD24
      - BACKEND=alsa
      - BITRATE=320
      - INITIAL_VOLUME=30
      - DEVICE_NAME=Test-Device
      - FORMAT=S32
      - ENABLE_SYSTEM_CACHE=Y
      - ONEVENT_COMMAND=onevent.sh http://localhost:1880/librespot
      - ONEVENT_POST_ENDPOINT=http://localhost:1880/librespot
    restart: unless-stopped
    volumes:
      - ./userscripts:/userscripts
  • smartphone was connected and disconnected. Events and following executions of scripts were observed
  • nodered was used as REST server to receive the POST requests

@GioF71
Copy link
Owner

GioF71 commented Nov 16, 2024

Hello, can you sign your commits? Maybe also squash everything into one.
If that is an obstacle, I can change the repo rules for this PR, but it would be better to have signed commits.
BTW, thank you. I was about to merge, everything looks ok!

@QuadratClown
Copy link
Contributor Author

QuadratClown commented Nov 16, 2024

Didn't manage to squash, but to retroactively sign the commits :) Hope thats fine.

You might be able to squash to commits through the PR though.

@GioF71 GioF71 merged commit fb8c50f into GioF71:main Nov 16, 2024
1 check passed
@GioF71
Copy link
Owner

GioF71 commented Nov 16, 2024

Thank you! Images will be automatically built in a few hours, but I will also make a release to highlight the changes. Thank you for contributing!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants