Add array concat util (#9306)
This commit is contained in:
@@ -18,6 +18,7 @@ import { IEncryptedFile, MatrixClient } from "matrix-js-sdk/src/matrix";
|
||||
import { SimpleObservable } from "matrix-widget-api";
|
||||
|
||||
import { uploadFile } from "../ContentMessages";
|
||||
import { concat } from "../utils/arrays";
|
||||
import { IDestroyable } from "../utils/IDestroyable";
|
||||
import { Singleflight } from "../utils/Singleflight";
|
||||
import { Playback } from "./Playback";
|
||||
@@ -148,10 +149,7 @@ export class VoiceMessageRecording implements IDestroyable {
|
||||
|
||||
private onDataAvailable = (data: ArrayBuffer) => {
|
||||
const buf = new Uint8Array(data);
|
||||
const newBuf = new Uint8Array(this.buffer.length + buf.length);
|
||||
newBuf.set(this.buffer, 0);
|
||||
newBuf.set(buf, this.buffer.length);
|
||||
this.buffer = newBuf;
|
||||
this.buffer = concat(this.buffer, buf);
|
||||
};
|
||||
|
||||
private get audioBuffer(): Uint8Array {
|
||||
|
||||
@@ -304,3 +304,12 @@ export class GroupedArray<K, T> {
|
||||
return new ArrayUtil(a);
|
||||
}
|
||||
}
|
||||
|
||||
export const concat = (...arrays: Uint8Array[]): Uint8Array => {
|
||||
return arrays.reduce((concatenatedSoFar: Uint8Array, toBeConcatenated: Uint8Array) => {
|
||||
const concatenated = new Uint8Array(concatenatedSoFar.length + toBeConcatenated.length);
|
||||
concatenated.set(concatenatedSoFar, 0);
|
||||
concatenated.set(toBeConcatenated, concatenatedSoFar.length);
|
||||
return concatenated;
|
||||
}, new Uint8Array(0));
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user