@@ -12,18 +12,20 @@ import {
12
12
VideoSourceType ,
13
13
createAgoraRtcEngine ,
14
14
} from 'agora-electron-sdk' ;
15
- import { ReactElement } from 'react' ;
15
+ import React , { ReactElement } from 'react' ;
16
16
17
17
import {
18
18
BaseComponent ,
19
19
BaseVideoComponentState ,
20
20
} from '../../../components/BaseComponent' ;
21
- import { AgoraDropdown } from '../../../components/ui' ;
21
+ import { AgoraButton , AgoraDropdown , AgoraView } from '../../../components/ui' ;
22
22
import Config from '../../../config/agora.config' ;
23
23
import { arrayToItems } from '../../../utils' ;
24
24
import { askMediaAccess } from '../../../utils/permissions' ;
25
25
26
- interface State extends BaseVideoComponentState { }
26
+ interface State extends BaseVideoComponentState {
27
+ selectedUser ?: number ;
28
+ }
27
29
28
30
export default class JoinChannelVideo
29
31
extends BaseComponent < { } , State >
@@ -178,21 +180,53 @@ export default class JoinChannelVideo
178
180
}
179
181
180
182
protected renderConfiguration ( ) : ReactElement | undefined {
181
- const { joinChannelSuccess, remoteUsers } = this . state ;
183
+ const { joinChannelSuccess, remoteUsers, selectedUser } = this . state ;
182
184
return (
183
185
< >
184
186
{ joinChannelSuccess ? (
185
- < AgoraDropdown
186
- title = { 'Append renderer to remote users' }
187
- items = { arrayToItems ( remoteUsers ) }
188
- onValueChange = { ( value ) => {
189
- this . setState ( ( prev ) => {
190
- return {
191
- remoteUsers : [ ...prev . remoteUsers , value ] ,
192
- } ;
193
- } ) ;
194
- } }
195
- />
187
+ < >
188
+ < AgoraDropdown
189
+ title = { 'Append renderer to remote users' }
190
+ items = { arrayToItems ( Array . from ( new Set ( remoteUsers ) ) ) }
191
+ value = { selectedUser }
192
+ onValueChange = { ( value ) => {
193
+ this . setState ( { selectedUser : value } ) ;
194
+ } }
195
+ />
196
+ < AgoraView >
197
+ < AgoraButton
198
+ title = "Add"
199
+ onPress = { ( ) => {
200
+ if ( selectedUser !== undefined ) {
201
+ this . setState ( ( prev ) => {
202
+ return {
203
+ remoteUsers : [ ...prev . remoteUsers , selectedUser ] ,
204
+ } ;
205
+ } ) ;
206
+ }
207
+ } }
208
+ />
209
+ < AgoraButton
210
+ title = "Remove"
211
+ onPress = { ( ) => {
212
+ if ( selectedUser !== undefined ) {
213
+ this . setState ( ( prev ) => {
214
+ const predicate = ( it : number ) => it === selectedUser ;
215
+ const firstIndex = prev . remoteUsers . findIndex ( predicate ) ;
216
+ const lastIndex =
217
+ prev . remoteUsers . findLastIndex ( predicate ) ;
218
+ if ( firstIndex !== lastIndex ) {
219
+ prev . remoteUsers . splice ( lastIndex , 1 ) ;
220
+ }
221
+ return {
222
+ remoteUsers : prev . remoteUsers ,
223
+ } ;
224
+ } ) ;
225
+ }
226
+ } }
227
+ />
228
+ </ AgoraView >
229
+ </ >
196
230
) : undefined }
197
231
</ >
198
232
) ;
0 commit comments