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

Feature/interactivity #76

Merged
merged 8 commits into from
Jan 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module.exports = {
'@typescript-eslint/no-redeclare': 'off',
'@typescript-eslint/space-before-function-paren': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-empty-object-type': 'off',
'prefer-const': 'warn',
// 'prettier/prettier': 'warn',
'prettier/prettier': ['warn', { endOfLine: 'auto' }],
Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
network-server: ./Dockerfile
docker-compose -f docker-compose.network.yml up server

network-proxy: ./proxy
docker-compose -f docker-compose.network.yml up proxy --build --force-recreate

1 change: 1 addition & 0 deletions docs/Spotify.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ In the project, `/api/v1/spotify/login/` has implemented Spotify's access token

- Dashboard: <https://developer.spotify.com/dashboard>
- How spotify authorization works: <https://developer.spotify.com/documentation/web-api/tutorials/code-flow>
- Spotify's GitHub: <https://github.com/spotify>

### Web Playback SDK

Expand Down
8 changes: 8 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"@types/express": "^4.17.17",
"@types/jest": "^29.5.2",
"@types/node": "^20.3.1",
"@types/spotify-web-playback-sdk": "^0.1.19",
"@types/supertest": "^6.0.0",
"@typescript-eslint/eslint-plugin": "^8.0.0",
"@typescript-eslint/parser": "^8.0.0",
Expand Down
4 changes: 3 additions & 1 deletion proxy/default.conf.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ include /etc/nginx/conf.d/includes/club-admin.conf;
server {
listen 8080;

add_header Access-Control-Allow-Origin *;
# add_header Access-Control-Allow-Origin *;
# proxy_set_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Headers *;
add_header Access-Control-Allow-Methods *;
Expand Down Expand Up @@ -55,6 +55,8 @@ server {

client_max_body_size 32M;
include /etc/nginx/uwsgi_params;


}

location ~* ^/api/v[0-9]/(docs|schema)/club-manager {
Expand Down
7 changes: 1 addition & 6 deletions src/app.gateway.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { WebSocketGateway, WebSocketServer } from '@nestjs/websockets'
import { Server } from 'socket.io'
import { TrackStateUpdateDto } from './jukebox/dto/track-player-state.dto'

@WebSocketGateway()
@WebSocketGateway({ cors: true })
export class AppGateway {
@WebSocketServer() server: Server

public emitTrackStateUpdate(payload: TrackStateUpdateDto) {
this.server.emit('track-state-update', payload)
}
}
3 changes: 2 additions & 1 deletion src/config/cache-options.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CacheModuleAsyncOptions } from '@nestjs/cache-manager'
import type { CacheModuleAsyncOptions } from '@nestjs/cache-manager'
import { ConfigModule, ConfigService } from '@nestjs/config'
import { redisStore } from 'cache-manager-redis-store'

Expand All @@ -7,6 +7,7 @@ export const CacheOptions: CacheModuleAsyncOptions = {
imports: [ConfigModule],
useFactory: async (configService: ConfigService) => {
const store = await redisStore({
ttl: 600,
socket: {
host: configService.get<string>('REDIS_HOST'),
port: parseInt(configService.get<string>('REDIS_PORT')!),
Expand Down
7 changes: 7 additions & 0 deletions src/jukebox/dto/jukebox-action.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
interface IJukeboxAction {
jukebox_id: number
action: 'like' | 'dislike'

queue_index: number
}
export class JukeboxActionDto {}
22 changes: 22 additions & 0 deletions src/jukebox/dto/jukebox-link.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { ApiProperty } from '@nestjs/swagger'
import { Expose } from 'class-transformer'

export class JukeboxLinkDto implements IJukeboxLink {
@Expose()
@ApiProperty()
id: number

@Expose()
@ApiProperty()
type: JukeboxLinkType

@Expose()
@ApiProperty()
email: string

@Expose()
@ApiProperty()
active: boolean
}

// export class JukeboxLinkCreds implements IJukeboxLinkCreds
33 changes: 1 addition & 32 deletions src/jukebox/dto/jukebox.dto.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,7 @@
import { ApiProperty } from '@nestjs/swagger'
import { Expose } from 'class-transformer'
import { BaseDto } from 'src/config/dtos'

export class JukeboxLinkDto implements IJukeboxLink {
@Expose()
@ApiProperty()
id: number

@Expose()
@ApiProperty()
type: JukeboxLinkType

@Expose()
@ApiProperty()
email: string

@Expose()
@ApiProperty()
active: boolean
}
import { JukeboxLinkDto } from './jukebox-link.dto'

export class JukeboxDto extends BaseDto implements IJukebox {
@Expose()
Expand All @@ -36,18 +19,4 @@ export class JukeboxDto extends BaseDto implements IJukebox {
@Expose()
@ApiProperty()
links: JukeboxLinkDto[]

// static serialize(entity: Jukebox): JukeboxDto {
// return {
// ...super.serialize(entity),
// name: entity.name,
// club_id: entity.club_id,
// links:
// entity.spotify_link_assignments?.map((assignment) => ({
// type: 'spotify',
// email: assignment.spotify_link.spotify_email,
// active: assignment.active,
// })) ?? [],
// }
// }
}
22 changes: 22 additions & 0 deletions src/jukebox/dto/player-state.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type { TrackMetaDto } from './track.dto'

export class PlayerStateDto implements IPlayerState {
jukebox_id: number
current_track?: TrackMetaDto
progress: number
is_playing: boolean
}
export class PlayerQueueStateDto extends PlayerStateDto implements IPlayerQueueState {
next_tracks: ITrack[]
}

export class PlayerMetaStateDto extends PlayerStateDto implements IPlayerMetaState {
default_next_tracks: ITrack[]
}

export class PlayerStateActionDto implements IPlayerAction {
jukebox_id: number
current_track?: Partial<TrackMetaDto>
progress?: number
is_playing?: boolean
}
17 changes: 11 additions & 6 deletions src/jukebox/dto/track-player-state.dto.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
export class TrackStateUpdateDto implements ITrackStateUpdate {
current_track?: ITrack
next_tracks?: ITrack[]
export class PlayerUpdateDto implements IPlayerUpdate {
jukebox_id: number
current_track?: ITrackMeta
progress: number
is_playing: boolean
next_tracks: ITrack[]
}

export class PlayerUpdateDto implements IPlayerUpdate {

current_track?: ITrack
export class PlayerAuxUpdateDto implements IPlayerAuxUpdate {
jukebox_id: number
current_track: ITrackMeta
progress: number
is_playing: boolean
default_next_tracks: ITrack[]
changed_tracks?: boolean
}
73 changes: 73 additions & 0 deletions src/jukebox/dto/track.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { ApiProperty } from '@nestjs/swagger'

class SpotifyImageDto implements Spotify.Image {
height?: number
url: string
size?: string
width?: number
}

class SpotifyAlbumDto implements Spotify.Album {
name: string
uri: string
images: SpotifyImageDto[]
}

class SpotifyEntityDto implements Spotify.Entity {
name: string
uri: string
url: string
}

export class TrackMetaDto implements ITrackMeta {
@ApiProperty()
queue_id: string

@ApiProperty()
recommended_by?: string

@ApiProperty()
spotify_queued?: boolean

@ApiProperty()
likes?: number

@ApiProperty()
dislikes?: number

@ApiProperty()
album: SpotifyAlbumDto

@ApiProperty()
artists: SpotifyEntityDto[]

@ApiProperty()
duration_ms: number

@ApiProperty()
id: string

@ApiProperty()
is_playable: boolean

@ApiProperty()
name: string

@ApiProperty()
uid: string

@ApiProperty()
uri: string

@ApiProperty({ oneOf: [{ type: 'string', enum: ['audio', 'video'] }] })
media_type: 'audio' | 'video'

@ApiProperty({ oneOf: [{ type: 'string', enum: ['track', 'episode', 'ad'] }] })
type: 'track' | 'episode' | 'ad'

@ApiProperty({ oneOf: [{ type: 'string', enum: ['audio', 'video'] }] })
track_type: 'audio' | 'video'

@ApiProperty()
linked_from: { uri: string | null; id: string | null }
}
3 changes: 2 additions & 1 deletion src/jukebox/entities/jukebox.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
PrimaryColumn,
PrimaryGeneratedColumn,
} from 'typeorm'
import { JukeboxDto, JukeboxLinkDto } from '../dto/jukebox.dto'
import { JukeboxLinkDto } from '../dto/jukebox-link.dto'
import { JukeboxDto } from '../dto/jukebox.dto'

@Entity('jukebox')
export class Jukebox extends BaseEntity {
Expand Down
Loading
Loading