- Añade componente LiveChatBox con Realtime de Appwrite (subscribe) - Integra chat en vivo junto al player en /tv con layout 2/3 + 1/3 - Nueva ruta /tv/overlay: página transparente para browser source en OBS con renderizadores de LOWER_THIRD, TICKER y COMMENT reactivos en Realtime - Exporta 'account' desde appwrite.ts para autenticación cliente - Incluye scripts setup_live_chat.js y setup_stream_state.js para provisionar colecciones live_chat y stream_state en Appwrite - Ajusta versiones SDK: appwrite@22.4.1 y node-appwrite@22.0.0 (compatibles con servidor 1.8.1)
45 lines
1.6 KiB
JavaScript
45 lines
1.6 KiB
JavaScript
const { Client, Databases, ID, Permission, Role } = require('node-appwrite');
|
|
require('dotenv').config({ path: '.env.local' });
|
|
|
|
async function setupLiveChat() {
|
|
console.log("Configuring Live Chat collection...");
|
|
const client = new Client()
|
|
.setEndpoint(process.env.NEXT_PUBLIC_APPWRITE_ENDPOINT)
|
|
.setProject(process.env.NEXT_PUBLIC_APPWRITE_PROJECT)
|
|
.setKey(process.env.APPWRITE_API_KEY);
|
|
|
|
const databases = new Databases(client);
|
|
const dbId = process.env.NEXT_PUBLIC_APPWRITE_DATABASE;
|
|
|
|
try {
|
|
const collection = await databases.createCollection(
|
|
dbId,
|
|
'live_chat',
|
|
'Live Chat',
|
|
[
|
|
Permission.read(Role.any()),
|
|
Permission.create(Role.users()), // Logged in users can chat
|
|
Permission.update(Role.team('admin')),
|
|
Permission.delete(Role.team('admin')),
|
|
]
|
|
);
|
|
console.log("Collection 'live_chat' created.");
|
|
|
|
// Attributes
|
|
await databases.createStringAttribute(dbId, 'live_chat', 'user_id', 50, true);
|
|
await databases.createStringAttribute(dbId, 'live_chat', 'user_name', 100, true);
|
|
await databases.createStringAttribute(dbId, 'live_chat', 'message', 500, true);
|
|
await databases.createDatetimeAttribute(dbId, 'live_chat', 'timestamp', true);
|
|
|
|
console.log("Attributes created.");
|
|
} catch (e) {
|
|
if (e.code === 409) {
|
|
console.log("Collection already exists.");
|
|
} else {
|
|
console.error("Error creating collection:", e);
|
|
}
|
|
}
|
|
}
|
|
|
|
setupLiveChat();
|