Skip to content

Commit 9eae9ca

Browse files
authored
Merge pull request #64 from GuiLeme/feat-implement-time-window
feat: Implement time window look back
2 parents f2ab0e3 + c597639 commit 9eae9ca

File tree

2 files changed

+45
-7
lines changed

2 files changed

+45
-7
lines changed

README.md

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,36 @@ For more information about the plugin API features, see the documentation (`read
1919

2020
If you have any suggestions, requirements, or questions, don’t hesitate to contact us.
2121

22-
## Necessary configurations
22+
## Configurations
2323

24-
By default, no ping is sounded for the randomly picked user. To activate this feature, one must add the following configurations in their `/etc/bigbluebutton/bbb-html5.yml` file.
24+
Down below, we list all the possible configurations this plugin supports, and then a brief explanation:
25+
26+
```yaml
27+
- name: PickRandomUserPlugin
28+
settings:
29+
pingSoundEnabled: false
30+
pingSoundUrl: resources/sounds/doorbell.mp3
31+
pickedUserTimeWindow: 30 seconds
32+
```
33+
34+
| Name | Description | Default |
35+
|------------------------|--------------------------------------|-----------------------------|
36+
| `pingSoundEnabled` | Whether the ping sound is enabled | `false` |
37+
| `pingSoundUrl` | URL of the ping sound file | `resources/sounds/doorbell.mp3` |
38+
| `pickedUserTimeWindow` | Time window to consider a user as recently picked (users that join after that time will not see the last modal) | `30` |
39+
40+
41+
### Notification/Ping sound
42+
43+
By default, no ping sound is played for the randomly picked user. To activate this feature, one must add the following configurations in their `/etc/bigbluebutton/bbb-html5.yml` file.
2544

2645
So within that file and in `public.plugins` add the following configurations:
2746

2847
```yaml
2948
- name: PickRandomUserPlugin
30-
settings:
31-
pingSoundEnabled: true
32-
pingSoundUrl: resources/sounds/doorbell.mp3
49+
settings:
50+
pingSoundEnabled: true
51+
pingSoundUrl: resources/sounds/doorbell.mp3
3352
```
3453

3554
The result yaml will look like:

src/components/pick-random-user/component.tsx

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ const LOCALE_REQUEST_OBJECT = (!process.env.NODE_ENV || process.env.NODE_ENV ===
2424
},
2525
} : null;
2626

27+
const PICKED_USER_TIME_WINDOW = 30; // seconds
28+
2729
function PickRandomUserPlugin({ pluginUuid: uuid }: PickRandomUserPluginProps) {
2830
BbbPluginSdk.initialize(uuid);
2931
const pluginApi: PluginApi = BbbPluginSdk.getPluginApi(uuid);
@@ -35,6 +37,7 @@ function PickRandomUserPlugin({ pluginUuid: uuid }: PickRandomUserPluginProps) {
3537
const [userFilterViewer, setUserFilterViewer] = useState<boolean>(true);
3638
const [filterOutPresenter, setFilterOutPresenter] = useState<boolean>(true);
3739
const [filterOutPickedUsers, setFilterOutPickedUsers] = useState<boolean>(true);
40+
const [pickedUserTimeWindow, setPickedUserTimeWindow] = useState<number>(PICKED_USER_TIME_WINDOW);
3841

3942
const { data: pluginSettings, loading: isPluginSettingsLoading } = pluginApi.usePluginSettings();
4043

@@ -44,6 +47,14 @@ function PickRandomUserPlugin({ pluginUuid: uuid }: PickRandomUserPluginProps) {
4447
&& pluginSettings.pingSoundEnabled) {
4548
Notification.requestPermission();
4649
}
50+
if (!isPluginSettingsLoading
51+
&& pluginSettings
52+
&& pluginSettings.pickedUserTimeWindow
53+
&& typeof pluginSettings.pickedUserTimeWindow === 'number'
54+
&& !Number.isNaN(pluginSettings.pickedUserTimeWindow)
55+
) {
56+
setPickedUserTimeWindow(pluginSettings.pickedUserTimeWindow);
57+
}
4758
}, [isPluginSettingsLoading, pluginSettings]);
4859

4960
const currentUserInfo = pluginApi.useCurrentUser();
@@ -154,15 +165,23 @@ function PickRandomUserPlugin({ pluginUuid: uuid }: PickRandomUserPluginProps) {
154165
currentUser?.userId,
155166
pickedUserToUpdate?.payloadJson.userId,
156167
);
157-
if (!hasCurrentUserSeen && !pickedUserSeenEntries?.loading) {
168+
const isPreviousPickInTimeWindow = (
169+
(new Date().getTime() - new Date(pickedUserToUpdate.createdAt).getTime()) / 1000
170+
<= pickedUserTimeWindow
171+
);
172+
if (
173+
!hasCurrentUserSeen
174+
&& !pickedUserSeenEntries?.loading
175+
&& isPreviousPickInTimeWindow
176+
) {
158177
setShowModal(true);
159178
}
160179
} else if (pickedUserFromDataChannel.data
161180
&& pickedUserFromDataChannel.data?.length === 0) {
162181
setPickedUserWithEntryId(null);
163182
if (currentUser && !currentUser.presenter) setShowModal(false);
164183
}
165-
}, [pickedUserFromDataChannelResponse, pickedUserSeenEntries]);
184+
}, [pickedUserFromDataChannelResponse, pickedUserSeenEntries, pickedUserTimeWindow]);
166185

167186
useEffect(() => {
168187
if (!pickedUserWithEntryId && !currentUser?.presenter) setShowModal(false);

0 commit comments

Comments
 (0)