|
1 |
| -import { registerPlugin, type RPCCallPayload } from '@pexip/plugin-api' |
| 1 | +import { |
| 2 | + Button, |
| 3 | + InfinityParticipant, |
| 4 | + registerPlugin, |
| 5 | + type RPCCallPayload, |
| 6 | +} from "@pexip/plugin-api"; |
2 | 7 |
|
3 | 8 | const plugin = await registerPlugin({
|
4 |
| - id: 'rx-presentation', |
5 |
| - version: 0 |
6 |
| -}) |
| 9 | + id: "rx-presentation", |
| 10 | + version: 0, |
| 11 | +}); |
7 | 12 |
|
8 |
| -const denyRxButtonPayload: RPCCallPayload<'ui:button:add'> = { |
9 |
| - position: 'participantActions', |
10 |
| - label: 'Deny receive presentation' |
11 |
| -} |
| 13 | +const denyRxButtonPayload: RPCCallPayload<"ui:button:add"> = { |
| 14 | + position: "participantActions", |
| 15 | + label: "Deny receive presentation", |
| 16 | +}; |
12 | 17 |
|
13 |
| -const allowRxButtonPayload: RPCCallPayload<'ui:button:add'> = { |
14 |
| - position: 'participantActions', |
15 |
| - label: 'Allow receive presentation' |
16 |
| -} |
| 18 | +const allowRxButtonPayload: RPCCallPayload<"ui:button:add"> = { |
| 19 | + position: "participantActions", |
| 20 | + label: "Allow receive presentation", |
| 21 | +}; |
17 | 22 |
|
18 |
| -const denyRxButton = await plugin.ui.addButton(denyRxButtonPayload) |
19 |
| -const allowRxButton = await plugin.ui.addButton(allowRxButtonPayload) |
| 23 | +let isDirectMedia: boolean | undefined = undefined; |
| 24 | + |
| 25 | +let participantList: Map<string, InfinityParticipant> = new Map(); |
| 26 | + |
| 27 | +const denyRxButton = await plugin.ui.addButton(denyRxButtonPayload); |
| 28 | +const allowRxButton = await plugin.ui.addButton(allowRxButtonPayload); |
20 | 29 |
|
21 | 30 | denyRxButton.onClick.add(async ({ participantUuid }) => {
|
22 | 31 | const payload = {
|
23 | 32 | path: "participants/" + participantUuid + "/denyrxpresentation",
|
24 | 33 | method: "POST",
|
25 |
| - payload: {} |
| 34 | + payload: {}, |
26 | 35 | };
|
27 | 36 | await plugin.conference.sendRequest(payload);
|
28 |
| -}) |
| 37 | + plugin.ui.showToast({ |
| 38 | + message: |
| 39 | + "Denying receive presentation for " + |
| 40 | + participantList.get(participantUuid)?.displayName, |
| 41 | + }); |
| 42 | +}); |
29 | 43 |
|
30 | 44 | allowRxButton.onClick.add(async ({ participantUuid }) => {
|
31 | 45 | const payload = {
|
32 | 46 | path: "participants/" + participantUuid + "/allowrxpresentation",
|
33 | 47 | method: "POST",
|
34 |
| - payload: {} |
| 48 | + payload: {}, |
35 | 49 | };
|
36 | 50 | await plugin.conference.sendRequest(payload);
|
37 |
| -}) |
| 51 | + plugin.ui.showToast({ |
| 52 | + message: |
| 53 | + "Allowing receive presentation for " + |
| 54 | + participantList.get(participantUuid)?.displayName, |
| 55 | + }); |
| 56 | +}); |
38 | 57 |
|
39 |
| -plugin.events.participants.add(({ participants }) => { |
| 58 | +plugin.events.conferenceStatus.add(async ({ status }) => { |
| 59 | + isDirectMedia = status.directMedia; |
| 60 | +}); |
| 61 | + |
| 62 | +const updateParticipantButtons = (participants: InfinityParticipant[]) => { |
40 | 63 | const allowedRxParticipants = participants
|
41 |
| - .filter((participant) => participant.rxPresentation) |
42 |
| - .map((participant) => participant.uuid) |
| 64 | + .filter((participant) => participant.rxPresentation && !isDirectMedia) |
| 65 | + .map((participant) => participant.uuid); |
43 | 66 |
|
44 | 67 | const deniedRxParticipants = participants
|
45 |
| - .filter((participant) => !participant.rxPresentation) |
46 |
| - .map((participant) => participant.uuid) |
| 68 | + .filter((participant) => !participant.rxPresentation && !isDirectMedia) |
| 69 | + .map((participant) => participant.uuid); |
47 | 70 |
|
48 | 71 | denyRxButton
|
49 | 72 | .update({
|
50 | 73 | ...denyRxButtonPayload,
|
51 |
| - participantIDs: allowedRxParticipants |
| 74 | + participantIDs: allowedRxParticipants, |
52 | 75 | })
|
53 |
| - .catch(console.error) |
| 76 | + .catch(console.error); |
54 | 77 |
|
55 | 78 | allowRxButton
|
56 | 79 | .update({
|
57 | 80 | ...allowRxButtonPayload,
|
58 |
| - participantIDs: deniedRxParticipants |
| 81 | + participantIDs: deniedRxParticipants, |
59 | 82 | })
|
60 |
| - .catch(console.error) |
61 |
| -}) |
| 83 | + .catch(console.error); |
| 84 | +}; |
| 85 | + |
| 86 | +plugin.events.participants.add(({ participants }) => { |
| 87 | + participantList = new Map(); |
| 88 | + participants.forEach((participant) => |
| 89 | + participantList.set(participant.uuid, participant) |
| 90 | + ); |
| 91 | + updateParticipantButtons(participants); |
| 92 | +}); |
0 commit comments