From 9efd191f4eccb5d00b06ee2c4804294c6d5168d2 Mon Sep 17 00:00:00 2001 From: Bruno Windels <274386+bwindels@users.noreply.github.com> Date: Tue, 22 Mar 2022 20:29:31 +0100 Subject: [PATCH] some more fixes --- src/domain/session/room/CallViewModel.ts | 1 - src/domain/session/room/RoomViewModel.js | 17 +++++++++++------ src/matrix/Session.js | 6 +++++- src/matrix/calls/CallHandler.ts | 3 +++ src/matrix/calls/group/GroupCall.ts | 5 ++++- src/observable/value/PickMapObservableValue.ts | 4 +++- src/platform/web/ui/session/room/CallView.ts | 6 +++--- 7 files changed, 29 insertions(+), 13 deletions(-) diff --git a/src/domain/session/room/CallViewModel.ts b/src/domain/session/room/CallViewModel.ts index 95d9b188..7fcabf02 100644 --- a/src/domain/session/room/CallViewModel.ts +++ b/src/domain/session/room/CallViewModel.ts @@ -42,7 +42,6 @@ export class CallViewModel extends ViewModel { } get localTracks(): Track[] { - console.log("localTracks", this.getOption("call").localMedia); return this.getOption("call").localMedia?.tracks ?? []; } } diff --git a/src/domain/session/room/RoomViewModel.js b/src/domain/session/room/RoomViewModel.js index 1d4bca42..81ca58d2 100644 --- a/src/domain/session/room/RoomViewModel.js +++ b/src/domain/session/room/RoomViewModel.js @@ -347,12 +347,17 @@ export class RoomViewModel extends ViewModel { } async startCall() { - const session = this.getOption("session"); - const mediaTracks = await this.platform.mediaDevices.getMediaTracks(true, true); - const localMedia = new LocalMedia().withTracks(mediaTracks); - console.log("localMedia", localMedia.tracks); - // this will set the callViewModel above as a call will be added to callHandler.calls - await session.callHandler.createCall(this._room.id, localMedia, "A call " + Math.round(this.platform.random() * 100)); + try { + const session = this.getOption("session"); + const mediaTracks = await this.platform.mediaDevices.getMediaTracks(true, true); + const localMedia = new LocalMedia().withTracks(mediaTracks); + console.log("localMedia", localMedia.tracks); + // this will set the callViewModel above as a call will be added to callHandler.calls + await session.callHandler.createCall(this._room.id, localMedia, "A call " + Math.round(this.platform.random() * 100)); + } catch (err) { + console.error(err.stack); + alert(err.message); + } } } diff --git a/src/matrix/Session.js b/src/matrix/Session.js index dbc0b17e..e604e068 100644 --- a/src/matrix/Session.js +++ b/src/matrix/Session.js @@ -88,7 +88,11 @@ export class Session { const devices = await this._deviceTracker.devicesForTrackedRoom(roomId, this._hsApi, log); const encryptedMessage = await this._olmEncryption.encrypt(message.type, message.content, devices, this._hsApi, log); return encryptedMessage; - } + }, + storage: this._storage, + webRTC: this._platform.webRTC, + ownDeviceId: sessionInfo.deviceId, + ownUserId: sessionInfo.userId, }); this._deviceMessageHandler = new DeviceMessageHandler({storage, callHandler: this._callHandler}); this._olm = olm; diff --git a/src/matrix/calls/CallHandler.ts b/src/matrix/calls/CallHandler.ts index a9b59f4f..269f6020 100644 --- a/src/matrix/calls/CallHandler.ts +++ b/src/matrix/calls/CallHandler.ts @@ -63,7 +63,9 @@ export class CallHandler { } throw err; } + console.log("joining call I just created"); await call.join(localMedia); + console.log("joined!"); return call; } @@ -73,6 +75,7 @@ export class CallHandler { /** @internal */ handleRoomState(room: Room, events: StateEvent[], log: ILogItem) { + console.log("handling room state"); // first update call events for (const event of events) { if (event.type === EventType.GroupCall) { diff --git a/src/matrix/calls/group/GroupCall.ts b/src/matrix/calls/group/GroupCall.ts index 8ea4528a..d22135d1 100644 --- a/src/matrix/calls/group/GroupCall.ts +++ b/src/matrix/calls/group/GroupCall.ts @@ -49,7 +49,7 @@ export type Options = Omit = new ObservableMap(); - private _localMedia?: LocalMedia; + private _localMedia?: LocalMedia = undefined; private _memberOptions: MemberOptions; private _state: GroupCallState; @@ -87,10 +87,12 @@ export class GroupCall { } this._state = GroupCallState.Joining; this._localMedia = localMedia; + this.options.emitUpdate(this); const memberContent = await this._joinCallMemberContent(); // send m.call.member state event const request = this.options.hsApi.sendState(this.roomId, "m.call.member", this.options.ownUserId, memberContent); await request.response(); + this.options.emitUpdate(this); // send invite to all members that are < my userId for (const [,member] of this._members) { member.connect(this._localMedia); @@ -119,6 +121,7 @@ export class GroupCall { }; const request = this.options.hsApi.sendState(this.roomId, "m.call", this.id, this.callContent); await request.response(); + this._state = GroupCallState.Created; } /** @internal */ diff --git a/src/observable/value/PickMapObservableValue.ts b/src/observable/value/PickMapObservableValue.ts index a20ec04e..67f9d562 100644 --- a/src/observable/value/PickMapObservableValue.ts +++ b/src/observable/value/PickMapObservableValue.ts @@ -53,7 +53,9 @@ export class PickMapObservableValue extends BaseObservableValue(t: TemplateBuilder, video: HTMLVideoElement, prop export class CallView extends TemplateView { render(t: TemplateBuilder, vm: CallViewModel): HTMLElement { return t.div({class: "CallView"}, [ - t.p(`Call ${vm.name} (${vm.id})`), - t.div({class: "CallView_me"}, bindVideoTracks(t, t.video(), vm => vm.localTracks)), + t.p(["Call ", vm => vm.name, vm => ` (${vm.id})`]), + t.div({class: "CallView_me"}, bindVideoTracks(t, t.video({autoplay: true}), vm => vm.localTracks)), t.view(new ListView({list: vm.memberViewModels}, vm => new MemberView(vm))) ]); } @@ -42,6 +42,6 @@ export class CallView extends TemplateView { class MemberView extends TemplateView { render(t: TemplateBuilder, vm: CallMemberViewModel) { - return bindVideoTracks(t, t.video(), vm => vm.tracks); + return bindVideoTracks(t, t.video({autoplay: true}), vm => vm.tracks); } }