@stream-io/video-client 0.0.27 → 0.0.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.
Files changed (67) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/index.browser.es.js +2517 -1760
  3. package/dist/index.browser.es.js.map +1 -1
  4. package/dist/index.cjs.js +2537 -1758
  5. package/dist/index.cjs.js.map +1 -1
  6. package/dist/index.es.js +2517 -1760
  7. package/dist/index.es.js.map +1 -1
  8. package/dist/src/Call.d.ts +7 -8
  9. package/dist/src/StreamSfuClient.d.ts +23 -10
  10. package/dist/src/StreamVideoClient.d.ts +1 -4
  11. package/dist/src/client-details.d.ts +2 -1
  12. package/dist/src/coordinator/connection/types.d.ts +2 -2
  13. package/dist/src/coordinator/connection/utils.d.ts +1 -0
  14. package/dist/src/events/internal.d.ts +4 -0
  15. package/dist/src/gen/coordinator/index.d.ts +6 -0
  16. package/dist/src/gen/google/protobuf/struct.d.ts +8 -15
  17. package/dist/src/gen/google/protobuf/timestamp.d.ts +2 -9
  18. package/dist/src/gen/video/sfu/event/events.d.ts +121 -1
  19. package/dist/src/gen/video/sfu/models/models.d.ts +38 -1
  20. package/dist/src/gen/video/sfu/signal_rpc/signal.client.d.ts +3 -14
  21. package/dist/src/gen/video/sfu/signal_rpc/signal.d.ts +4 -12
  22. package/dist/src/logger.d.ts +4 -2
  23. package/dist/src/rtc/Dispatcher.d.ts +1 -2
  24. package/dist/src/rtc/{publisher.d.ts → Publisher.d.ts} +49 -15
  25. package/dist/src/rtc/Subscriber.d.ts +58 -0
  26. package/dist/src/rtc/__tests__/Subscriber.test.d.ts +1 -0
  27. package/dist/src/rtc/flows/join.d.ts +8 -1
  28. package/dist/src/rtc/index.d.ts +2 -2
  29. package/dist/src/rtc/signal.d.ts +1 -0
  30. package/dist/src/stats/state-store-stats-reporter.d.ts +3 -4
  31. package/dist/src/store/CallState.d.ts +10 -0
  32. package/package.json +3 -1
  33. package/src/Call.ts +218 -214
  34. package/src/StreamSfuClient.ts +48 -21
  35. package/src/StreamVideoClient.ts +7 -24
  36. package/src/client-details.ts +33 -1
  37. package/src/coordinator/connection/client.ts +6 -8
  38. package/src/coordinator/connection/types.ts +2 -3
  39. package/src/coordinator/connection/utils.ts +1 -0
  40. package/src/events/call.ts +0 -1
  41. package/src/events/callEventHandlers.ts +2 -0
  42. package/src/events/internal.ts +20 -0
  43. package/src/events/sessions.ts +0 -1
  44. package/src/gen/coordinator/index.ts +6 -0
  45. package/src/gen/google/protobuf/struct.ts +541 -333
  46. package/src/gen/google/protobuf/timestamp.ts +214 -148
  47. package/src/gen/video/sfu/event/events.ts +353 -3
  48. package/src/gen/video/sfu/models/models.ts +37 -0
  49. package/src/gen/video/sfu/signal_rpc/signal.client.ts +160 -94
  50. package/src/gen/video/sfu/signal_rpc/signal.ts +1214 -731
  51. package/src/logger.ts +43 -30
  52. package/src/rtc/Dispatcher.ts +5 -9
  53. package/src/rtc/{publisher.ts → Publisher.ts} +245 -111
  54. package/src/rtc/Subscriber.ts +304 -0
  55. package/src/rtc/__tests__/{publisher.test.ts → Publisher.test.ts} +77 -9
  56. package/src/rtc/__tests__/Subscriber.test.ts +121 -0
  57. package/src/rtc/__tests__/mocks/webrtc.mocks.ts +20 -0
  58. package/src/rtc/flows/join.ts +43 -2
  59. package/src/rtc/index.ts +2 -2
  60. package/src/rtc/signal.ts +6 -5
  61. package/src/rtc/videoLayers.ts +1 -4
  62. package/src/stats/state-store-stats-reporter.ts +3 -5
  63. package/src/store/CallState.ts +20 -0
  64. package/src/types.ts +0 -1
  65. package/dist/src/rtc/subscriber.d.ts +0 -9
  66. package/src/rtc/subscriber.ts +0 -107
  67. /package/dist/src/rtc/__tests__/{publisher.test.d.ts → Publisher.test.d.ts} +0 -0
