Docs
  • 🍎Stream Avatars
    • Introduction
    • ⏩Quick Setup
    • 📸How to Overlay
      • OBS
      • Streamlabs Desktop
      • XSplit
      • Twitch Studio
      • Unlisted / Other
    • ⚛️Extension
    • ⏩Quick Guide
    • 📬Commands
      • ❗!commands
      • ↕️Selection Commands
        • !random
          • !mass random
          • !change {user} {command} random
        • !avatars
          • !avatar {avatar}
          • !change {user} !avatar {avatar}
          • !change {user} !avatar {avatar} {timer}
          • !mass avatar {avatar}
          • !mass avatar {avatar} {timer}
        • !color
        • !gear
        • !nametags
        • !actions
        • !show
      • ↕️Minigames and Fun Commands
        • !basketball
        • !battleroyale
        • !boss
        • !duel {user} {amount}
        • !slots {amount}
        • !bomb {user}
        • !sling {power} {angle}
        • !fart
        • !quote {#}
        • !roll {#d#}
        • !8ball {question}
        • !freeze {user} {seconds}
        • !pin {user} {x%} {y%} {seconds}
        • !attack {user}
        • !dance
        • !hug {user}
        • !throw
        • !explode {target}
        • !bet {amount} {calltype}
        • !scale {target} {size}
        • !spawn game
        • !screensaver {seconds}
        • ↕️!mass {command}
      • ↕️Shop Commands
        • !shop
        • !buy avatars
        • !buy colors
        • !buy gear
        • !buy nametags
        • !buy actions
      • ↕️Currency Commands
        • !currency
        • !currency add {user} {amount}
        • !currency remove {user} {amount}
        • !currency give {user} {amount}
      • ↕️Gifting Commands
        • !gift {user} lootbox {name}
        • !gift {user} avatar {avatar}
        • !gift {user} gear {gear_set} {gear_piece}
        • !gift {user} color {avatar} {color}
        • !gift {user} nametag {nametag}
        • !gift {user} all true
        • !currency add {user} {amount}
      • ↕️Remove Ownership Commands
        • !remove {user} avatar {avatar}
        • !remove {user} gear {gear_set} {gear_piece}
        • !remove {user} color {avatar} {color}
        • !remove {user} nametag {nametag}
        • !currency remove {user} {amount}
      • !extension
      • !hideavatar
      • !mass {command}
      • !change {user} {command}
      • !spawn {title}
      • !whitelist add {user}
      • !blacklist add {user}
      • !mod add {user}
      • !leaderboard
      • !leaderboard exclude {user}
      • !game exclude {user}
      • !sounds
      • !shoutout {user}
    • 📃Application Settings
      • General
      • Login Details
      • Minigames
      • Avatars And Gear
      • Sounds
      • Nametag Settings
      • Import & Export
      • Shop Editing
      • User Editing
      • ❗Unfinished Docs!
      • ❗Bot Commands
        • ❗Custom Commands
      • ❗Edit Lootboxes
      • ❗Backgrounds
      • ❗Bot Commands
    • 🎨Content Creating
      • Creating Avatars
      • Extension Sorting Order
      • Deleting Avatars, Palettes/Colors, and Gear
      • Creating Gear
      • Creating Colors
      • Creating Backgrounds
      • Creating Bosses
      • Creating Player Classes (boss)
      • Creating Nametags
      • Creating Lootboxes
      • Importing Scripts
      • Importing Private Content
      • Creating Custom Redemptions
      • Creating Extension Thumbnails
      • Creating Custom Language Localization
    • 💫Integrations
      • Stream Deck
    • ❓Support
      • New Platform Additions
      • Various Troubleshooting
      • Data Folder
      • Beta Branch
      • F.A.Q
      • Crash Log - Event Viewer
    • 🤝Stream Avatars Partner
  • ⚙️LUA Scripting API
    • Introduction
    • Quick Start
    • API Reference & Tips
      • 🌎Global Functions
        • log
        • wait
        • yield
        • yieldBreak
        • async functions
        • waitForAsync function
        • stopAsync function
        • get
        • set
        • applyImage
        • waitForAnimation
        • webrequest get/post
        • getUser
        • getUsers
        • getUserById
        • getCurrency
        • addCurrency
        • removeCurrency
        • adjustCurrency
        • getBackground
        • getScriptableBlocks
        • getAvatar
        • getAllAvatars
        • runCommand
        • writeChat
        • setProperty
        • getApp
        • save
        • load
        • addEvent
        • removeEvent
        • keepAlive
      • 🔫Events
        • BankController
        • ServiceController
        • Read Chat
        • Websockets
        • Scriptable Block Trigger
        • Platform Donation
        • App State Change
        • Custom Command
        • Basketball Outcome
        • BattleRoyale Outcome
        • Boss Battle Outcome
        • Boss Battle Player Joined
        • Duel Outcome
        • On JumpCatch Star
        • On Background Switch
        • On Avatar Change
        • On New Viewer
        • On InitializeNewViewer
        • On Follower
        • On Raid
        • On Subscriber
        • On Avatar Spawn
        • On Trigger Object
        • On Hotkey
        • On Purchase
      • 📦Classes
        • App
          • globalAvatarScale {get;set}
          • globalNametagScale {get;set}
          • globalChatBubbleScale {get;set}
          • globalNametagStack {get;set}
          • getResolution
          • platformServiceSettings
          • setResolution
          • setFullscreen
          • getStreamer
          • convertPositionToPercent
          • convertPercentToPosition
          • playSound
          • createBomb
          • pitchSound
          • stopSound
          • soundIsPlaying
          • createGameObject
          • getGameObject
          • createChatBubble
          • createWebsocket
          • removeWebsocket
          • sendWebsocketMessage
          • getAppState
          • sha256_base64
          • getUserFromData
          • getIdsFromData
          • deleteUser
          • exportAvatarImage
          • translateCommand
        • User
          • id {get}
          • isActive {get}
          • isFake {get}
          • lastActiveDate {get}
          • secondsSinceLastActive {get}
          • displayName {get}
          • channelName {get}
          • follower {get}
          • vip {get}
          • subscriber {get}
          • moderator {get}
          • platformModerator {get}
          • platform {get}
          • streamer {get}
          • avatar {get;set}
          • scale {get;set}
          • override_scale {get;set}
          • color {get;set}
          • nametag {get;set}
          • getState
          • getGear
          • setGear
          • setPosition
          • getPosition
          • getWearableAvatars
          • getWearableAvatarColors
          • getWearableGearSetPieces
          • getWearableNametags
          • setTemporaryAvatar
          • setTemporaryColor
          • setTemporaryNametag
          • setTemporaryGear
          • setTemporaryNone
          • clearAllTemporarySelections
          • chatBubble
          • runCommand
          • physics
          • saveUserData
          • loadUserData
        • Physics
          • grounded {get;set}
          • setVelocity
        • ObjectPhysics
          • hasTrigger {get}
          • hasRigidBody {get}
          • layer {get;set}
          • kinemetic {get;set}
          • setVelocity
          • addBoxCollider
          • addCircleCollider
          • addBoxTrigger
          • addCircleTrigger
        • Avatar
          • name {get}
          • getGear
          • getGearPieces
          • getColors
          • getActions
        • GameObject
          • image {get}
          • destroy
          • setAngle
          • setPosition
          • getPosition
          • adjustPosition
          • getScale
          • setScale
          • adjustScale
          • physics
        • Image
          • playAnimation
          • stopAnimation
          • flipX
          • flipY
          • sorting
          • anchor
        • ScriptableBlock
          • id {get}
          • position
      • 📤Helper Class
        • createCooldown
        • checkCooldown
        • setCooldown
        • cooldownTimeLeft
        • startsWith
        • replace
        • split
        • randomElement
        • hasValue
        • matchRegex
Powered by GitBook
On this page
  1. LUA Scripting API
  2. API Reference & Tips
  3. Classes
  4. App

sha256_base64

API -

return function()
    local app = getApp();
    local state = app.getAppState();
    
    --encryption and base64 shortcut
    local sha256AndBase64 = app.sha256_base64('somestring');
    log(sha256AndBase64);
end

This is usually used with security issues and dealing with API stuff.

Example script for OBS websockets

function authentication(ob)
    local challenge = ob['d']['authentication']['challenge'];
    local salt = ob['d']['authentication']['salt'];

    set('rpcVersion', ob['d']['authentication']['rpcVersion'])

    local app = getApp();
    local salted_sha_base64 = app.sha256_base64(password .. salt); 
    local password_challenge_sha_base64 = app.sha256_base64(salted_sha_base64 .. challenge); 

    local m_data = {};
    m_data['op'] = 1;
    m_data['d'] = {};

    m_data['d']['rpcVersion'] = rpcVersion;
    m_data['d']['authentication'] = password_challenge_sha_base64;
    m_data['d']['eventSubscriptions'] = 33; --these are events you can subscribe to

    app.sendWebsocketMessage(socket, json.serialize(m_data));

end

function yourEvent(title, type, message, code)

    if title ~= socket then --make sure we're using the socket title we want!
        return; --otherwise exit out early :)
    end

    if type == 'OnMessage' then
        --route all messages here!
        --the code will be blank. ''

        log('receiving message: ' .. message);

        local ob = json.parse(message);
        if ob['op'] == 0 then
            authentication(ob);
        end

        if ob['op'] == 2 then
           switchToScene(gamePlaySceneName);
        end
    end
    if type == 'OnOpen' then
        --the socket opened!!
        --the message and code will be blank. ''
        log('socket was opened!');
    end

    if type == 'OnClose' or type == 'OnError' then
        --if the message type is OnClose or OnError, let's clean up the socket...
        local app = getApp();
        app.removeWebSocket(socket);
        log('socket is closed!');
        log(message);
        log(code);
    end
end


function switchToScene(scene)
    local m_data = {};
    m_data['op'] = 6;
    m_data['d'] = {};
    local app = getApp();
    m_data['d']['requestType'] = 'SetCurrentProgramScene';
    m_data['d']['requestId'] = 'f819dcf0-89cc-11eb-8f0e-382c4ac93b9c';
    m_data['d']['requestData'] = {};
    m_data['d']['requestData']['sceneName'] = scene;
    app.sendWebsocketMessage(socket, json.serialize(m_data));
end

--retrieved from json data
ip = 'ws://192.168.1.70:4444';
password = 'your_websocket_password_in_obs';
gamePlaySceneName = 'your scene title';
--
rpcVersion = 1;
socket = 'obs_socket_holder'; 

return function()

    load();
    log('OBS websocket tutorial');
    local app = getApp();

    --remove old existing websocket just incase...
    app.removeWebSocket(socket);
    wait(1); --give it time to remove the old one
    addEvent('websocket', 'yourEvent'); --subscribe to all websockets that exist...

    
    local params = {};
    params[1] = 'Sec-WebSocket-Protocol';
    params[2] = 'obswebsocket.json';
    app.createWebsocket(socket, ip, params); --title a websoscket and connect to a server...

    keepAlive();
end
PreviousgetAppStateNextgetUserFromData

Last updated 2 years ago

⚙️
📦