@stream-io/video-client 0.6.10 → 0.7.1

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 (34) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/index.browser.es.js +60 -157
  3. package/dist/index.browser.es.js.map +1 -1
  4. package/dist/index.cjs.js +59 -164
  5. package/dist/index.cjs.js.map +1 -1
  6. package/dist/index.d.ts +0 -1
  7. package/dist/index.es.js +60 -162
  8. package/dist/index.es.js.map +1 -1
  9. package/dist/src/Call.d.ts +13 -1
  10. package/dist/src/coordinator/connection/client.d.ts +0 -11
  11. package/dist/src/coordinator/connection/signing.d.ts +1 -24
  12. package/dist/src/coordinator/connection/token_manager.d.ts +2 -3
  13. package/dist/src/coordinator/connection/types.d.ts +4 -4
  14. package/dist/src/gen/coordinator/index.d.ts +382 -1018
  15. package/dist/src/stats/utils.d.ts +11 -0
  16. package/dist/src/store/CallState.d.ts +2 -2
  17. package/index.ts +0 -1
  18. package/package.json +2 -3
  19. package/src/Call.ts +53 -0
  20. package/src/__tests__/StreamVideoClient.test.ts +8 -3
  21. package/src/coordinator/connection/client.ts +1 -40
  22. package/src/coordinator/connection/signing.ts +10 -89
  23. package/src/coordinator/connection/token_manager.ts +3 -17
  24. package/src/coordinator/connection/types.ts +4 -4
  25. package/src/gen/coordinator/index.ts +361 -983
  26. package/src/stats/utils.ts +23 -0
  27. package/src/store/CallState.ts +5 -4
  28. package/dist/src/StreamVideoServerClient.d.ts +0 -33
  29. package/src/StreamVideoServerClient.ts +0 -106
  30. package/src/__tests__/server-side/call-members.test.ts +0 -93
  31. package/src/__tests__/server-side/call-types.test.ts +0 -127
  32. package/src/__tests__/server-side/call.test.ts +0 -158
  33. package/src/__tests__/server-side/create-token.test.ts +0 -44
  34. package/src/__tests__/server-side/server-side-user.test.ts +0 -28
package/dist/index.d.ts CHANGED
@@ -8,7 +8,6 @@ export * from './src/stats/types';
8
8
  export * from './src/Call';
9
9
  export * from './src/CallType';
10
10
  export * from './src/StreamVideoClient';
11
- export * from './src/StreamVideoServerClient';
12
11
  export * from './src/StreamSfuClient';
13
12
  export * from './src/devices';
14
13
  export * from './src/store';
package/dist/index.es.js CHANGED
@@ -9,8 +9,6 @@ import * as SDP from 'sdp-transform';
9
9
  import { UAParser } from 'ua-parser-js';
10
10
  import WebSocket from 'isomorphic-ws';
11
11
  import https from 'https';
12
- import jwt from 'jsonwebtoken';
13
- import 'crypto';
14
12
  import { fromByteArray } from 'base64-js';
15
13
 