@@ -25,10 +25,7 @@ export const findOptimalVideoLayers = (
25
25
  ) => {
26
26
  const optimalVideoLayers: OptimalVideoLayer[] = [];
27
27
  const settings = videoTrack.getSettings();
28
- const {
29
- width: w = targetResolution.width,
30
- height: h = targetResolution.height,
31
- } = settings;
28
+ const { width: w = 0, height: h = 0 } = settings;
32
29
 
33
30
  const maxBitrate = getComputedMaxBitrate(targetResolution, w, h);
34
31
  let downscaleFactor = 1;
@@ -5,15 +5,14 @@ import type {
5
5
  StatsReport,
6
6
  } from './types';
7
7
  import { CallState } from '../store';
8
- import { Publisher } from '../rtc';
8
+ import { Publisher, Subscriber } from '../rtc';
9
9
  import { getLogger } from '../logger';
10
10
 
11
11
  export type StatsReporterOpts = {
12
- subscriber: RTCPeerConnection;
12
+ subscriber: Subscriber;
13
13
  publisher: Publisher;
14
14
  state: CallState;
15
15
  pollingIntervalInMs?: number;
16
- edgeName?: string;
17
16
  };
18
17
 
19
18
  export type StatsReporter = {
@@ -67,7 +66,6 @@ export const createStatsReporter = ({
67
66
  subscriber,
68
67
  publisher,
69
68
  state,
70
- edgeName,
71
69
  pollingIntervalInMs = 2000,
72
70
  }: StatsReporterOpts): StatsReporter => {
73
71
  const logger = getLogger(['stats']);
@@ -176,7 +174,7 @@ export const createStatsReporter = ({
176
174
  ]);
177
175
 
178
176
  state.setCallStatsReport({
179
- datacenter: edgeName || 'N/A',
177
+ datacenter: publisher.sfuClient.edgeName,
180
178
  publisherStats,
181
179
  subscriberStats,
182
180
  subscriberRawStats,
@@ -62,6 +62,11 @@ export enum CallingState {
62
62
  */
63
63
  RECONNECTING = 'reconnecting',
64
64
 
65
+ /**
66
+ * The call is in the process of migrating from one node to another.
67
+ */
68
+ MIGRATING = 'migrating',
69
+
65
70
  /**
66
71
  * The call has failed to reconnect.
67
72
  */
@@ -603,6 +608,21 @@ export class CallState {
603
608
  return this.participants.find((p) => p.sessionId === sessionId);
604
609
  };
605
610
 
611
+ /**
612
+ * Returns a new lookup table of participants indexed by their session ID.
613
+ */
614
+ getParticipantLookupBySessionId = () => {
615
+ return this.participants.reduce<{
616
+ [sessionId: string]:
617
+ | StreamVideoParticipant
618
+ | StreamVideoLocalParticipant
619
+ | undefined;
620
+ }>((lookupTable, participant) => {
621
+ lookupTable[participant.sessionId] = participant;
622
+ return lookupTable;
623
+ }, {});
624
+ };
625
+
606
626
  /**
607
627
  * Updates a participant in the current call identified by the given `sessionId`.
608
628
  * If the participant can't be found, this operation is no-op.
package/src/types.ts CHANGED
@@ -13,7 +13,6 @@ import type { StreamClient } from './coordinator/connection/client';
13
13
  import type { Comparator } from './sorting';
14
14
  import type { StreamVideoWriteableStateStore } from './store';
15
15
  import { AxiosError } from 'axios';
16
- import { Logger } from './coordinator/connection/types';
17
16
 
18
17
  export type StreamReaction = Pick<
19
18
  ReactionResponse,
@@ -1,9 +0,0 @@
1
- import { StreamSfuClient } from '../StreamSfuClient';
2
- import { Dispatcher } from './Dispatcher';
3
- export type SubscriberOpts = {
4
- sfuClient: StreamSfuClient;
5
- dispatcher: Dispatcher;
6
- connectionConfig?: RTCConfiguration;
7
- onTrack?: (e: RTCTrackEvent) => void;
8
- };
9
- export declare const createSubscriber: ({ sfuClient, dispatcher, connectionConfig, onTrack, }: SubscriberOpts) => RTCPeerConnection;
@@ -1,107 +0,0 @@
1
- import { StreamSfuClient } from '../StreamSfuClient';
2
- import { getIceCandidate } from './helpers/iceCandidate';
3
- import { PeerType } from '../gen/video/sfu/models/models';
4
- import { Dispatcher } from './Dispatcher';
5
- import { getLogger } from '../logger';
6
-
7
- export type SubscriberOpts = {
8
- sfuClient: StreamSfuClient;
9
- dispatcher: Dispatcher;
10
- connectionConfig?: RTCConfiguration;
11
- onTrack?: (e: RTCTrackEvent) => void;
12
- };
13
-
14
- export const createSubscriber = ({
15
- sfuClient,
16
- dispatcher,
17
- connectionConfig,
18
- onTrack,
19
- }: SubscriberOpts) => {
20
- const logger = getLogger(['sfu-client']);
21
- const subscriber = new RTCPeerConnection(connectionConfig);
22
- attachDebugEventListeners(subscriber);
23
-
24
- subscriber.addEventListener('icecandidate', async (e) => {
25
- const { candidate } = e;
26
- if (!candidate) {
27
- logger?.('warn', 'null ice candidate');
28
- return;
29
- }
30
-
31
- await sfuClient.iceTrickle({
32
- iceCandidate: getIceCandidate(candidate),
33
- peerType: PeerType.SUBSCRIBER,
34
- });
35
- });
36
-
37
- if (onTrack) {
38
- subscriber.addEventListener('track', onTrack);
39
- }
40
-
41
- const { iceTrickleBuffer } = sfuClient;
42
- const unsubscribe = dispatcher.on('subscriberOffer', async (message) => {
43
- if (message.eventPayload.oneofKind !== 'subscriberOffer') return;
44
- const { subscriberOffer } = message.eventPayload;
45
- logger?.('info', 'Received subscriberOffer', subscriberOffer);
46
-
47
- await subscriber.setRemoteDescription({
48
- type: 'offer',
49
- sdp: subscriberOffer.sdp,
50
- });
51
-
52
- iceTrickleBuffer.subscriberCandidates.subscribe(async (candidate) => {
53
- try {
54
- const iceCandidate = JSON.parse(candidate.iceCandidate);
55
- await subscriber.addIceCandidate(iceCandidate);
56
- } catch (e) {
57
- logger?.('error', `Subscriber: ICE candidate error`, {
58
- error: e,
59
- candidate,
60
- });
61
- }
62
- });
63
-
64
- // apply ice candidates
65
- const answer = await subscriber.createAnswer();
66
- await subscriber.setLocalDescription(answer);
67
-
68
- await sfuClient.sendAnswer({
69
- peerType: PeerType.SUBSCRIBER,
70
- sdp: answer.sdp || '',
71
- });
72
- });
73
-
74
- // we replace the close method of the subscriber PeerConnection
75
- // so that we can preform some cleanups before closing the connection.
76
- // We are doing this as currently there is no event that is fired
77
- // when the subscriber PeerConnection is closed.
78
- const originalClose = subscriber.close;
79
- subscriber.close = () => {
80
- unsubscribe();
81
- originalClose.call(subscriber);
82
- };
83
-
84
- return subscriber;
85
- };
86
-
87
- const attachDebugEventListeners = (subscriber: RTCPeerConnection) => {
88
- const logger = getLogger(['sfu-client']);
89
- subscriber.addEventListener('icecandidateerror', (e) => {
90
- const errorMessage =
91
- e instanceof RTCPeerConnectionIceErrorEvent &&
92
- `${e.errorCode}: ${e.errorText}`;
93
- logger?.('error', `Subscriber: ICE Candidate error: ${errorMessage}`);
94
- });
95
- subscriber.addEventListener('iceconnectionstatechange', () => {
96
- logger?.(
97
- 'info',
98
- `Subscriber: ICE Connection state changed: ${subscriber.iceConnectionState}`,
99
- );
100
- });
101
- subscriber.addEventListener('icegatheringstatechange', () => {
102
- logger?.(
103
- 'info',
104
- `Subscriber: ICE Gathering State: ${subscriber.iceGatheringState}`,
105
- );
106
- });
107
- };