Compare commits

4 Commits

Author SHA1 Message Date
6ca518af56 ci: version bump to 0.0.2 2023-02-14 00:14:53 +01:00
c4a7ba98b8 fix: implement whispering 2023-02-14 00:00:47 +01:00
89311aa4d8 fix: fix channel listing
`channelViewers` is now updated properly
2023-02-13 23:09:31 +01:00
071ae4545a ci: update repo link 2023-02-11 18:47:09 +01:00
5 changed files with 15 additions and 24 deletions

3
.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
dist
node_modules
.log

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{ {
"name": "fedwave-chat-client", "name": "fedwave-chat-client",
"version": "1.0.0-0", "version": "0.0.2",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "fedwave-chat-client", "name": "fedwave-chat-client",
"version": "1.0.0-0", "version": "0.0.2",
"license": "LGPL-3.0", "license": "LGPL-3.0",
"dependencies": { "dependencies": {
"socket.io-client": "^3.1.3" "socket.io-client": "^3.1.3"

View File

@@ -1,8 +1,8 @@
{ {
"name": "fedwave-chat-client", "name": "fedwave-chat-client",
"version": "0.0.1", "version": "0.0.2",
"description": "Basic API client for a [fedwave] chat server", "description": "Basic API client for a [fedwave] chat server",
"repository": "github:bitwave-tv/chat-client", "repository": "https://git.dvdrw.dev/dvdrw/fedwave-chat-client",
"author": "dvdrw", "author": "dvdrw",
"license": "LGPL-2.0", "license": "LGPL-2.0",
"types": "dist/index.d.ts", "types": "dist/index.d.ts",

View File

@@ -27,13 +27,6 @@ export interface OutgoingMessage {
export type Credentials = string | Token | void; 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 { export interface Token {
recaptcha: any; recaptcha: any;
page: string; page: string;
@@ -114,7 +107,8 @@ export class FedwaveChat {
*/ */
public async updateUsernames(): Promise<void> { public async updateUsernames(): Promise<void> {
try { 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) { if (data && data.success) {
await this.onUpdateUsernames(data.data); await this.onUpdateUsernames(data.data);
this.channelViewers = data.data; this.channelViewers = data.data;
@@ -301,9 +295,8 @@ export class FedwaveChat {
} }
async sendWhisper(recipient: string, msg: string): Promise<void> { async sendWhisper(recipient: string, msg: string): Promise<void> {
await $http.post(this._whisperEndpoint[0], this._whisperEndpoint[1], { this._socket.emit("whisper", {
chatToken: this.userProfile.jwt, to: recipient,
receiver: recipient,
message: msg, message: msg,
}); });
} }

View File

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