Compare commits
6 Commits
d04bd6a437
...
1.0.11
| Author | SHA1 | Date | |
|---|---|---|---|
| dc782003b0 | |||
| 2af9142d6c | |||
| 40905b225c | |||
| 77e032fdb2 | |||
| 96a5e5896b | |||
| 14fe7ef41d |
8
package-lock.json
generated
8
package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "chatenium-sdk",
|
||||
"version": "1.0.0",
|
||||
"name": "@chatenium/chatenium-sdk",
|
||||
"version": "1.0.8",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "chatenium-sdk",
|
||||
"version": "1.0.0",
|
||||
"name": "@chatenium/chatenium-sdk",
|
||||
"version": "1.0.8",
|
||||
"dependencies": {
|
||||
"@faker-js/faker": "^10.4.0",
|
||||
"axios": "^1.14.0",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@chatenium/chatenium-sdk",
|
||||
"version": "1.0.8",
|
||||
"version": "1.0.11",
|
||||
"description": "A library for interacting with the Chatenium API",
|
||||
"type": "module",
|
||||
"main": "dist/index.js",
|
||||
|
||||
@@ -64,9 +64,10 @@ export class WebSocketHandler {
|
||||
if (payl.action == "connectionId") {
|
||||
console.log("ConnectionID received")
|
||||
const data: WSConnIdPayload = JSON.parse(payl.data);
|
||||
this.connectionId = data.connId;
|
||||
this.listeners.forEach(listener => {
|
||||
console.log(data.connId, listener)
|
||||
listener.onNewConnId(data.connId)
|
||||
this.connectionId = data.connId;
|
||||
})
|
||||
} else {
|
||||
this.listeners.forEach(listener => {
|
||||
@@ -78,6 +79,7 @@ export class WebSocketHandler {
|
||||
}
|
||||
|
||||
public registerService(service: WSListenerPipe) {
|
||||
console.log("Registering service", service)
|
||||
this.listeners.add(service);
|
||||
}
|
||||
|
||||
|
||||
@@ -41,5 +41,5 @@ export interface FileData {
|
||||
}
|
||||
|
||||
export interface FileUploadProgressListener {
|
||||
fileProgressUpdate: (fileId: string, allChunks: number, chunksDone: number) => void
|
||||
fileProgressUpdate: (tempMsgId: string, fileId: string, allChunks: number, chunksDone: number) => void
|
||||
}
|
||||
@@ -23,7 +23,7 @@ describe("DmService", () => {
|
||||
|
||||
it('should send a new message', async () => {
|
||||
const message = faker.internet.displayName()
|
||||
const newMessage = await service.sendMessage(message)
|
||||
const newMessage = await service.sendMessage("", message)
|
||||
expect(newMessage.message).toBe(message)
|
||||
});
|
||||
})
|
||||
@@ -42,7 +42,7 @@ export class DMService {
|
||||
}
|
||||
|
||||
private onNewConnId(newConnId: string) {
|
||||
console.log("NetworkService: New connection id")
|
||||
console.log("DmService: New connection id")
|
||||
this.client.defaults.headers["X-WS-ID"] = newConnId;
|
||||
this.joinWebSocketRoom().then()
|
||||
}
|
||||
@@ -130,17 +130,18 @@ export class DMService {
|
||||
|
||||
/**
|
||||
* Sends a new message to the chat
|
||||
* @param tempMsgId
|
||||
* @param message
|
||||
* @param replyTo
|
||||
* @param replyToMessage
|
||||
* @param attachments
|
||||
* @param progressListener
|
||||
*/
|
||||
async sendMessage(message: string, replyTo: string | null = null, replyToMessage: string | null = null, attachments: FileData[] | null = null, progressListener: FileUploadProgressListener | null = null): Promise<Message> {
|
||||
async sendMessage(tempMsgId: string, message: string, replyTo: string | null = null, replyToMessage: string | null = null, attachments: FileData[] | null = null, progressListener: FileUploadProgressListener | null = null): Promise<Message> {
|
||||
let uploadId = ""
|
||||
if (attachments) {
|
||||
const uploader = new FileUploadService(this.token)
|
||||
uploadId = await uploader.uploadFiles(this.chatid, this.userid, attachments, progressListener!)
|
||||
uploadId = await uploader.uploadFiles(tempMsgId, this.chatid, this.userid, attachments, progressListener!)
|
||||
}
|
||||
try {
|
||||
const resp = await this.client.post<Message>("chat/dm/finishMessage", <FinishMessageReq>{
|
||||
|
||||
@@ -4,7 +4,7 @@ import {FileUploadService} from './fileUploadService.js';
|
||||
describe("fileUploadService", () => {
|
||||
it('should upload files', async () => {
|
||||
const service = new FileUploadService("");
|
||||
const uploadId = await service.uploadFiles("", "", [], {
|
||||
const uploadId = await service.uploadFiles("","", "", [], {
|
||||
fileProgressUpdate: () => {}
|
||||
})
|
||||
expect(uploadId).toBe("MockUploadId")
|
||||
|
||||
@@ -39,12 +39,13 @@ export class FileUploadService {
|
||||
|
||||
/**
|
||||
* Automatically registers the upload, calculates chunksize and uploads each chunk and returns with an uploadId that must be provided when sending the message
|
||||
* @param tempMsgId
|
||||
* @param roomId chatid or channelId
|
||||
* @param userid
|
||||
* @param files
|
||||
* @param listener
|
||||
*/
|
||||
async uploadFiles(roomId: string, userid: string, files: FileData[], listener: FileUploadProgressListener): Promise<string> {
|
||||
async uploadFiles(tempMsgId: string, roomId: string, userid: string, files: FileData[], listener: FileUploadProgressListener): Promise<string> {
|
||||
let registrations: FileUploadRegistration[] = [];
|
||||
|
||||
files.forEach(file => {
|
||||
@@ -63,7 +64,7 @@ export class FileUploadService {
|
||||
files: registrations,
|
||||
});
|
||||
for (let filesUploaded = 0; filesUploaded < files.length; filesUploaded++) {
|
||||
await this.uploadFile(resp.data.uploadId, roomId, userid, files[filesUploaded], registrations[filesUploaded], listener)
|
||||
await this.uploadFile(tempMsgId, resp.data.uploadId, roomId, userid, files[filesUploaded], registrations[filesUploaded], listener)
|
||||
}
|
||||
await this.finishUpload(roomId, userid, resp.data.uploadId)
|
||||
return resp.data.uploadId
|
||||
@@ -93,7 +94,7 @@ export class FileUploadService {
|
||||
}
|
||||
}
|
||||
|
||||
private async uploadFile(uploadId: string, roomId: string, userid: string, file: FileData, registration: FileUploadRegistration, listener: FileUploadProgressListener): Promise<void> {
|
||||
private async uploadFile(tempMsgId: string, uploadId: string, roomId: string, userid: string, file: FileData, registration: FileUploadRegistration, listener: FileUploadProgressListener): Promise<void> {
|
||||
const chunkSize = this.calculateChunkSize(file.data.size);
|
||||
const totalChunks = Math.ceil(file.data.size / chunkSize);
|
||||
|
||||
@@ -105,7 +106,7 @@ export class FileUploadService {
|
||||
const chunk = new Uint8Array(arrayBuffer.slice(start, end));
|
||||
const base64 = this.uint8ToBase64(chunk);
|
||||
await this.uploadChunk(uploadId, roomId, userid, registration.fileId, base64);
|
||||
listener.fileProgressUpdate(file.fileId, totalChunks, i)
|
||||
listener.fileProgressUpdate(tempMsgId, file.fileId, totalChunks, i)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -137,17 +137,18 @@ export class TextChannelServiceService {
|
||||
|
||||
/**
|
||||
* Sends a new message to the chat
|
||||
* @param tempMsgId
|
||||
* @param message
|
||||
* @param replyTo
|
||||
* @param replyToMessage
|
||||
* @param attachments
|
||||
* @param progressListener
|
||||
*/
|
||||
async sendMessage(message: string, replyTo: string | null = null, replyToMessage: string | null = null, attachments: FileData[] | null = null, progressListener: FileUploadProgressListener | null = null): Promise<Message> {
|
||||
async sendMessage(tempMsgId: string, message: string, replyTo: string | null = null, replyToMessage: string | null = null, attachments: FileData[] | null = null, progressListener: FileUploadProgressListener | null = null): Promise<Message> {
|
||||
let uploadId = ""
|
||||
if (attachments) {
|
||||
const uploader = new FileUploadService(this.token)
|
||||
uploadId = await uploader.uploadFiles(this.channelId, this.userid, attachments, progressListener!)
|
||||
uploadId = await uploader.uploadFiles(tempMsgId, this.channelId, this.userid, attachments, progressListener!)
|
||||
}
|
||||
try {
|
||||
const resp = await this.client.post<Message>("network/channel/finishMessage", <FinishMessageReq>{
|
||||
|
||||
@@ -38,7 +38,7 @@ describe("DmService Integration Testing", () => {
|
||||
|
||||
it('should send a message', async () => {
|
||||
const message = faker.lorem.paragraph()
|
||||
const newMessage = await service.sendMessage(message)
|
||||
const newMessage = await service.sendMessage("", message)
|
||||
expect(newMessage.message).toBe(message)
|
||||
});
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ describe("DmService Integration Testing", () => {
|
||||
|
||||
it('should send a message', async () => {
|
||||
const message = faker.lorem.paragraph()
|
||||
const newMessage = await service.sendMessage(message)
|
||||
const newMessage = await service.sendMessage("", message)
|
||||
expect(newMessage.message).toBe(message)
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user