16
14
  /**
@@ -36,26 +34,6 @@ const CreateDeviceRequestPushProviderEnum = {
36
34
  HUAWEI: 'huawei',
37
35
  XIAOMI: 'xiaomi',
38
36
  };
39
- /**
40
- * @export
41
- */
42
- const LayoutSettingsNameEnum = {
43
- SPOTLIGHT: 'spotlight',
44
- GRID: 'grid',
45
- SINGLE_PARTICIPANT: 'single-participant',
46
- MOBILE: 'mobile',
47
- CUSTOM: 'custom',
48
- };
49
- /**
50
- * @export
51
- */
52
- const LayoutSettingsRequestNameEnum = {
53
- SPOTLIGHT: 'spotlight',
54
- GRID: 'grid',
55
- SINGLE_PARTICIPANT: 'single-participant',
56
- MOBILE: 'mobile',
57
- CUSTOM: 'custom',
58
- };
59
37
  /**
60
38
  * All possibility of string to use
61
39
  * @export
@@ -7109,6 +7087,7 @@ class CallState {
7109
7087
  'call.session_started': (e) => this.updateFromCallResponse(e.call),
7110
7088
  'call.unblocked_user': this.unblockUser,
7111
7089
  'call.updated': (e) => this.updateFromCallResponse(e.call),
7090
+ 'call.deleted': undefined,
7112
7091
  };
7113
7092
  }
7114
7093
  /**
@@ -9261,6 +9240,22 @@ const flatten$1 = (report) => {
9261
9240
  });
9262
9241
  return stats;
9263
9242
  };
9243
+ const getSdkSignature = (clientDetails) => {
9244
+ const { sdk, ...platform } = clientDetails;
9245
+ const sdkName = sdk && sdk.type === SdkType.REACT
9246
+ ? 'stream-react'
9247
+ : sdk && sdk.type === SdkType.REACT_NATIVE
9248
+ ? 'stream-react-native'
9249
+ : 'stream-js';
9250
+ const sdkVersion = sdk
9251
+ ? `${sdk.major}.${sdk.minor}.${sdk.patch}`
9252
+ : '0.0.0-development';
9253
+ return {
9254
+ sdkName,
9255
+ sdkVersion,
9256
+ ...platform,
9257
+ };
9258
+ };
9264
9259
 
9265
9260
  /**
9266
9261
  * Creates a new StatsReporter instance that collects metrics about the ongoing call and reports them to the state store
@@ -12612,6 +12607,37 @@ class Call {
12612
12607
  const endpoint = `${this.streamClientBasePath}/stats/${callSessionID}`;
12613
12608
  return this.streamClient.get(endpoint);
12614
12609
  };
12610
+ /**
12611
+ * Submit user feedback for the call
12612
+ *
12613
+ * @param rating Rating between 1 and 5 denoting the experience of the user in the call
12614
+ * @param reason The reason/description for the rating
12615
+ * @param custom Custom data
12616
+ * @returns
12617
+ */
12618
+ this.submitFeedback = async (rating, { reason, custom, } = {}) => {
12619
+ if (rating < 1 || rating > 5) {
12620
+ throw new Error('Rating must be between 1 and 5');
12621
+ }
12622
+ const userSessionId = this.sfuClient?.sessionId;
12623
+ const callSessionId = this.state.session?.id;
12624
+ if (!callSessionId || !userSessionId) {
12625
+ throw new Error('Feedback can be submitted only in the context of a call session');
12626
+ }
12627
+ const { sdkName, sdkVersion, ...platform } = getSdkSignature(getClientDetails());
12628
+ const endpoint = `${this.streamClientBasePath}/feedback/${callSessionId}`;
12629
+ return this.streamClient.post(endpoint, {
12630
+ rating,
12631
+ reason,
12632
+ user_session_id: userSessionId,
12633
+ sdk: sdkName,
12634
+ sdk_version: sdkVersion,
12635
+ custom: {
12636
+ ...custom,
12637
+ 'x-stream-platform-data': platform,
12638
+ },
12639
+ });
12640
+ };
12615
12641
  /**
12616
12642
  * Sends a custom event to all call participants.
12617
12643
  *
@@ -13616,52 +13642,6 @@ const decodeBase64 = (s) => {
13616
13642
  return r;
13617
13643
  };
13618
13644
 
13619
- /**
13620
- * Creates the JWT token that can be used for a UserSession
13621
- * @method JWTUserToken
13622
- * @memberof signing
13623
- * @private
13624
- * @param {Secret} apiSecret - API Secret key
13625
- * @param {string} userId - The user_id key in the JWT payload
13626
- * @param {UR} [extraData] - Extra that should be part of the JWT token
13627
- * @param {SignOptions} [jwtOptions] - Options that can be past to jwt.sign
13628
- * @return {string} JWT Token
13629
- */
13630
- function JWTUserToken(apiSecret, userId, extraData = {}, jwtOptions = {}) {
13631
- if (typeof userId !== 'string') {
13632
- throw new TypeError('userId should be a string');
13633
- }
13634
- const payload = {
13635
- user_id: userId,
13636
- ...extraData,
13637
- };
13638
- // make sure we return a clear error when jwt is shimmed (ie. browser build)
13639
- if (jwt == null || jwt.sign == null) {
13640
- throw Error(`Unable to find jwt crypto, if you are getting this error is probably because you are trying to generate tokens on browser or React Native (or other environment where crypto functions are not available). Please Note: token should only be generated server-side.`);
13641
- }
13642
- const opts = Object.assign({ algorithm: 'HS256', noTimestamp: true }, jwtOptions);
13643
- if (payload.iat) {
13644
- opts.noTimestamp = false;
13645
- }
13646
- return jwt.sign(payload, apiSecret, opts);
13647
- }
13648
- function JWTServerToken(apiSecret, jwtOptions = {}) {
13649
- const payload = {
13650
- server: true,
13651
- };
13652
- const opts = Object.assign({ algorithm: 'HS256', noTimestamp: true }, jwtOptions);
13653
- return jwt.sign(payload, apiSecret, opts);
13654
- }
13655
- function UserFromToken(token) {
13656
- const fragments = token.split('.');
13657
- if (fragments.length !== 3) {
13658
- return '';
13659
- }
13660
- const b64Payload = fragments[1];
13661
- const payload = decodeBase64(b64Payload);
13662
- const data = JSON.parse(payload);
13663
- return data.user_id;
13664
- }
13665
13645
  /**
13666
13646
  *
13667
13647
  * @param {string} userId the id of the user
@@ -13674,6 +13654,16 @@ function DevToken(userId) {
13674
13654
  'devtoken', // hardcoded signature
13675
13655
  ].join('.');
13676
13656
  }
13657
+ function UserFromToken(token) {
13658
+ const fragments = token.split('.');
13659
+ if (fragments.length !== 3) {
13660
+ return '';
13661
+ }
13662
+ const b64Payload = fragments[1];
13663
+ const payload = decodeBase64(b64Payload);
13664
+ const data = JSON.parse(payload);
13665
+ return data.user_id;
13666
+ }
13677
13667
 
13678
13668
  /**
13679
13669
  * TokenManager
@@ -13706,10 +13696,6 @@ class TokenManager {
13706
13696
  this.token = tokenOrProvider;
13707
13697
  this.type = 'static';
13708
13698
  }
13709
- if (!tokenOrProvider && this.user && this.secret) {
13710
- this.token = JWTUserToken(this.secret, user.id, {}, {});
13711
- this.type = 'static';
13712
- }
13713
13699
  await this.loadToken();
13714
13700
  };
13715
13701
  /**
@@ -13779,9 +13765,6 @@ class TokenManager {
13779
13765
  if (this.user && !this.token) {
13780
13766
  return this.token;
13781
13767
  }
13782
- if (this.secret) {
13783
- return JWTServerToken(this.secret);
13784
- }
13785
13768
  throw new Error(`Both secret and user tokens are not set. Either client.connectUser wasn't called or client.disconnect was called`);
13786
13769
  };
13787
13770
  this.isStatic = () => this.type === 'static';
@@ -13790,9 +13773,6 @@ class TokenManager {
13790
13773
  this.secret = secret;
13791
13774
  }
13792
13775
  this.type = 'static';
13793
- if (this.secret) {
13794
- this.token = JWTServerToken(this.secret);
13795
- }
13796
13776
  }
13797
13777
  }
13798
13778
 
@@ -14219,7 +14199,6 @@ class StreamClient {
14219
14199
  this.guestUserCreatePromise = this.doAxiosRequest('post', '/guest', {
14220
14200
  user: {
14221
14201
  ...user,
14222
- role: 'guest',
14223
14202
  },
14224
14203
  }, { publicEndpoint: true });
14225
14204
  const response = await this.guestUserCreatePromise;
@@ -14481,7 +14460,7 @@ class StreamClient {
14481
14460
  });
14482
14461
  };
14483
14462
  this.getUserAgent = () => {
14484
- const version = "0.6.10" ;
14463
+ const version = "0.7.1" ;
14485
14464
  return (this.userAgent ||
14486
14465
  `stream-video-javascript-client-${this.node ? 'node' : 'browser'}-${version}`);
14487
14466
  };
@@ -14553,32 +14532,6 @@ class StreamClient {
14553
14532
  this.createAbortControllerForNextRequest = () => {
14554
14533
  return (this.nextRequestAbortController = new AbortController());
14555
14534
  };
14556
- /**
14557
- * createToken - Creates a token to authenticate this user. This function is used server side.
14558
- * The resulting token should be passed to the client side when the users registers or logs in.
14559
- *
14560
- * @param {string} userID The UserWithId ID
14561
- * @param {number} [exp] The expiration time for the token expressed in the number of seconds since the epoch
14562
- * @param call_cids for anonymous tokens you have to provide the call cids the use can join
14563
- *
14564
- * @return {string} Returns a token
14565
- */
14566
- this.createToken = (userID, exp, iat, call_cids) => {
14567
- if (this.secret == null) {
14568
- throw Error(`tokens can only be created server-side using the API Secret`);
14569
- }
14570
- const extra = {};
14571
- if (exp) {
14572
- extra.exp = exp;
14573
- }
14574
- if (iat) {
14575
- extra.iat = iat;
14576
- }
14577
- if (call_cids) {
14578
- extra.call_cids = call_cids;
14579
- }
14580
- return JWTUserToken(this.secret, userID, extra, {});
14581
- };
14582
14535
  // set the key
