Skip to content

Commit

Permalink
safer go live
Browse files Browse the repository at this point in the history
  • Loading branch information
goldbuick committed Jan 3, 2025
1 parent 4d8080f commit 835f90b
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 16 deletions.
11 changes: 10 additions & 1 deletion zss/device/broadcast.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import IVSBroadcastClient, { Callback } from 'amazon-ivs-web-broadcast'
import { createdevice } from 'zss/device'
import { doasync } from 'zss/mapping/func'
import { waitfor } from 'zss/mapping/tick'
import { ispresent, isstring, MAYBE } from 'zss/mapping/types'
import { write } from 'zss/words/writeui'
import { write, writeheader, writeoption } from 'zss/words/writeui'

import { api_error } from './api'
import { synthbroadcastdestination } from './synth'
Expand Down Expand Up @@ -93,6 +94,14 @@ const broadcast = createdevice('broadcast', ['second'], (message) => {
case 'startstream':
doasync('broadcast:startstream', async () => {
if (isstring(message.data) && ispresent(broadcastclient)) {
writeheader(broadcast.name(), 'broadcasting in')
writeoption(broadcast.name(), '3', '...')
await waitfor(1000)
writeoption(broadcast.name(), '2', '...')
await waitfor(1000)
writeoption(broadcast.name(), '1', '...')
await waitfor(1000)
writeheader(broadcast.name(), 'GOING LIVE')
await broadcastclient.startBroadcast(
message.data,
'https://g.webrtc.live-video.net:4443',
Expand Down
8 changes: 1 addition & 7 deletions zss/device/peer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@ import { ispresent, MAYBE } from 'zss/mapping/types'
import { shorturl } from 'zss/mapping/url'
import { write, writecopyit } from 'zss/words/writeui'

import {
api_error,
peer_create,
peer_joincode,
register_ackbooks,
vm_login,
} from './api'
import { api_error, peer_create, peer_joincode, register_ackbooks } from './api'
import { createforward } from './forward'
import { registerreadplayer } from './register'

Expand Down
18 changes: 12 additions & 6 deletions zss/device/synth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,29 @@ export function enableaudio() {
start()
.then(() => {
if (!enabled) {
const context: AudioContext = getContext() as unknown as AudioContext
const transport = getTransport()
enabled = true
transport.start()
transport.bpm.value = 107
unmute(context, true)
tape_info('synth', 'audio is enabled!')
try {
const context: AudioContext = getContext() as unknown as AudioContext
unmute(context, true)
} catch (error) {
console.debug(error)
}
}
})
.catch(() => {})
.catch((err: any) => {
api_error('synth', 'audio', err.message)
})
}

function createsynth() {
const destination = getDestination()
const broadcastdestination = getContext().createMediaStreamDestination()

const mainvolume = new Volume(8)
const mainvolume = new Volume(4)
mainvolume.connect(destination)
mainvolume.connect(broadcastdestination)

Expand Down Expand Up @@ -692,10 +698,10 @@ async function handletts(voice: string, phrase: string) {
playaudiobuffer(audiobuffer)
}

let synth: ReturnType<typeof createsynth>
let synth: MAYBE<ReturnType<typeof createsynth>>

export function synthbroadcastdestination(): MAYBE<MediaStreamAudioDestinationNode> {
return synth.broadcastdestination
return synth?.broadcastdestination
}

const synthdevice = createdevice('synth', [], (message) => {
Expand Down
25 changes: 25 additions & 0 deletions zss/firmware/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import {
register_share,
register_dev,
peer_joincode,
broadcast_closesession,
broadcast_startstream,
broadcast_stopstream,
broadcast_createsession,
} from 'zss/device/api'
import { modemwriteinitstring } from 'zss/device/modem'
import { createfirmware } from 'zss/firmware'
Expand Down Expand Up @@ -448,3 +452,24 @@ export const CLI_FIRMWARE = createfirmware()
peer_joincode('cli', READ_CONTEXT.player)
return 0
})
.command('broadcast', (_, words) => {
const [maybeaction, ii] = readargs(words, 0, [ARG_TYPE.MAYBE_STRING])
switch (NAME(maybeaction ?? '')) {
default:
case 'create':
broadcast_createsession('cli', READ_CONTEXT.player)
break
case 'close':
broadcast_closesession('cli', READ_CONTEXT.player)
break
case 'start': {
const [streamkey] = readargs(words, ii, [ARG_TYPE.STRING])
broadcast_startstream('cli', streamkey, READ_CONTEXT.player)
break
}
case 'stop':
broadcast_stopstream('cli', READ_CONTEXT.player)
break
}
return 0
})
5 changes: 4 additions & 1 deletion zss/gadget/editor/editorinput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,10 @@ export function EditorInput({
break
case 'p':
vm_cli('editor', strvalueselected, player)
writetext('editor', `running: ${strvalueselected}`)
writetext(
'editor',
`running: ${strvalueselected.substring(0, 18)}`,
)
break
}
} else if (mods.alt) {
Expand Down
8 changes: 7 additions & 1 deletion zss/memory/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { CYCLE_DEFAULT, TICK_FPS } from 'zss/mapping/tick'
import { MAYBE, isnumber, ispresent, isstring } from 'zss/mapping/types'
import { createos } from 'zss/os'
import { READ_CONTEXT } from 'zss/words/reader'
import { COLOR, NAME } from 'zss/words/types'
import { NAME } from 'zss/words/types'

import {
boarddeleteobject,
Expand Down Expand Up @@ -506,9 +506,15 @@ export function memorycli(player: string, cli = '') {
READ_CONTEXT.player = player
READ_CONTEXT.isplayer = true

// cli invokes get more processing time
const resethalt = RUNTIME.HALT_AT_COUNT
RUNTIME.HALT_AT_COUNT = resethalt * 8

// invoke once
tape_debug('memory', 'running', mainbook.timestamp, id, cli)
os.once(id, DRIVER_TYPE.CLI, 'cli', cli)

RUNTIME.HALT_AT_COUNT = resethalt
}

export function memoryrun(address: string) {
Expand Down

0 comments on commit 835f90b

Please sign in to comment.