fix updates from call and member classes in VM

this fixes this.emitChange sending the update over the
collection in the call member VM, which is how updates
are subscribed to by the UI.

It also adds a callback to the VM for when the member
sends an update, so we can check later on if the error
on the member has been set.
This commit is contained in:
Bruno Windels 2023-01-12 14:36:39 +01:00
parent 42ee2d294b
commit 64d6db556a

View File

@ -40,14 +40,19 @@ export class CallViewModel extends ViewModel<Options> {
constructor(options: Options) {
super(options);
const callObservable = new EventObservableValue(this.call, "change");
this.track(callObservable.subscribe(() => {
this.emitChange();
}));
this.track(callObservable.subscribe(() => this.onUpdate()));
const ownMemberViewModelMap = new ObservableValueMap("self", callObservable)
.mapValues((call, emitChange) => new OwnMemberViewModel(this.childOptions({call, emitChange})), () => {});
this.memberViewModels = this.call.members
.filterValues(member => member.isConnected)
.mapValues(member => new CallMemberViewModel(this.childOptions({member, mediaRepository: this.getOption("room").mediaRepository})))
.mapValues(
(member, emitChange) => new CallMemberViewModel(this.childOptions({
member,
emitChange,
mediaRepository: this.getOption("room").mediaRepository
})),
(vm: CallMemberViewModel) => vm.onUpdate(),
)
.join(ownMemberViewModelMap)
.sortValues((a, b) => a.compare(b));
this.track(this.memberViewModels.subscribe({
@ -91,6 +96,9 @@ export class CallViewModel extends ViewModel<Options> {
return this.getOption("call");
}
private onUpdate() {
}
async hangup() {
if (this.call.hasJoined) {
await this.call.leave();
@ -241,6 +249,8 @@ export class CallMemberViewModel extends ViewModel<MemberOptions> implements ISt
return this.member.member.name;
}
onUpdate() {
}
compare(other: OwnMemberViewModel | CallMemberViewModel): number {
if (other instanceof OwnMemberViewModel) {
return -other.compare(this);