Make CallHandler
more EventEmitter
y (#6704)
* sharedInstance() -> instance Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com> * Use CallState event instead of dispatching Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com> * Simplifie some code Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com> * Use a method to start a call instead of the dispatcher Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com> * Use a method instead of place_conference_call Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com> * Make terminateCallApp() and hangupCallApp() public Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com> * Use hangupAllCalls() instead of the dispatcher Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com> * Make dialNumber(), startTransferToMatrixID() and startTransferToPhoneNumber() public instead of using the dispatcher Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com> * Use answerCall() instead of using the dispatcher Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com> * Use hangupOrReject() instead of the dispatcher Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com> * Update docs Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com> * Improve TS Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com> * Dispatch call_state, see https://github.com/vector-im/element-web/pull/18823#issuecomment-917377277 Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com> * Add missing import Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
This commit is contained in:
parent
e3187ed15c
commit
cbb34d8ac7
23 changed files with 300 additions and 511 deletions
|
@ -16,16 +16,16 @@ limitations under the License.
|
|||
|
||||
import './skinned-sdk';
|
||||
|
||||
import CallHandler, { PlaceCallType, CallHandlerEvent } from '../src/CallHandler';
|
||||
import CallHandler, { CallHandlerEvent } from '../src/CallHandler';
|
||||
import { stubClient, mkStubRoom } from './test-utils';
|
||||
import { MatrixClientPeg } from '../src/MatrixClientPeg';
|
||||
import dis from '../src/dispatcher/dispatcher';
|
||||
import { CallEvent, CallState } from 'matrix-js-sdk/src/webrtc/call';
|
||||
import { CallEvent, CallState, CallType } from 'matrix-js-sdk/src/webrtc/call';
|
||||
import DMRoomMap from '../src/utils/DMRoomMap';
|
||||
import EventEmitter from 'events';
|
||||
import SdkConfig from '../src/SdkConfig';
|
||||
import { ActionPayload } from '../src/dispatcher/payloads';
|
||||
import { Action } from '../src/dispatcher/actions';
|
||||
import { Action } from "../src/dispatcher/actions";
|
||||
|
||||
const REAL_ROOM_ID = '$room1:example.org';
|
||||
const MAPPED_ROOM_ID = '$room2:example.org';
|
||||
|
@ -88,6 +88,14 @@ function untilDispatch(waitForAction: string): Promise<ActionPayload> {
|
|||
});
|
||||
}
|
||||
|
||||
function untilCallHandlerEvent(callHandler: CallHandler, event: CallHandlerEvent): Promise<void> {
|
||||
return new Promise<void>((resolve) => {
|
||||
callHandler.addListener(event, () => {
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
describe('CallHandler', () => {
|
||||
let dmRoomMap;
|
||||
let callHandler;
|
||||
|
@ -173,10 +181,7 @@ describe('CallHandler', () => {
|
|||
},
|
||||
}]);
|
||||
|
||||
dis.dispatch({
|
||||
action: Action.DialNumber,
|
||||
number: '01818118181',
|
||||
}, true);
|
||||
await callHandler.dialNumber('01818118181');
|
||||
|
||||
const viewRoomPayload = await untilDispatch(Action.ViewRoom);
|
||||
expect(viewRoomPayload.room_id).toEqual(MAPPED_ROOM_ID);
|
||||
|
@ -186,14 +191,9 @@ describe('CallHandler', () => {
|
|||
});
|
||||
|
||||
it('should move calls between rooms when remote asserted identity changes', async () => {
|
||||
dis.dispatch({
|
||||
action: 'place_call',
|
||||
type: PlaceCallType.Voice,
|
||||
room_id: REAL_ROOM_ID,
|
||||
}, true);
|
||||
callHandler.placeCall(REAL_ROOM_ID, CallType.Voice);
|
||||
|
||||
// wait for the call to be set up
|
||||
await untilDispatch('call_state');
|
||||
await untilCallHandlerEvent(callHandler, CallHandlerEvent.CallState);
|
||||
|
||||
// should start off in the actual room ID it's in at the protocol level
|
||||
expect(callHandler.getCallForRoom(REAL_ROOM_ID)).toBe(fakeCall);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue