投票
更新时间 2025/02/05 08:08:31
通过插件的形式来添加更多的功能,投票 是官方提供的用于对多个元素组成的组进行投票的插件。
使用
初始化获取英飞 Web SDK 实例的时候,在 config 参数的 plugins 字段中配置投票插件即可:
import InfiWebSdk, { VotingPlugin } from '@plaso-infi/whiteboard-sdk';
const initRes = await InfiWebSdk.getSdkInstance({
containerDom: container,
plugins: [
// 投票插件
{
pluginConstructor: VotingPlugin,
config: {
votingId: getVoteId(),
canCreate: true,
canEnd: true,
canShare: true,
getInviteUrl: getInviteVotingUrl,
showQrCode: showVotingQrCode,
onJoin: onJoinVoting,
onLeave: didLeaveVoting,
onEnded: handleVotingEnded,
},
},
// other plugins
...
],
// other configs
...
});
配置
属性名称
类型
是否必须
默认值
说明
votingId
string
否
-
投票的 id,传入后自动加入这个投票
canCreate
boolean
否
false
是否能创建投票
canEnd
boolean
否
false
是否能结束投票
canShare
boolean
否
true
是否能分享投票
getInviteUrl
GetInviteUrlT
否
-
提供邀请链接的函数
showQrCode
VotingIdT
否
-
提供展示邀请二维码逻辑
onJoin
OnJoinT
否
-
传入votingId后,自动加入投票后的回调
onLeave
VotingIdT
否
-
离开投票后的回调
onEnded
VotingIdT
否
-
投票结束后的回调
属性类型定义
type GetInviteUrlT = (params: {
voteId: string;
creator: string;
voteName: string;
endTime?: number;
}) => Promise<string>;
type OnJoinT = (params: { voteId: string; success: boolean }) => void;
type VotingIdT = (params: { voteId: string }) => void;