You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
1.9 KiB
74 lines
1.9 KiB
import { invoke } from '@tauri-apps/api/core';
|
|
import { listen } from '@tauri-apps/api/event';
|
|
import { fetch } from '@tauri-apps/plugin-http';
|
|
|
|
export const OSC_ADDRESS={
|
|
LIGHT: '/light',
|
|
STATUS: '/status',
|
|
INPUT: '/input',
|
|
COUNTDOWN: '/countdown',
|
|
VOLUME: '/volume',
|
|
SCRIPT: '/script',
|
|
SUMMARY: '/summary',
|
|
PROMPT: '/prompt',
|
|
EXPORT: '/export',
|
|
CHOICE:'/choice',
|
|
SAVE: 'save',
|
|
DISCARD: 'discard',
|
|
PASSWORD: '/password',
|
|
HINT:'/hint',
|
|
}
|
|
|
|
|
|
export async function sendOsc(key, message){
|
|
|
|
if(message === undefined || message === null) {
|
|
console.warn('sendOsc: message is empty, skipping');
|
|
return;
|
|
}
|
|
// if(key!=OSC_ADDRESS.HINT && message === '') {
|
|
// return;
|
|
// }
|
|
|
|
try{
|
|
console.log(`Sending OSC message: ${key} -> ${message}`);
|
|
await invoke('send_osc_message', {
|
|
key: key,
|
|
message: message.toString(),
|
|
host:`0.0.0.0:0`,
|
|
target: '127.0.0.1:9000',
|
|
});
|
|
}catch (error){
|
|
console.error('Error sending OSC message:', error);
|
|
}
|
|
}
|
|
|
|
|
|
// send to python fastapi
|
|
export async function updatePrompt(prompt) {
|
|
console.log(`Updating prompt: ${prompt}`);
|
|
|
|
try{
|
|
await fetch('http://localhost:34800/api/update/prompt', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify({ prompt })
|
|
});
|
|
}catch(error){
|
|
console.error('Error updating prompt:', error);
|
|
}
|
|
}
|
|
|
|
|
|
export function onOscMessageReceived(callback) {
|
|
try{
|
|
listen('osc_message', (event) => {
|
|
console.log(`Received OSC message: ${event.payload}`);
|
|
callback(event.payload);
|
|
});
|
|
}catch(error){
|
|
console.error('Error setting up OSC message listener:', error);
|
|
}
|
|
} |