Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit ce47856

Browse files
authored
Merge pull request #5340 from matrix-org/dbkr/voip_analytics
Add analytics to VoIP
2 parents 92f89b8 + 88b7210 commit ce47856

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/CallHandler.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ import WidgetStore from "./stores/WidgetStore";
7878
import { WidgetMessagingStore } from "./stores/widgets/WidgetMessagingStore";
7979
import { ElementWidgetActions } from "./stores/widgets/ElementWidgetActions";
8080
import { MatrixCall, CallErrorCode, CallState, CallEvent, CallParty } from "matrix-js-sdk/lib/webrtc/call";
81+
import Analytics from './Analytics';
8182

8283
enum AudioID {
8384
Ring = 'ringAudio',
@@ -191,6 +192,7 @@ export default class CallHandler {
191192
call.on(CallEvent.Error, (err) => {
192193
if (!this.matchesCallForThisRoom(call)) return;
193194

195+
Analytics.trackEvent('voip', 'callError', 'error', err);
194196
console.error("Call error:", err);
195197
if (
196198
MatrixClientPeg.get().getTurnServers().length === 0 &&
@@ -208,6 +210,8 @@ export default class CallHandler {
208210
call.on(CallEvent.Hangup, () => {
209211
if (!this.matchesCallForThisRoom(call)) return;
210212

213+
Analytics.trackEvent('voip', 'callHangup');
214+
211215
this.removeCallForRoom(call.roomId);
212216
});
213217
call.on(CallEvent.State, (newState: CallState, oldState: CallState) => {
@@ -232,6 +236,7 @@ export default class CallHandler {
232236
this.play(AudioID.Ringback);
233237
break;
234238
case CallState.Ended:
239+
Analytics.trackEvent('voip', 'callEnded', 'hangupReason', call.hangupReason);
235240
this.removeCallForRoom(call.roomId);
236241
if (oldState === CallState.InviteSent && (
237242
call.hangupParty === CallParty.Remote ||
@@ -329,6 +334,7 @@ export default class CallHandler {
329334
roomId: string, type: PlaceCallType,
330335
localElement: HTMLVideoElement, remoteElement: HTMLVideoElement,
331336
) {
337+
Analytics.trackEvent('voip', 'placeCall', 'type', type);
332338
const call = Matrix.createNewMatrixCall(MatrixClientPeg.get(), roomId);
333339
this.calls.set(roomId, call);
334340
this.setCallListeners(call);
@@ -406,6 +412,7 @@ export default class CallHandler {
406412
break;
407413
case 'place_conference_call':
408414
console.info("Place conference call in %s", payload.room_id);
415+
Analytics.trackEvent('voip', 'placeConferenceCall');
409416
this.startCallApp(payload.room_id, payload.type);
410417
break;
411418
case 'end_conference':
@@ -432,6 +439,7 @@ export default class CallHandler {
432439
}
433440

434441
const call = payload.call as MatrixCall;
442+
Analytics.trackEvent('voip', 'receiveCall', 'type', call.type);
435443
this.calls.set(call.roomId, call)
436444
this.setCallListeners(call);
437445
}

0 commit comments

Comments
 (0)