14583
14536
  this.key = key;
14584
14537
  // set the secret
@@ -14983,60 +14936,5 @@ class StreamVideoClient {
14983
14936
  }
14984
14937
  }
14985
14938
 
14986
- /**
14987
- * @deprecated Please use the `@stream-io/node-sdk` package instead.
14988
- *
14989
- * @see https://getstream.io/video/docs/api/
14990
- */
14991
- class StreamVideoServerClient extends StreamVideoClient {
14992
- constructor(apiKey, options) {
14993
- super({ apiKey, options });
14994
- this.getCallTypes = () => {
14995
- return this.streamClient.get('/calltypes');
14996
- };
14997
- this.getCallType = (name) => {
14998
- return this.streamClient.get(`/calltypes/${name}`);
14999
- };
15000
- this.createCallType = (data) => {
15001
- return this.streamClient.post('/calltypes', data);
15002
- };
15003
- this.deleteCallType = (name) => {
15004
- return this.streamClient.delete(`/calltypes/${name}`);
15005
- };
15006
- this.updateCallType = (name, data) => {
15007
- return this.streamClient.put(`/calltypes/${name}`, data);
15008
- };
15009
- this.listExternalStorage = () => {
15010
- return this.streamClient.get('/external_storage');
15011
- };
15012
- this.createExternalStorage = (request) => {
15013
- return this.streamClient.post('/external_storage', request);
15014
- };
15015
- this.deleteExternalStorage = (name) => {
15016
- return this.streamClient.delete(`/external_storage/${name}`);
15017
- };
15018
- this.updateExternalStorage = (name, request) => {
15019
- return this.streamClient.put(`/external_storage/${name}`, request);
15020
- };
15021
- this.checkExternalStorage = (name) => {
15022
- return this.streamClient.get(`/external_storage/${name}/check`);
15023
- };
15024
- }
15025
- /**
15026
- * createToken - Creates a token to authenticate this user. This function is used server side.
15027
- * The resulting token should be passed to the client side when the users register or logs in.
15028
- *
15029
- * @param {string} userID The User ID
15030
- * @param {number} [exp] The expiration time for the token expressed in the number of seconds since the epoch
15031
- * @param {number} [iat] The timestamp when a token has been issued
15032
- * @param call_cids for anonymous tokens you have to provide the call cids the use can join
15033
- *
15034
- * @return {string} Returns a token
15035
- */
15036
- createToken(userID, exp, iat, call_cids) {
15037
- return this.streamClient.createToken(userID, exp, iat, call_cids);
15038
- }
15039
- }
15040
-
15041
- export { AudioSettingsDefaultDeviceEnum, AudioSettingsRequestDefaultDeviceEnum, browsers as Browsers, Call, CallState, CallType, CallTypes, CallingState, CameraManager, CameraManagerState, CreateDeviceRequestPushProviderEnum, DebounceType, DynascaleManager, ErrorFromResponse, InputMediaDeviceManager, InputMediaDeviceManagerState, LayoutSettingsNameEnum, LayoutSettingsRequestNameEnum, MicrophoneManager, MicrophoneManagerState, OwnCapability, RecordSettingsRequestModeEnum, RecordSettingsRequestQualityEnum, rxUtils as RxUtils, ScreenShareManager, ScreenShareState, events as SfuEvents, models as SfuModels, SpeakerManager, SpeakerState, StreamSfuClient, StreamVideoClient, StreamVideoReadOnlyStateStore, StreamVideoServerClient, StreamVideoWriteableStateStore, TranscriptionSettingsModeEnum, TranscriptionSettingsRequestModeEnum, VideoSettingsCameraFacingEnum, VideoSettingsRequestCameraFacingEnum, ViewportTracker, VisibilityState, checkIfAudioOutputChangeSupported, combineComparators, conditional, createSoundDetector, defaultSortPreset, descending, deviceIds$, disposeOfMediaStream, dominantSpeaker, getAudioDevices, getAudioOutputDevices, getAudioStream, getClientDetails, getDeviceInfo, getLogger, getOSInfo, getScreenShareStream, getSdkInfo, getVideoDevices, getVideoStream, getWebRTCInfo, livestreamOrAudioRoomSortPreset, logLevels, logToConsole, name, noopComparator, paginatedLayoutSortPreset, pinned, publishingAudio, publishingVideo, reactionType, role, screenSharing, setDeviceInfo, setLogLevel, setLogger, setOSInfo, setSdkInfo, setWebRTCInfo, speakerLayoutSortPreset, speaking };
14939
+ export { AudioSettingsDefaultDeviceEnum, AudioSettingsRequestDefaultDeviceEnum, browsers as Browsers, Call, CallState, CallType, CallTypes, CallingState, CameraManager, CameraManagerState, CreateDeviceRequestPushProviderEnum, DebounceType, DynascaleManager, ErrorFromResponse, InputMediaDeviceManager, InputMediaDeviceManagerState, MicrophoneManager, MicrophoneManagerState, OwnCapability, RecordSettingsRequestModeEnum, RecordSettingsRequestQualityEnum, rxUtils as RxUtils, ScreenShareManager, ScreenShareState, events as SfuEvents, models as SfuModels, SpeakerManager, SpeakerState, StreamSfuClient, StreamVideoClient, StreamVideoReadOnlyStateStore, StreamVideoWriteableStateStore, TranscriptionSettingsModeEnum, TranscriptionSettingsRequestModeEnum, VideoSettingsCameraFacingEnum, VideoSettingsRequestCameraFacingEnum, ViewportTracker, VisibilityState, checkIfAudioOutputChangeSupported, combineComparators, conditional, createSoundDetector, defaultSortPreset, descending, deviceIds$, disposeOfMediaStream, dominantSpeaker, getAudioDevices, getAudioOutputDevices, getAudioStream, getClientDetails, getDeviceInfo, getLogger, getOSInfo, getScreenShareStream, getSdkInfo, getVideoDevices, getVideoStream, getWebRTCInfo, livestreamOrAudioRoomSortPreset, logLevels, logToConsole, name, noopComparator, paginatedLayoutSortPreset, pinned, publishingAudio, publishingVideo, reactionType, role, screenSharing, setDeviceInfo, setLogLevel, setLogger, setOSInfo, setSdkInfo, setWebRTCInfo, speakerLayoutSortPreset, speaking };
15042
14940
  //# sourceMappingURL=index.es.js.map