Skip to content

Commit

Permalink
Introduce gql user_voice_activity_stream (#20557)
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavotrott committed Jun 20, 2024
1 parent ac07c46 commit 3402edc
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,19 +119,6 @@ object UserVoiceDAO {
}
}

def delete(meetingId: String, userId: String) = {
DatabaseConnection.db.run(
TableQuery[UserDbTableDef]
.filter(_.meetingId === meetingId)
.filter(_.userId === userId)
.map(u => (u.loggedOut))
.update((true))
).onComplete {
case Success(rowsAffected) => DatabaseConnection.logger.debug(s"$rowsAffected row(s) updated loggedOut=true on user table!")
case Failure(e) => DatabaseConnection.logger.error(s"Error updating loggedOut=true user: $e")
}
}

def deleteUserVoice(meetingId: String,userId: String) = {
//Meteor sets this props instead of removing
// muted: false
Expand All @@ -145,7 +132,7 @@ object UserVoiceDAO {
.filter(_.meetingId === meetingId)
.filter(_.userId === userId)
.map(u => (u.muted, u.talking, u.listenOnly, u.joined, u.spoke, u.startTime, u.endTime))
.update((false, false, false, false, false, None, None))
.update((true, false, false, false, false, None, None))
).onComplete {
case Success(rowsAffected) => DatabaseConnection.logger.debug(s"Voice of user ${userId} deleted (joined=false)")
case Failure(e) => DatabaseConnection.logger.error(s"Error deleting voice user: $e")
Expand Down
41 changes: 41 additions & 0 deletions bbb-graphql-server/bbb_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,7 @@ CREATE TABLE "user_voice" (
"voiceConfCallState" varchar(30),
"endTime" bigint,
"startTime" bigint,
"voiceActivityAt" timestamp with time zone,
CONSTRAINT "user_voice_pkey" PRIMARY KEY ("meetingId","userId"),
FOREIGN KEY ("meetingId", "userId") REFERENCES "user"("meetingId","userId") ON DELETE CASCADE
);
Expand All @@ -614,6 +615,7 @@ GENERATED ALWAYS AS (to_timestamp("endTime"::double precision / 1000)) STORED;

CREATE INDEX "idx_user_voice_userId_talking" ON "user_voice"("meetingId", "userId","talking");
CREATE INDEX "idx_user_voice_userId_hideTalkingIndicatorAt" ON "user_voice"("meetingId", "userId","hideTalkingIndicatorAt");
CREATE INDEX "idx_user_voice_userId_voiceActivityAt" ON "user_voice"("meetingId", "voiceActivityAt") WHERE "voiceActivityAt" is not null;

CREATE OR REPLACE VIEW "v_user_voice" AS
SELECT
Expand All @@ -634,6 +636,45 @@ LEFT JOIN "user_voice" user_talking ON (
)
WHERE "user_voice"."joined" is true;

--Populate voiceActivityAt to provide users that are active in audio via stream subscription using the view v_user_voice_activity
CREATE OR REPLACE FUNCTION "update_user_voice_voiceActivityAt_trigger_func"() RETURNS TRIGGER AS $$
BEGIN
NEW."voiceActivityAt" := CASE WHEN
NEW."muted" IS false
or (OLD."muted" IS false and NEW."muted" is true)
or NEW."talking" is true
or (OLD."talking" IS true and NEW."talking" is false)
or (NEW."startTime" != OLD."startTime")
or (NEW."endTime" != OLD."endTime")
THEN current_timestamp
ELSE OLD."voiceActivityAt"
END;
RETURN NEW;
END;
$$ LANGUAGE plpgsql;

CREATE TRIGGER "update_user_voice_voiceActivityAt_trigger" BEFORE INSERT OR UPDATE ON "user_voice" FOR EACH ROW
EXECUTE FUNCTION "update_user_voice_voiceActivityAt_trigger_func"();

CREATE OR REPLACE VIEW "v_user_voice_activity" AS
select
"user_voice"."meetingId",
"user_voice"."userId",
"user_voice"."muted",
"user_voice"."talking",
"user_voice"."startTime",
"user_voice"."endTime",
"user_voice"."voiceActivityAt"
FROM "user_voice"
WHERE "voiceActivityAt" is not null
AND --filter recent activities to avoid receiving all history every time it starts the streming
("voiceActivityAt" > current_timestamp - '10 seconds'::interval
OR "user_voice"."muted" is false
OR "user_voice"."talking" is true
)
;

----


---TEMPORARY MINIMONGO ADAPTER START
Expand Down
15 changes: 8 additions & 7 deletions bbb-graphql-server/metadata/actions.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -486,13 +486,6 @@ type Mutation {
): Boolean
}

type Mutation {
userSetSpeechOptions(
partialUtterances: Boolean!
minUtteranceLength: Float!
): Boolean
}

type Mutation {
userSetCaptionLocale(
locale: String!
Expand Down Expand Up @@ -565,6 +558,13 @@ type Mutation {
): Boolean
}

type Mutation {
userSetSpeechOptions(
partialUtterances: Boolean!
minUtteranceLength: Float!
): Boolean
}

type Mutation {
userThirdPartyInfoResquest(
externalUserId: String!
Expand Down Expand Up @@ -593,3 +593,4 @@ input GuestUserApprovalStatus {
guest: String!
status: String!
}

14 changes: 7 additions & 7 deletions bbb-graphql-server/metadata/actions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -439,12 +439,6 @@ actions:
handler: '{{HASURA_BBB_GRAPHQL_ACTIONS_ADAPTER_URL}}'
permissions:
- role: bbb_client
- name: userSetSpeechOptions
definition:
kind: synchronous
handler: '{{HASURA_BBB_GRAPHQL_ACTIONS_ADAPTER_URL}}'
permissions:
- role: bbb_client
- name: userSetConnectionAlive
definition:
kind: synchronous
Expand Down Expand Up @@ -505,6 +499,12 @@ actions:
handler: '{{HASURA_BBB_GRAPHQL_ACTIONS_ADAPTER_URL}}'
permissions:
- role: bbb_client
- name: userSetSpeechOptions
definition:
kind: synchronous
handler: '{{HASURA_BBB_GRAPHQL_ACTIONS_ADAPTER_URL}}'
permissions:
- role: bbb_client
- name: userThirdPartyInfoResquest
definition:
kind: synchronous
Expand All @@ -523,4 +523,4 @@ custom_types:
- name: BreakoutRoom
- name: GuestUserApprovalStatus
objects: []
scalars: []
scalars: []
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
table:
name: v_user_voice_activity
schema: public
select_permissions:
- role: bbb_client
permission:
columns:
- endTime
- muted
- startTime
- talking
- userId
- voiceActivityAt
filter:
voiceActivityAt:
_eq: X-Hasura-MeetingId
comment: ""
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,6 @@
- "!include public_v_user_typing_private.yaml"
- "!include public_v_user_typing_public.yaml"
- "!include public_v_user_voice.yaml"
- "!include public_v_user_voice_activity.yaml"
- "!include public_v_user_voice_mongodb_adapter.yaml"
- "!include public_v_user_welcomeMsgs.yaml"

0 comments on commit 3402edc

Please sign in to comment.