Skip to content

Commit

Permalink
Merge branch 'main' into deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
davwheat committed Jun 8, 2024
2 parents 00071f3 + 0b9f398 commit b6a9c75
Show file tree
Hide file tree
Showing 8 changed files with 693 additions and 43 deletions.
13 changes: 0 additions & 13 deletions .github/workflows/smoketest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,19 +131,6 @@ jobs:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
command: d1 migrations apply rail-announcements

- name: Setup Rclone
uses: AnimMouse/setup-rclone@v1
with:
rclone_config: ${{ secrets.RCLONE_CONFIG }}

- name: Upload audio files to Cloudflare R2
# If it's a PR, only run if the PR head is not a fork
if: ${{ github.event_name != 'pull_request' || !github.event.pull_request.head.repo.fork }}
run: |
rclone --fast-list -v --transfers=128 --checkers=256 --progress copy "./audio" "Cloudflare R2:/rail-announcements-audio"
env:
RCLONE_CONFIG_PASS: ${{ secrets.RCLONE_CONFIG_PASSWORD }}

- name: Publish to Cloudflare Pages
uses: cloudflare/pages-action@1
if: ${{ github.event_name != 'pull_request_target' || contains(github.event.label.name, '🚀 request deploy') }}
Expand Down
56 changes: 56 additions & 0 deletions .github/workflows/upload_audio_to_r2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Smoketest

on:
push:
branches:
- main
- deploy
paths:
- 'audio/**'
# Triggers the workflow on pull request event, but only for pull request from not forked repo
pull_request:
types:
- opened
- synchronize
paths:
- 'audio/**'

permissions:
# default contents: read & write (in forked repos, only read)
contents: write
# default deployments: read & write (in forked repos, only read)
deployments: write
# default pull-requests: read & write (in forked repos, only read)
pull-requests: write

env:
NODE_VERSION: 20.x
CF_PAGES_PROJECT_NAME: rail-announcements

jobs:
smoketest:
runs-on: ubuntu-latest
name: Upload Audio to Cloudflare R2

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.head.ref || github.ref }}
cancel-in-progress: true

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha || github.ref }}

- name: Setup Rclone
uses: AnimMouse/setup-rclone@v1
with:
rclone_config: ${{ secrets.RCLONE_CONFIG }}

- name: Upload audio files to Cloudflare R2
# If it's a PR, only run if the PR head is not a fork
if: ${{ github.event_name != 'pull_request' || !github.event.pull_request.head.repo.fork }}
run: |
rclone --fast-list -v --transfers=128 --checkers=256 --progress copy "./audio" "Cloudflare R2:/rail-announcements-audio"
env:
RCLONE_CONFIG_PASS: ${{ secrets.RCLONE_CONFIG_PASSWORD }}
2 changes: 1 addition & 1 deletion gatsby-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const onCreateWebpackConfig: GatsbyNode['onCreateWebpackConfig'] = ({ sta
module: {
rules: [
{
test: /crunker/,
test: /crunker/g,
use: loaders.null(),
},
],
Expand Down
55 changes: 48 additions & 7 deletions src/announcement-data/AnnouncementSystem.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Crunker from 'crunker'
import Crunker from '../helpers/crunker'

import type { ICustomAnnouncementPaneProps } from '@components/PanelPanes/CustomAnnouncementPane'
import type { ICustomButtonPaneProps } from '@components/PanelPanes/CustomButtonPane'
Expand Down Expand Up @@ -170,6 +170,12 @@ export default abstract class AnnouncementSystem {
return
}

window.Crunker = Crunker

if ('audioSession' in window.navigator) {
window.navigator.audioSession.type = 'playback'
}

window.__audio = fileIds
console.info('Playing audio files:', fileIds)

Expand All @@ -186,20 +192,55 @@ export default abstract class AnnouncementSystem {

if (audio.numberOfChannels > 1) {
// This is stereo. We need to mux it to mono.

audio.copyToChannel(audio.getChannelData(0), 1, 0)
}

if (download) {
crunker.download(crunker.export(audio, 'audio/wav').blob, 'announcement')
window.__audio = undefined
} else {
const source = crunker.play(audio)

return new Promise<void>(resolve => {
source.addEventListener('ended', () => {
window.__audio = undefined
resolve()
crunker.play(audio, source => {
console.log('[Crunker] About to play audio...')
crunker._context.onstatechange = () => console.log('state changed to: ', audioContext.state)
console.log('Context state: ', crunker._context.state)

if (crunker._context.state === 'suspended') {
console.log('[Crunker] Resuming audio context')
crunker._context.resume()
console.log('Context state: ', crunker._context.state)

if (crunker._context.state === 'suspended') {
console.error('[Crunker] Failed to resume audio context')

document.getElementById('resume-audio-button')?.remove()

const button = document.createElement('button')
button.textContent = 'Resume audio'
button.id = 'resume-audio-button'
button.style.margin = '16px'
button.onclick = () => {
crunker._context.resume()
button.remove()
}

const container = document.getElementById('resume-audio-container')
if (container) container.appendChild(button)
else document.body.appendChild(button)

alert(
"Your device or web browser is refusing to let the website play audio.\n\nThis is especially common on iPhones and iPads. We'd recommend you try using a desktop computer or an alterantive device.\n\nTry scrolling to and pressing the 'Resume audio' button. If this doesn't help, there's nothing else that we can do. Sorry!",
)

button.scrollIntoView()
}
}

source.addEventListener('ended', () => {
console.log('[Crunker] Finished playing audio')
window.__audio = undefined
resolve()
})
})
})
}
Expand Down
31 changes: 30 additions & 1 deletion src/announcement-data/systems/stations/AmeyPhil.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,12 @@ export default class AmeyPhil extends StationAnnouncementSystem {
>[]
disruptedTrain: ICustomAnnouncementPreset<IDisruptedTrainAnnouncementOptions>[]
}> {
return {
const presets: {
nextTrain: ICustomAnnouncementPreset<
INextTrainAnnouncementOptions & IStandingTrainAnnouncementOptions & IPlatformAlterationAnnouncementOptions
>[]
disruptedTrain: ICustomAnnouncementPreset<IDisruptedTrainAnnouncementOptions>[]
} = {
nextTrain: [
{
name: '12:28 | SN Littlehampton to Brighton',
Expand Down Expand Up @@ -487,6 +492,30 @@ export default class AmeyPhil extends StationAnnouncementSystem {
},
],
}

presets.nextTrain.push({
name: '23:45 | Calling at every station (needs a powerful device)',
state: {
chime: this.DEFAULT_CHIME,
platform: '1',
newPlatform: '1',
oldPlatform: '18',
announceOldPlatform: true,
firstClassLocation: 'middle',
isDelayed: false,
mindTheGap: true,
thisStationCode: 'North Pole International',
hour: '23',
min: '45',
toc: '',
terminatingStationCode: 'North Pole International',
vias: ['SLO'].map(stationItemCompleter),
callingAt: this.STATIONS.map(stationItemCompleter),
coaches: '1 coach',
},
})

return presets
}

protected get AVAILABLE_TOCS() {
Expand Down
Loading

0 comments on commit b6a9c75

Please sign in to comment.