add more info about sync

main
Cogent Apps 2023-03-08 13:45:15 -08:00 committed by GitHub
parent f5c20db0b5
commit d82346fec0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 25 additions and 4 deletions

View File

@ -1,6 +1,27 @@
import EventEmitter from 'events';
import { Chat } from './types';
/*
Sync and login requires a backend implementation.
Example syncing:
const customBackend = new MyCustomBackend();
customBackend.register();
In your custom backend, load saved chats from the server and call chatManager.loadChat(chat);
chatManager.on('messages', async (messages: Message[]) => {
// send messages to server
});
chatManager.on('title', async (id: string, title: string) => {
// send updated chat title to server
});
*/
export let backend: Backend | null = null;
export class Backend extends EventEmitter {
@ -13,21 +34,21 @@ export class Backend extends EventEmitter {
}
get isAuthenticated() {
// return whether the user is currently signed in
return false;
}
async signIn(options?: any) {
// sign in the user
}
async shareChat(chat: Chat): Promise<string|null> {
// create a public share from the chat, and return the share's ID
return null;
}
async getSharedChat(id: string): Promise<Chat|null> {
// load a publicly shared chat from its ID
return null;
}
}
export function getBackend() {
return backend;
}