2022-11-19 01:06:03 +00:00
|
|
|
import { ConsoleHelper } from "../../ConsoleHelper";
|
2023-09-10 12:59:22 +01:00
|
|
|
import DataStream from "./DataStream";
|
|
|
|
import FunkyArray from "./FunkyArray";
|
|
|
|
import User from "./User";
|
2022-11-19 01:06:03 +00:00
|
|
|
|
2023-09-10 12:59:22 +01:00
|
|
|
export default class DataStreamArray extends FunkyArray<DataStream> {
|
2022-11-19 01:06:03 +00:00
|
|
|
public CreateStream(name:string, removeWhenEmpty:boolean = true) : DataStream {
|
|
|
|
const dataStream:DataStream = this.add(name, new DataStream(name, this, removeWhenEmpty));
|
|
|
|
ConsoleHelper.printStream(`Created stream [${name}]`);
|
|
|
|
return dataStream;
|
|
|
|
}
|
|
|
|
|
2022-11-19 15:06:03 +00:00
|
|
|
public DeleteStream(stream:DataStream | string) {
|
|
|
|
const isObject = stream instanceof DataStream;
|
|
|
|
if (isObject) {
|
|
|
|
stream.Deactivate();
|
|
|
|
this.remove(stream.name);
|
|
|
|
} else {
|
|
|
|
const dso = this.getByKey(stream);
|
|
|
|
if (dso != null) {
|
|
|
|
dso.Deactivate();
|
|
|
|
}
|
|
|
|
this.remove(stream);
|
|
|
|
}
|
|
|
|
ConsoleHelper.printStream(`Deleted stream [${isObject ? stream.name : stream}]`);
|
|
|
|
}
|
|
|
|
|
2022-11-19 01:06:03 +00:00
|
|
|
public RemoveUserFromAllStreams(user:User) {
|
|
|
|
for (let stream of this.getIterableItems()) {
|
|
|
|
stream.RemoveUser(user);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|