-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
84 lines (71 loc) · 2.34 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import { DyteUIBuilder, UIConfig } from "@dytesdk/ui-kit";
import { Meeting } from "@dytesdk/ui-kit/dist/types/types/dyte-client";
import CustomMenuItem, { MenuState } from "./CustomMenuItem";
interface ParticipantMenuItemArgs {
label: string;
icon?: string;
styles?: string;
onClick: (participantId: string) => void;
onStateChange: (participantId: string, callback: (state: MenuState) => void) => void;
}
/**
* A class that represents a custom menu item in the participant menu.
* @class ParticipantMenuItem
* @example
* ```typescript
* const participantMenuItem = new ParticipantMenuItem({
* label: "My Custom Menu Item",
* icon: "<svg> </svg>",
* styles: ".customClass { color: red; }",
* onClick: () => {
* console.log('Clicked on custom menu item');
* }
* });
*
* const config = registerAddons([participantMenuItem], meeting);
* ```
*/
export default class ParticipantMenuItem {
meeting?: Meeting;
onClick: (participantId: string) => void;
label: string;
icon?: string;
styles?: string;
onStateChange: (participantId: string, callback: (state: MenuState) => void) => void;
constructor(args: ParticipantMenuItemArgs) {
this.label = args.label;
this.icon = args.icon;
this.styles = args.styles;
this.onClick = args.onClick;
this.onStateChange = args.onStateChange;
}
async unregister() {
return;
}
register(config: UIConfig, meeting: Meeting, getBuilder: (c: UIConfig) => DyteUIBuilder) {
if (!customElements.get("dyte-custom-menu-item")) {
customElements.define(
"dyte-custom-menu-item",
CustomMenuItem
);
}
this.meeting = meeting;
if (!config.root["dyte-participant"]) {
config.root["dyte-participant"] = {};
}
// Add buttons with config
const builder = getBuilder(config);
const dyteParticipant = builder.find(`dyte-participant`);
dyteParticipant.add("dyte-custom-menu-item", {
label: this.label,
icon: this.icon,
styles: this.styles,
// @ts-ignore
onStateChange: this.onStateChange,
// @ts-ignore
onClick: this.onClick
});
// Return the updated config
return builder.build();
}
}