fix: fix channel listing

`channelViewers` is now updated properly
This commit is contained in:
Upkeep 2023-02-13 23:09:31 +01:00
parent 071ae4545a
commit 89311aa4d8
Signed by: dvdrw
GPG Key ID: 044B8425E3CD03E0
2 changed files with 7 additions and 18 deletions

View File

@ -27,13 +27,6 @@ export interface OutgoingMessage {
export type Credentials = string | Token | void;
const apiPrefix = "https://api.bitwave.tv/api/";
const chatServer = "https://chat.bitwave.tv";
const whisperEndpoint: [string, string] = [
"api.bitwave.tv",
"/v1/whispers/send",
];
export interface Token {
recaptcha: any;
page: string;
@ -114,7 +107,8 @@ export class FedwaveChat {
*/
public async updateUsernames(): Promise<void> {
try {
const data = await $http.get(this._apiPrefix + "/v1/chat/channels");
const res = await $http.get(this._apiPrefix + "/v1/chat/channels");
const data = JSON.parse(res);
if (data && data.success) {
await this.onUpdateUsernames(data.data);
this.channelViewers = data.data;
@ -301,7 +295,7 @@ export class FedwaveChat {
}
async sendWhisper(recipient: string, msg: string): Promise<void> {
await $http.post(this._whisperEndpoint[0], this._whisperEndpoint[1], {
await $http.post(this._apiPrefix + this._whisperEndpoint, {
chatToken: this.userProfile.jwt,
receiver: recipient,
message: msg,

View File

@ -11,19 +11,14 @@ const $get = (url: string, cb: Function): void => {
req.send(null);
};
const $post = (
url: string,
path: string,
data: any,
cb: (...args: any[]) => void
): void => {
const $post = (url: string, data: any, cb: (...args: any[]) => void): void => {
const req = new XMLHttpRequest();
req.onreadystatechange = () => {
if (req.readyState === 4 && req.status === 200) {
cb(JSON.parse(req.responseText));
}
};
req.open("POST", url + path);
req.open("POST", url);
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
req.setRequestHeader("X-Requested-With", "XMLHttpRequest");
@ -37,9 +32,9 @@ export default {
$get(url, (response) => resolve(response));
});
},
post: (url: string, path: string, data: Object): Promise<any> => {
post: (url: string, data: Object): Promise<any> => {
return new Promise((resolve) => {
$post(url, path, data, (response) => resolve(response));
$post(url, data, (response) => resolve(response));
});
},
};