Merge branch 'bwindels/calls' into calls-show-toast

This commit is contained in:
Bruno Windels 2023-01-26 11:50:52 +01:00
commit 725757e235
5 changed files with 94 additions and 15 deletions

View File

@ -141,7 +141,7 @@ export class GroupCall extends EventEmitter<{change: never}> {
get members(): BaseObservableMap<string, Member> { return this._members; }
get isTerminated(): boolean {
return this.callContent?.["m.terminated"] === true;
return !!this.callContent?.["m.terminated"];
}
get isRinging(): boolean {
@ -287,7 +287,7 @@ export class GroupCall extends EventEmitter<{change: never}> {
const request = this.options.hsApi.sendState(this.roomId, EventType.GroupCallMember, this.options.ownUserId, memberContent, {log});
await request.response();
// our own user isn't included in members, so not in the count
if (this.intent === CallIntent.Ring && this._members.size === 0) {
if ((this.intent === CallIntent.Ring || this.intent === CallIntent.Prompt) && this._members.size === 0) {
await this.terminate(log);
}
} else {

View File

@ -18,6 +18,7 @@ import {BaseObservable} from "../BaseObservable";
import {JoinedMap} from "./index";
import {MappedMap} from "./index";
import {FilteredMap} from "./index";
import {BaseObservableValue, MapSizeObservableValue} from "../value/index";
import {SortedMapList} from "../list/SortedMapList.js";
@ -80,6 +81,10 @@ export abstract class BaseObservableMap<K, V> extends BaseObservable<IMapObserve
return new FilteredMap(this, filter);
}
observeSize(): BaseObservableValue<number> {
return new MapSizeObservableValue(this);
}
abstract [Symbol.iterator](): Iterator<[K, V]>;
abstract get size(): number;
abstract get(key: K): V | undefined;

View File

@ -0,0 +1,71 @@
/*
Copyright 2022 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import {BaseObservableValue} from "./index";
import {BaseObservableMap} from "../map/index";
import type {SubscriptionHandle} from "../BaseObservable";
export class MapSizeObservableValue<K, V> extends BaseObservableValue<number> {
private subscription?: SubscriptionHandle;
constructor(private readonly map: BaseObservableMap<K, V>)
{
super();
}
onSubscribeFirst(): void {
this.subscription = this.map.subscribe({
onAdd: (key: K, value: V) => {
this.emit(this.get());
},
onRemove: (key: K, value: V) => {
this.emit(this.get());
},
onUpdate: (key: K, value: V) => {},
onReset: () => {
this.emit(this.get());
},
});
}
onUnsubscribeLast(): void {
this.subscription = this.subscription?.();
}
get(): number {
return this.map.size;
}
}
import {ObservableMap} from "../map/index";
export function tests() {
return {
"emits update on add and remove": assert => {
const map = new ObservableMap<string, number>();
const size = new MapSizeObservableValue(map);
const updates: number[] = [];
size.subscribe(size => {
updates.push(size);
});
map.add("hello", 1);
map.add("world", 2);
map.remove("world");
map.remove("hello");
assert.deepEqual(updates, [1, 2, 1, 0]);
}
};
}

View File

@ -12,4 +12,5 @@ export {EventObservableValue} from './EventObservableValue';
export {FlatMapObservableValue} from './FlatMapObservableValue';
export {PickMapObservableValue} from './PickMapObservableValue';
export {RetainedObservableValue} from './RetainedObservableValue';
export {MapSizeObservableValue} from './MapSizeObservableValue';
export {ObservableValue} from './ObservableValue';

View File

@ -25,11 +25,13 @@ limitations under the License.
}
.CallView_error {
color: red;
font-weight: bold;
align-self: start;
justify-self: center;
margin: 16px;
/** Chrome (v100) requires this to make the buttons clickable
* where they overlap with the video element, even though
* the buttons come later in the DOM. */
z-index: 1;
}
.CallView_members {