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

Commit

Permalink
Merge pull request #5340 from matrix-org/dbkr/voip_analytics
Browse files Browse the repository at this point in the history
Add analytics to VoIP
  • Loading branch information
dbkr authored Oct 19, 2020
2 parents 92f89b8 + 88b7210 commit ce47856
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/CallHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ import WidgetStore from "./stores/WidgetStore";
import { WidgetMessagingStore } from "./stores/widgets/WidgetMessagingStore";
import { ElementWidgetActions } from "./stores/widgets/ElementWidgetActions";
import { MatrixCall, CallErrorCode, CallState, CallEvent, CallParty } from "matrix-js-sdk/lib/webrtc/call";
import Analytics from './Analytics';

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

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

Analytics.trackEvent('voip', 'callHangup');

this.removeCallForRoom(call.roomId);
});
call.on(CallEvent.State, (newState: CallState, oldState: CallState) => {
Expand All @@ -232,6 +236,7 @@ export default class CallHandler {
this.play(AudioID.Ringback);
break;
case CallState.Ended:
Analytics.trackEvent('voip', 'callEnded', 'hangupReason', call.hangupReason);
this.removeCallForRoom(call.roomId);
if (oldState === CallState.InviteSent && (
call.hangupParty === CallParty.Remote ||
Expand Down Expand Up @@ -329,6 +334,7 @@ export default class CallHandler {
roomId: string, type: PlaceCallType,
localElement: HTMLVideoElement, remoteElement: HTMLVideoElement,
) {
Analytics.trackEvent('voip', 'placeCall', 'type', type);
const call = Matrix.createNewMatrixCall(MatrixClientPeg.get(), roomId);
this.calls.set(roomId, call);
this.setCallListeners(call);
Expand Down Expand Up @@ -406,6 +412,7 @@ export default class CallHandler {
break;
case 'place_conference_call':
console.info("Place conference call in %s", payload.room_id);
Analytics.trackEvent('voip', 'placeConferenceCall');
this.startCallApp(payload.room_id, payload.type);
break;
case 'end_conference':
Expand All @@ -432,6 +439,7 @@ export default class CallHandler {
}

const call = payload.call as MatrixCall;
Analytics.trackEvent('voip', 'receiveCall', 'type', call.type);
this.calls.set(call.roomId, call)
this.setCallListeners(call);
}
Expand Down

0 comments on commit ce47856

Please sign in to comment.