Skip to content

Commit

Permalink
Update Pipe to support OpenVROverlayPipe v4.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
BOLL7708 committed Aug 1, 2024
1 parent 6d4cb8e commit cc745ba
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 28 deletions.
2 changes: 1 addition & 1 deletion app/src/Shared/Bot/MainController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default class MainController {
const controllerConfig = await DataBaseHelper.loadMain(new ConfigController())
if(controllerConfig.useWebsockets.twitchEventSub) modules.twitchEventSub.init().then()

modules.pipe.setOverlayTitle("desbot")
modules.pipe.setOverlayTitle("desbot").then()

Functions.setEmptySoundForTTS().then()

Expand Down
4 changes: 2 additions & 2 deletions app/src/Shared/Classes/OBS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ export default class OBS {
}
}
if(opData.authentication) {
const base64secret = await Utils.sha256(this._config.password+opData.authentication.salt)
const authentication = await Utils.sha256(base64secret + opData.authentication.challenge)
const base64secret = await Utils.hashPassword(this._config.password+opData.authentication.salt)
const authentication = await Utils.hashPassword(base64secret + opData.authentication.challenge)
authResponse.d.authentication = authentication
}
this._socket?.send(JSON.stringify(authResponse))
Expand Down
2 changes: 1 addition & 1 deletion app/src/Shared/Classes/OpenVR2WS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default class OpenVR2WS {

async init() { // Init function as we want to set the callbacks before the first messages arrive.
this._config = await DataBaseHelper.loadMain(new ConfigOpenVR2WS())
this._password = await Utils.sha256(this._config.password)
this._password = await Utils.hashPassword(this._config.password)
this._socket = new WebSockets(
`ws://localhost:${this._config.port}`,
10,
Expand Down
76 changes: 55 additions & 21 deletions app/src/Shared/Classes/Pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,24 @@ export default class Pipe {
return this._socket?.isConnected() ?? false
}

setOverlayTitle(title: string) {
private async getPassword(): Promise<string> {
return this._config.password.length > 0 ? await Utils.hashPassword(this._config.password) : ''
}

async setOverlayTitle(title: string) {
this._socket?.send(JSON.stringify(<IPipeRequest>{
basicTitle: title,
basicMessage: "Initializing Overlay Pipe"
key: 'EnqueueNotification',
password: await this.getPassword(),
nonce: Utils.getNonce('DesbotPipe'),
data: {
title: title,
message: "Initializing Overlay Pipe"
}
}))
}



sendBasicObj(
messageData: ITwitchMessageData,
userData: IActionUser,
Expand Down Expand Up @@ -207,14 +218,22 @@ export default class Pipe {
const text = displayName.length > 0 ? `${displayName}: ${cleanText}` : cleanText
if(imageDataUrl != null) {
this._socket?.send(JSON.stringify(<IPipeRequest>{
basicTitle: "",
basicMessage: text,
imageData: Utils.removeImageHeader(imageDataUrl)
key: 'EnqueueNotification',
password: await this.getPassword(),
data: {
title: "",
message: text,
imageData: Utils.removeImageHeader(imageDataUrl)
}
}))
} else {
this._socket?.send(JSON.stringify(<IPipeRequest>{
basicTitle: "",
basicMessage: text,
key: 'EnqueueNotification',
password: await this.getPassword(),
data: {
title: "",
message: text
}
}))
}
}
Expand All @@ -223,6 +242,8 @@ export default class Pipe {
async sendCustom(preset: PresetPipeCustom&AbstractData, imageData: string, durationMs: number = -1) {
if(!this._socket?.isConnected()) console.warn('Pipe.sendCustom: Websockets instance not initiated.')
const nonce = Utils.getNonce('custom-pipe')

// Generate sub-items
const animations: IPipeRequestCustomPropertiesAnimation[] = []
for(const animPreset of preset.animations) {
animations.push({
Expand All @@ -249,11 +270,14 @@ export default class Pipe {
verticalAlignment: areaPreset.alignmentHorizontally_andVertically
})
}

// Build request
const message: IPipeRequest = {
key: 'EnqueueOverlay',
password: await this.getPassword(),
nonce,
imageData,
customProperties: {
enabled: true,
data: {
imageData,
anchorType: preset.anchorType,
attachToAnchor: preset.anchorType_isAttached,
ignoreAnchorYaw: preset.ignoreAnchorYaw,
Expand Down Expand Up @@ -343,7 +367,6 @@ export default class Pipe {
// If the above resulted in image data, broadcast it
for(const imageB64 of imageB64arr) {
if(customPreset) {
const textAreaCount = customPreset.textAreas.length
const texts = ArrayUtils.getAsType(action.texts, action.texts_use)
let i = 0
let text = texts[i]
Expand All @@ -367,17 +390,28 @@ export default class Pipe {
}
}

type TPipeRequestKey =
'EnqueueNotification' |
'EnqueueOverlay'

interface IPipeRequest {
key: TPipeRequestKey
password: string
nonce: string
data: IPipeRequestNotification|IPipeRequestOverlay
}

interface IPipeRequestNotification {
title: string
message: string
imageData?: string
imagePath?: string
nonce?: string
basicTitle?: string
basicMessage?: string
customProperties?: IPipeRequestCustomProperties
}

interface IPipeRequestCustomProperties {
enabled: boolean
interface IPipeRequestOverlay {
imageData?: string
imagePath?: string

anchorType: string
attachToAnchor: boolean
ignoreAnchorYaw: boolean
Expand All @@ -398,9 +432,9 @@ interface IPipeRequestCustomProperties {
pitchDeg: number
rollDeg: number

follow: IPipeRequestCustomPropertiesFollow
transitionIn: IPipeRequestCustomPropertiesTransition
transitionOut: IPipeRequestCustomPropertiesTransition
follow?: IPipeRequestCustomPropertiesFollow
transitionIn?: IPipeRequestCustomPropertiesTransition
transitionOut?: IPipeRequestCustomPropertiesTransition
animations: IPipeRequestCustomPropertiesAnimation[]
textAreas: IPipeRequestCustomPropertiesTextArea[]
}
Expand Down
9 changes: 7 additions & 2 deletions app/src/Shared/Objects/Data/Config/ConfigPipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import ConfigImageEditorRect, {ConfigImageEditorFontSettings, ConfigImageEditorO

export default class ConfigPipe extends AbstractData {
port: number = 8077
password: string = ''
useCustomChatNotification: boolean = false
customChatMessageConfig = new ConfigPipeCustomMessage()
customChatNameConfig = new ConfigPipeCustomMessageName()
Expand All @@ -14,14 +15,18 @@ export default class ConfigPipe extends AbstractData {
enlist() {
DataMap.addRootInstance({
instance: new ConfigPipe(),
description: 'In-VR-overlays and notifications with: https://github.com/BOLL7708/OpenVRNotificationPipe',
description: 'In-VR-overlays and notifications with: https://github.com/BOLL7708/OpenVROverlayPipe',
documentation: {
port: 'The port number set in OpenVRNotificationPipe.',
port: 'The port number set in OpenVROverlayPipe.',
password: 'The optional password for OpenVROverlayPipe.',
useCustomChatNotification: 'If on uses a custom notification graphic for text pipes into VR, instead of the default SteamVR notification.',
customChatMessageConfig: 'The text box settings for the custom chat notification text message.',
customChatNameConfig: 'The text box settings for the custom chat notification username.\nWill not be drawn if no username was supplied.',
customChatAvatarConfig: 'The settings for the custom chat notification avatar image.\nWill not be drawn if the image could not be loaded.',
cleanTextConfig: 'Configuration for cleaning the text before it is piped.'
},
types: {
password: 'string|secret'
}
})
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/Shared/Utils/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default class Utils {
return rest ? [first, rest.join(needle)] : [first]
}

static async sha256(message: string) {
static async hashPassword(message: string) {
const textBuffer = new TextEncoder().encode(message); // encode as UTF-8
const hashBuffer = await crypto.subtle.digest('SHA-256', textBuffer); // hash the message
const byteArray = Array.from(new Uint8Array(hashBuffer)); // convert ArrayBuffer to Array
Expand Down

0 comments on commit cc745ba

Please sign in to comment.