@stream-io/node-sdk 0.7.1 → 0.7.2

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/README.md CHANGED
@@ -14,6 +14,7 @@ The package is tested against these environments:
14
14
  - Node.js@18
15
15
  - Node.js@20
16
16
  - Node.js@22
17
+ - Node.js@24
17
18
  - Bun@1
18
19
 
19
20
  ## What is Stream?
package/dist/index.cjs.js CHANGED
@@ -4973,8 +4973,11 @@ class CallApi {
4973
4973
  }
4974
4974
 
4975
4975
  class StreamCall extends CallApi {
4976
- constructor() {
4977
- super(...arguments);
4976
+ constructor(videoApi, type, id, streamClient) {
4977
+ super(videoApi, type, id);
4978
+ this.type = type;
4979
+ this.id = id;
4980
+ this.streamClient = streamClient;
4978
4981
  this.create = (request) => this.getOrCreate(request);
4979
4982
  this.queryMembers = (request) => {
4980
4983
  return this.videoApi.queryCallMembers({
@@ -4983,6 +4986,33 @@ class StreamCall extends CallApi {
4983
4986
  ...(request ?? {}),
4984
4987
  });
4985
4988
  };
4989
+ this.getOrCreate = async (request) => {
4990
+ const response = await super.getOrCreate(request);
4991
+ this.data = response.call;
4992
+ return response;
4993
+ };
4994
+ this.get = async () => {
4995
+ const response = await super.get();
4996
+ this.data = response.call;
4997
+ return response;
4998
+ };
4999
+ this.createSRTCredetials = (userID) => {
5000
+ if (!this.data) {
5001
+ throw new Error('Object is not initialized, call get() or getOrCreate() first');
5002
+ }
5003
+ const token = this.streamClient.generatePermanentUserToken({
5004
+ user_id: userID,
5005
+ });
5006
+ const segments = token.split('.');
5007
+ if (segments.length !== 3) {
5008
+ throw new Error('Invalid token format');
5009
+ }
5010
+ return {
5011
+ address: this.data.ingress.srt.address
5012
+ .replace('{passphrase}', segments[2])
5013
+ .replace('{token}', token),
5014
+ };
5015
+ };
4986
5016
  }
4987
5017
  get cid() {
4988
5018
  return `${this.type}:${this.id}`;
@@ -4993,7 +5023,7 @@ class StreamVideoClient extends VideoApi {
4993
5023
  constructor({ streamClient, apiClient, }) {
4994
5024
  super(apiClient);
4995
5025
  this.call = (type, id) => {
4996
- return new StreamCall(this, type, id);
5026
+ return new StreamCall(this, type, id, this.streamClient);
4997
5027
  };
4998
5028
  this.connectOpenAi = async (options) => {
4999
5029
  let doCreateRealtimeClient;
@@ -6638,7 +6668,7 @@ class ApiClient {
6638
6668
  const headers = {
6639
6669
  Authorization: this.apiConfig.token,
6640
6670
  'stream-auth-type': 'jwt',
6641
- 'X-Stream-Client': 'stream-node-' + "0.7.1",
6671
+ 'X-Stream-Client': 'stream-node-' + "0.7.2",
6642
6672
  'Accept-Encoding': 'gzip',
6643
6673
  'x-client-request-id': clientRequestId,
6644
6674
  };
@@ -7827,6 +7857,17 @@ class StreamClient extends CommonApi {
7827
7857
  payload.exp = payload.exp ?? payload.iat + validityInSeconds;
7828
7858
  return JWTUserToken(this.secret, payload);
7829
7859
  };
7860
+ /**
7861
+ *
7862
+ * @param payload
7863
+ * - user_id - the id of the user the token is for
7864
+ * - iat - issued at date of the token, unix timestamp in seconds, by default it's now
7865
+ */
7866
+ this.generatePermanentUserToken = (payload) => {
7867
+ const defaultIat = Math.floor((Date.now() - 1000) / 1000);
7868
+ payload.iat = payload.iat ?? defaultIat;
7869
+ return JWTUserToken(this.secret, payload);
7870
+ };
7830
7871
  /**
7831
7872
  *
7832
7873
  * @param payload