Skip to content

From StreamCore To WebAudio

Vurv edited this page Feb 5, 2023 · 8 revisions

For server owners: You can enable backwards compatibility with wa_sc_compat 1.

Because WebAudio is object oriented (We don't use indexes to run code) and much more advanced, this guide is here to help you convert your Streamcore contraptions to WebAudio

Playing a stream parented to a prop

# StreamCore
E:streamStart(1, "<URL>")
# WebAudio
local Stream = webAudio("<URL>")
Stream:setParent(E) # or use parentTo
Stream:play()

Modifying an existing stream (Setting Volume to 50%)

# StreamCore
streamVolume(1, 0.5)
# WebAudio
Stream:setVolume(50)
Stream:update()
# If we are not calling :play() or :pause(), the data is not immediately updated.
# We call :update() to manually send this new volume information to the client.

For everything WebAudio can do but StreamCore can't, see the Features page

Adaption Library

You can #include this library that provides streamcore's functions through a webaudio backend if you do not want to refactor the code.

@name Streamcore Replacement with WebAudio Backend
@persist WSTRCORE_TBL:table

function streamHelp() {}
function number streamCanStart() { return webAudioCanCreate() }

function entity:streamStart(Index, Url:string) {
    local Wa = webAudio(Url)
    Wa:setParent(This)
    Wa:play()
    WSTRCORE_TBL[Index, webaudio] = Wa
}

function entity:streamStart(Index, Url:string, Volume) {
    local Wa = webAudio(Url)
    Wa:setVolume(Volume * 100)
    Wa:setParent(This)
    Wa:play()
    WSTRCORE_TBL[Index, webaudio] = Wa
}

function entity:streamStart(Index, Volume, Url:string) {
    local Wa = webAudio(Url)
    Wa:setVolume(Volume * 100)
    Wa:setParent(This)
    Wa:play()
    WSTRCORE_TBL[Index, webaudio]:destroy() # Might not be necessary
    WSTRCORE_TBL[Index, webaudio] = Wa
}

function streamStop(Index) {
    local Wa = WSTRCORE_TBL[Index, webaudio]
    if(Wa:isValid()) {
        Wa:destroy()
    }
}
function streamVolume(Index, Volume) {
    local Wa = WSTRCORE_TBL[Index, webaudio]
    if (Wa:isValid()){
        Wa:setVolume(Volume * 100)
        Wa:update()
    }
}
function streamRadius(Index, Radius) {
    local Wa = WSTRCORE_TBL[Index, webaudio]
    if (Wa:isValid()){
        Wa:setRadius(Radius)
        Wa:update()
    }
}

function number streamLimit() { return 0.3 }
function number streamMaxRadius() { return convarnum("wa_radius_max") ?: 3000 }
function number streamAdminOnly() { return webAudioAdminOnly() }

function streamDisable3D(N) {}