@tellescope/video-chat 1.3.27 → 1.3.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tellescope/video-chat",
3
- "version": "1.3.27",
3
+ "version": "1.3.29",
4
4
  "description": "",
5
5
  "main": "./lib/cjs/index.js",
6
6
  "module": "./lib/esm/index.js",
@@ -55,7 +55,7 @@
55
55
  "react": "^16.8.0 || ^17.0.0 || ^18.0.0",
56
56
  "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0"
57
57
  },
58
- "gitHead": "84949695c66af0d03234a569d5cfc900515c7a7b",
58
+ "gitHead": "72917f76ec3d8ac91de746464a44cdfd896e44b0",
59
59
  "publishConfig": {
60
60
  "access": "public"
61
61
  }
@@ -7,7 +7,7 @@
7
7
  */
8
8
 
9
9
  import React, { useCallback, useContext, useEffect, useState } from "react"
10
- import { View, StyleSheet } from "react-native"
10
+ import { StyleSheet } from "react-native"
11
11
  import {
12
12
  AttendeeInfo,
13
13
  MeetingInfo,
@@ -20,10 +20,9 @@ import {
20
20
  useSession,
21
21
  Flex,
22
22
  useCalendarEvents,
23
+ useMeetings,
23
24
  } from "@tellescope/react-components"
24
25
  import {
25
- Button,
26
- Typography,
27
26
  convert_CSS_to_RNStyles, // requires mui.native
28
27
  } from "@tellescope/react-components/lib/esm/mui.native"
29
28
 
@@ -43,7 +42,6 @@ import {
43
42
  NativeFunction,
44
43
  ControlBar,
45
44
  } from "./index.native"
46
- import { borderColor, borderRadius } from "@mui/system"
47
45
  // import RNSwitchAudioOutput from 'react-native-switch-audio-output';
48
46
 
49
47
  interface TileState {
@@ -65,6 +63,17 @@ export const WithVideo = ({ children } : VideoProps) => {
65
63
  const [screenShareTile, setScreenShareTile] = useState(null as number | null)
66
64
  const [attendees, setAttendees] = useState ([] as AttendeeDisplayInfo[])
67
65
 
66
+ const resetState = () => {
67
+ setMeeting(undefined)
68
+ setIsHost(false)
69
+ setMuted(false)
70
+ setVideoIsEnabled(false)
71
+ setVideoTiles([])
72
+ setLocalTileId(null)
73
+ setScreenShareTile(null)
74
+ setAttendees([])
75
+ }
76
+
68
77
  const toggleVideo = async () => {
69
78
  NativeFunction.setCameraOn(!videoIsEnabled)
70
79
  if (videoIsEnabled) {
@@ -86,8 +95,7 @@ export const WithVideo = ({ children } : VideoProps) => {
86
95
 
87
96
  // called when user clicks Leave Meeting or meeting is ended by host
88
97
  const endSubscription = emitter.addListener(MobileSDKEvent.OnMeetingEnd, a => {
89
- setInMeeting(false)
90
- setIsLoading(false)
98
+ resetState()
91
99
  });
92
100
 
93
101
  const joinSubscription = emitter.addListener(MobileSDKEvent.OnAttendeesJoin, (added: { attendeeId: string, externalUserId: string }) => {
@@ -104,7 +112,7 @@ export const WithVideo = ({ children } : VideoProps) => {
104
112
  });
105
113
 
106
114
  const errorSubscription = emitter.addListener(MobileSDKEvent.OnError, (message) => {
107
- console.error("SDK Error", message);
115
+ console.error("SDK Error in errorSubscription", message);
108
116
  });
109
117
 
110
118
  const muteSubscription = emitter.addListener(MobileSDKEvent.OnAttendeesMute, attendeeId => {
@@ -136,6 +144,9 @@ export const WithVideo = ({ children } : VideoProps) => {
136
144
  setVideoIsEnabled(v => tileState.isLocal ? false : v)
137
145
  });
138
146
 
147
+ // clean up any old meetings when the context is loaded
148
+ NativeFunction.stopMeeting()
149
+
139
150
  return () => {
140
151
  startSubscription.remove();
141
152
  endSubscription.remove();
@@ -191,6 +202,8 @@ export const useStartVideoCall = (): StartVideoCallReturnType => {
191
202
  const session = useSession()
192
203
  const { meeting, setMeeting, setIsHost, videoIsEnabled, toggleVideo } = React.useContext(CurrentCallContext)
193
204
 
205
+ const [, { updateLocalElement: updateLocalMeeting }] = useMeetings({ dontFetch: true })
206
+
194
207
  const [starting, setStarting] = useState(false)
195
208
  const [ending, setEnding] = useState(false)
196
209
 
@@ -198,7 +211,7 @@ export const useStartVideoCall = (): StartVideoCallReturnType => {
198
211
  setStarting(true)
199
212
  try {
200
213
  const { id, meeting, host } = await session.api.meetings.start_meeting({ attendees: initialAttendees })
201
- NativeFunction.startMeeting(meeting.Meeting, host.info)
214
+ await NativeFunction.startMeeting(meeting.Meeting, host.info)
202
215
 
203
216
  setMeeting(meeting.Meeting)
204
217
  setIsHost(true)
@@ -223,10 +236,15 @@ export const useStartVideoCall = (): StartVideoCallReturnType => {
223
236
 
224
237
  try {
225
238
  await session.api.meetings.end_meeting({ id: meeting.ExternalMeetingId })
239
+
240
+ updateLocalMeeting(meeting.ExternalMeetingId, {
241
+ status: 'ended',
242
+ // @ts-ignore
243
+ endedAt: new Date().toString(),
244
+ })
226
245
  } catch(err) { console.error(err) }
227
246
 
228
- setEnding(false)
229
- setMeeting(undefined)
247
+ NativeFunction.stopMeeting()
230
248
  }
231
249
 
232
250
  return {
@@ -255,7 +273,7 @@ export const useStartAndJoinMeetingForCalendarEvent = (calendarEventId: string)
255
273
 
256
274
  updateLocalEvent(calendarEventId, { meetingId: id } )
257
275
 
258
- NativeFunction.startMeeting(meeting.Meeting, host.info)
276
+ await NativeFunction.startMeeting(meeting.Meeting, host.info)
259
277
 
260
278
  setMeeting(meeting.Meeting)
261
279
  setIsHost(true)
@@ -271,6 +289,7 @@ export const useJoinVideoCall = (): JoinVideoCallReturnType => {
271
289
  const { meeting, setIsHost, setMeeting, videoIsEnabled, toggleVideo } = React.useContext(CurrentCallContext)
272
290
 
273
291
  const joinMeeting = async (meetingInfo: string | { Meeting: MeetingInfo }, attendeeInfo?: { Attendee: AttendeeInfo }) => {
292
+ let isHost = false
274
293
  if (typeof meetingInfo == 'string') {
275
294
  const meetings = await session.api.meetings.my_meetings()
276
295
  const meeting = meetings.find(m => m.id === meetingInfo)
@@ -278,70 +297,29 @@ export const useJoinVideoCall = (): JoinVideoCallReturnType => {
278
297
  attendeeInfo = { Attendee: meeting?.attendees.find?.(a => a.id === session.userInfo.id)?.info as AttendeeInfo}
279
298
 
280
299
  if (attendeeInfo.Attendee.ExternalUserId === meeting?.creator) {
281
- setIsHost(true)
300
+ isHost = true
282
301
  }
283
302
  }
284
303
 
285
304
  if (!meetingInfo || typeof meetingInfo === 'string' || !attendeeInfo) return
286
305
 
287
- NativeFunction.startMeeting(meetingInfo.Meeting ?? meetingInfo, attendeeInfo.Attendee ?? attendeeInfo)
306
+ try {
307
+ await NativeFunction.startMeeting(meetingInfo.Meeting ?? meetingInfo, attendeeInfo.Attendee ?? attendeeInfo)
308
+ } catch(err) {
309
+ await NativeFunction.startMeeting(meetingInfo.Meeting ?? meetingInfo, attendeeInfo.Attendee ?? attendeeInfo)
310
+ }
288
311
 
289
- setMeeting(meetingInfo.Meeting)
312
+ setMeeting(meetingInfo.Meeting ?? meetingInfo)
313
+ setIsHost(isHost)
290
314
  }
291
315
 
292
- const leaveMeeting = () => setMeeting(undefined)
316
+ const leaveMeeting = () => {
317
+ NativeFunction.stopMeeting()
318
+ // setMeeting(undefined)
319
+ }
293
320
 
294
321
  return { meeting, videoIsEnabled, toggleVideo, joinMeeting, leaveMeeting }
295
322
  }
296
- export const VideoTileGrid = () => {
297
- const {
298
- // attendees,
299
- videoTiles,
300
- toggleVideo,
301
- } = useContext(CurrentCallContext)
302
-
303
- return (
304
- <Flex column justifyContent="space-between" alignItems="center">
305
- <Flex style={styles.videoContainer}>
306
- {
307
- videoTiles.length > 0 ? videoTiles.map(tileId =>
308
- <RNVideoRenderView style={styles.video} key={tileId} tileId={tileId} />
309
- ) : <Typography style={styles.subtitle}>No one is sharing video at this moment</Typography>
310
- }
311
- </Flex>
312
-
313
- {/*
314
- {
315
- !!shareScreenId &&
316
- <React.Fragment>
317
- <Typography style={styles.title}>Screen Share</Typography>
318
- <View style={styles.videoContainer}>
319
- <RNVideoRenderView style={styles.screenShare} key={shareScreenId} tileId={shareScreenId} />
320
- </View>
321
- </React.Fragment>
322
- }
323
- */}
324
-
325
- <Flex justifyContent="space-between" style={{ height: '5%' }}>
326
- {/* <MuteButton muted={currentMuted} onPress={() => NativeFunction.setMute(!currentMuted) }/> */}
327
- {/* <CameraButton disabled={selfVideoEnabled} onPress={() => NativeFunction.setCameraOn(!videoIsEnabled)}/> */}
328
- <Button onPress={toggleVideo}>
329
- Toggle Video
330
- </Button>
331
- {/* <HangOffButton onPress={() => NativeFunction.stopMeeting()} /> */}
332
- <Button onPress={() => NativeFunction.stopMeeting()}> Leave Meeting </Button>
333
- </Flex>
334
-
335
- {/* <FlatList
336
- style={styles.attendeeList}
337
- data={attendees}
338
- renderItem={({ item }) => <AttendeeItem attendeeName={attendeeNameMap[item] ? attendeeNameMap[item] : item} muted={this.state.mutedAttendee.includes(item)}/>}
339
- keyExtractor={(item) => item}
340
- /> */}
341
-
342
- </Flex>
343
- );
344
- }
345
323
 
346
324
  const styles = StyleSheet.create({
347
325
  title: {
@@ -466,9 +444,7 @@ export const VideoCallNative: React.JSXElementConstructor<VideoCallNativeProps>
466
444
 
467
445
  </Flex>
468
446
 
469
- <ControlBar {...props}
470
- style={{ position: 'absolute', bottom: 20, width: '100%' }}
471
- />
447
+ <ControlBar {...props} style={{ position: 'absolute', bottom: 20, width: '100%' }} />
472
448
  </Flex>
473
449
  )
474
450
  }