owncast/web/services/chat-service.ts

35 lines
936 B
TypeScript
Raw Normal View History

import { ChatMessage } from '../interfaces/chat-message.model';
import { getUnauthedData } from '../utils/apis';
const ENDPOINT = `/api/chat`;
const URL_CHAT_REGISTRATION = `/api/chat/register`;
2022-04-27 00:04:35 +03:00
interface UserRegistrationResponse {
id: string;
accessToken: string;
displayName: string;
displayColor: number;
2022-04-27 00:04:35 +03:00
}
class ChatService {
public static async getChatHistory(accessToken: string): Promise<ChatMessage[]> {
const response = await getUnauthedData(`${ENDPOINT}?accessToken=${accessToken}`);
return response;
}
public static async registerUser(username: string): Promise<UserRegistrationResponse> {
2022-04-27 00:04:35 +03:00
const options = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ displayName: username }),
};
const response = await getUnauthedData(URL_CHAT_REGISTRATION, options);
return response;
2022-04-27 00:04:35 +03:00
}
}
export default ChatService;