Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
oxodao committed Dec 13, 2024
1 parent 42ffada commit dc07963
Show file tree
Hide file tree
Showing 10 changed files with 173 additions and 60 deletions.
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ init:
@docker compose up -d
# @$(MAKE) fixtures

run-app:
@cd backend && go run .

compile-sdk:
@sudo rm -rf sdk/dist
@docker run --rm -v $(PWD)/sdk:/sdk -w /sdk node:lts npm install
Expand All @@ -26,10 +29,16 @@ build-release:
@docker run --rm -v $(PWD)/build:/binaries partyhall:latest /bin/sh -c 'cp /partyhall-*-linux-* /binaries/'

fixtures:
@$(MAKE) create-users
@$(MAKE) create-events


create-users:
@echo "Creating the default users"
@cd backend && go run . user create-admin --username admin --password password --name Administrator
@cd backend && go run . user create user password "Some user"

create-events:
@echo "Creating an event"
@curl -s -o /dev/null -L -X POST 'http://localhost:8080/api/webapp/events' -H "Authorization: Bearer $(VITE_PARTYHALL_APPLIANCE_JWT)" -H 'Content-Type: application/json' --data-raw '{"name":"New event","author":"Some author","date":"2024-01-10T11:58:00Z","location":"Some place"}'
@echo "Creating a second event"
Expand Down
7 changes: 7 additions & 0 deletions admin/public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@
"title": "About you",
"your_display_name": "Your displayed name"
},
"sound_settings": {
"title": "Sound settings",
"input_device": "Microphone",
"output_device": "Speakers",
"volume_input": "Microphones volume",
"volume_output": "Speakers volume"
},
"actions": {
"title": "Actions",
"ph_version": "PartyHall version",
Expand Down
7 changes: 7 additions & 0 deletions admin/public/locales/fr/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@
"title": "Mon compte",
"your_display_name": "Pseudo affiché"
},
"sound_settings": {
"title": "Audio",
"input_device": "Microphone",
"output_device": "Haut-parleurs",
"volume_input": "Volume micros",
"volume_output": "Volume haut-parleurs"
},
"actions": {
"title": "Actions",
"ph_version": "Version PartyHall",
Expand Down
10 changes: 7 additions & 3 deletions admin/src/assets/css/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,17 @@ a {
}

.red {
color: var(--fg-red);
color: var(--fg-red) !important;
text-shadow: var(--fg-red-shadow);
}

.yellow {
color: var(--fg-yellow);
color: var(--fg-yellow) !important;
text-shadow: var(--fg-yellow-shadow);
}

.green {
color: var(--fg-green);
color: var(--fg-green) !important;
text-shadow: var(--fg-green-shadow);
}

Expand All @@ -157,3 +157,7 @@ a {
.overflowAuto {
overflow-y: auto;
}

.no-margin {
margin: 0 !important;
}
24 changes: 24 additions & 0 deletions admin/src/components/sound_card.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Card, Flex, Slider, Typography } from "antd";
import { useAuth } from "../hooks/auth";
import { useTranslation } from "react-i18next";

export default function SoundCard() {
const {t} = useTranslation();
const {api} = useAuth();

return <Card title={t('home.sound_settings.title')}>
<Flex vertical>
{
api.tokenUser?.roles.includes('ADMIN')
&& <>
</>
}

<Typography.Title level={4} className="no-margin red">{t('home.sound_settings.volume_output')}</Typography.Title>
<Slider />

<Typography.Title level={4} className="no-margin red">{t('home.sound_settings.volume_input')}</Typography.Title>
<Slider />
</Flex>
</Card>;
}
3 changes: 3 additions & 0 deletions admin/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { useEffect } from 'react';
import { useMercure } from '../hooks/mercure';
import { useSettings } from '../hooks/settings';
import { useTranslation } from 'react-i18next';
import SoundCard from '../components/sound_card';

export default function Index() {
const { t } = useTranslation('', { keyPrefix: 'home' });
Expand Down Expand Up @@ -50,6 +51,8 @@ export default function Index() {

{event && <EventCard event={event} />}

<SoundCard />

<Card title={t('actions.title')}>
<Flex vertical gap={'.25em'}>
<KeyVal label={t('actions.ph_version')}>{version}</KeyVal>
Expand Down
21 changes: 16 additions & 5 deletions backend/pipewire/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,25 @@ func (d Device) String() string {
}

type Devices struct {
Sources []Device `json:"sources"`
Sinks []Device `json:"sinks"`
Links []Link `json:"links"`
KaraokeSource Device `json:"karaoke_source"`
KaraokeSink Device `json:"karaoke_sink"`
Sources []Device `json:"sources"`
Sinks []Device `json:"sinks"`
Links []Link `json:"links"`
}

type PipeWireMetadata struct {
Subject int `json:"subject"`
Key string `json:"key"`
Type string `json:"type"`
Value any `json:"value"`
}

type PipeWireObject struct {
ID int `json:"id"`
Info struct {
ID int `json:"id"`
Type string `json:"type"`
Metadata []PipeWireMetadata `json:"metadata"`
Info struct {
Props map[string]interface{} `json:"props"`
Params struct {
Props []map[string]interface{} `json:"Props"`
Expand Down
64 changes: 63 additions & 1 deletion backend/pipewire/parsing.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package pipewire

import "fmt"
import (
"fmt"

"github.com/partyhall/partyhall/log"
)

func parseLink(obj PipeWireObject) (*Link, error) {
props := obj.Info.Props
Expand Down Expand Up @@ -49,3 +53,61 @@ func parsePort(obj PipeWireObject) (*Port, error) {
Channel: channel,
}, nil
}

func findPortsByNode(objects []PipeWireObject) map[int][]Port {
portsByNode := make(map[int][]Port)

for _, obj := range objects {
props := obj.Info.Props
if props == nil {
continue
}

if _, ok := props["port.direction"].(string); ok {
nodeID, ok := props["node.id"].(float64)
if !ok {
continue
}

port, err := parsePort(obj)
if err != nil {
continue
}

portsByNode[int(nodeID)] = append(portsByNode[int(nodeID)], *port)
}
}

return portsByNode
}

func findLinks(objects []PipeWireObject, karaokeSinkDevice, karaokeSourceDevice int) []Link {
var links []Link

for _, obj := range objects {
props := obj.Info.Props
if props == nil {
continue
}

if _, ok := props["link.input.port"].(float64); !ok {
continue
}

link, err := parseLink(obj)
if err != nil {
log.Error("Failed to parse link", "error", err)
continue
}

isInputLink := link.InputNodeId == karaokeSinkDevice || link.InputNodeId == karaokeSourceDevice
isOutputLink := link.OutputNodeId == karaokeSinkDevice || link.OutputNodeId == karaokeSourceDevice

// Only include links that connect to either the karaoke source or sink
if isInputLink || isOutputLink {
links = append(links, *link)
}
}

return links
}
84 changes: 35 additions & 49 deletions backend/pipewire/pw.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ func GetVolume(d *Device) error {
/**
* Devices should also have the different ports they have
* so that the link method can work
*
* Note: Yeah we iterate quite a bit on the list of PipewireObjects
* but meh
*/
func GetDevices() (*Devices, error) {
cmd := exec.Command("pw-dump")
Expand All @@ -87,27 +90,7 @@ func GetDevices() (*Devices, error) {
return nil, err
}

portsByNode := make(map[int][]Port)
for _, obj := range objects {
props := obj.Info.Props
if props == nil {
continue
}

if _, ok := props["port.direction"].(string); ok {
nodeID, ok := props["node.id"].(float64)
if !ok {
continue
}

port, err := parsePort(obj)
if err != nil {
continue
}

portsByNode[int(nodeID)] = append(portsByNode[int(nodeID)], *port)
}
}
portsByNode := findPortsByNode(objects)

var karaokeSourceDevice *Device = nil
var karaokeSinkDevice *Device = nil
Expand All @@ -119,6 +102,27 @@ func GetDevices() (*Devices, error) {
continue
}

// Metadata struct will hold the default devices
if obj.Type == "PipeWire:Interface:Metadata" {
metaName, ok := obj.Info.Props["metadata.name"].(string)

if ok && metaName == "default" {
for _, meta := range obj.Metadata {
valueMap, ok := meta.Value.(map[string]any)
if !ok {
continue
}

name, ok := valueMap["name"].(string)
if !ok {
continue
}

fmt.Println(name)
}
}
}

class, ok := props["media.class"].(string)
if !ok || (class != "Audio/Source" && class != "Audio/Sink") {
continue
Expand Down Expand Up @@ -155,36 +159,18 @@ func GetDevices() (*Devices, error) {
return nil, errors.New("pipewire is not setup properly! No KaraokeLoopback interface")
}

var links []Link
for _, obj := range objects {
props := obj.Info.Props
if props == nil {
continue
}

if _, ok := props["link.input.port"].(float64); !ok {
continue
}

link, err := parseLink(obj)
if err != nil {
log.Error("Failed to parse link", "error", err)
continue
}

isInputLink := link.InputNodeId == karaokeSinkDevice.ID || link.InputNodeId == karaokeSourceDevice.ID
isOutputLink := link.OutputNodeId == karaokeSinkDevice.ID || link.OutputNodeId == karaokeSourceDevice.ID

// Only include links that connect to either the karaoke source or sink
if isInputLink || isOutputLink {
links = append(links, *link)
}
}
links := findLinks(
objects,
karaokeSinkDevice.ID,
karaokeSourceDevice.ID,
)

return &Devices{
Sources: sources,
Sinks: sinks,
Links: links,
KaraokeSource: *karaokeSourceDevice,
KaraokeSink: *karaokeSinkDevice,
Sources: sources,
Sinks: sinks,
Links: links,
}, nil
}

Expand Down
4 changes: 2 additions & 2 deletions backend/routes/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ func routeLogin(c *gin.Context) {
}

dbUser, err := dal.USERS.FindByUsername(loginRequest.Username)
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
if err != nil || dbUser == nil {
if errors.Is(err, sql.ErrNoRows) || err == nil {
api_errors.ApiError(
c,
http.StatusBadRequest,
Expand Down

0 comments on commit dc07963

Please sign in to comment.