Implemented SessionManager and TextChannelService + several improvements and fixes
All checks were successful
Setup testing environment and test the code / build (push) Successful in 1m13s
All checks were successful
Setup testing environment and test the code / build (push) Successful in 1m13s
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import {
|
||||
ChunkUploadReq,
|
||||
FileData,
|
||||
FileData, FileUploadProgressListener,
|
||||
FileUploadRegistration, FinishUploadReq,
|
||||
RegisterUploadReq,
|
||||
RegisterUploadResp
|
||||
@@ -42,13 +42,14 @@ export class FileUploadService {
|
||||
* @param roomId chatid or channelId
|
||||
* @param userid
|
||||
* @param files
|
||||
* @param listener
|
||||
*/
|
||||
async uploadFiles(roomId: string, userid: string, files: FileData[]): Promise<string> {
|
||||
async uploadFiles(roomId: string, userid: string, files: FileData[], listener: FileUploadProgressListener): Promise<string> {
|
||||
let registrations: FileUploadRegistration[] = [];
|
||||
|
||||
files.forEach(file => {
|
||||
registrations.push({
|
||||
fileId: uuidv4(),
|
||||
fileId: file.fileId,
|
||||
name: file.name,
|
||||
type: file.type,
|
||||
size: file.data.size,
|
||||
@@ -62,7 +63,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])
|
||||
await this.uploadFile(resp.data.uploadId, roomId, userid, files[filesUploaded], registrations[filesUploaded], listener)
|
||||
}
|
||||
await this.finishUpload(roomId, userid, resp.data.uploadId)
|
||||
return resp.data.uploadId
|
||||
@@ -92,7 +93,7 @@ export class FileUploadService {
|
||||
}
|
||||
}
|
||||
|
||||
private async uploadFile(uploadId: string, roomId: string, userid: string, file: FileData, registration: FileUploadRegistration): Promise<void> {
|
||||
private async uploadFile(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);
|
||||
|
||||
@@ -104,6 +105,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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user