@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 +1 -0
- package/dist/index.cjs.js +45 -4
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.mjs +45 -4
- package/dist/index.es.mjs.map +1 -1
- package/dist/src/StreamCall.d.ts +13 -1
- package/dist/src/StreamClient.d.ts +10 -0
- package/dist/src/types.d.ts +2 -1
- package/dist/src/utils/create-token.d.ts +1 -1
- package/package.json +1 -1
- package/src/StreamCall.ts +56 -1
- package/src/StreamClient.ts +18 -0
- package/src/StreamVideoClient.ts +1 -1
- package/src/types.ts +2 -1
- package/src/utils/create-token.ts +1 -1
package/dist/index.es.mjs
CHANGED
|
@@ -4954,8 +4954,11 @@ class CallApi {
|
|
|
4954
4954
|
}
|
|
4955
4955
|
|
|
4956
4956
|
class StreamCall extends CallApi {
|
|
4957
|
-
constructor() {
|
|
4958
|
-
super(
|
|
4957
|
+
constructor(videoApi, type, id, streamClient) {
|
|
4958
|
+
super(videoApi, type, id);
|
|
4959
|
+
this.type = type;
|
|
4960
|
+
this.id = id;
|
|
4961
|
+
this.streamClient = streamClient;
|
|
4959
4962
|
this.create = (request) => this.getOrCreate(request);
|
|
4960
4963
|
this.queryMembers = (request) => {
|
|
4961
4964
|
return this.videoApi.queryCallMembers({
|
|
@@ -4964,6 +4967,33 @@ class StreamCall extends CallApi {
|
|
|
4964
4967
|
...(request ?? {}),
|
|
4965
4968
|
});
|
|
4966
4969
|
};
|
|
4970
|
+
this.getOrCreate = async (request) => {
|
|
4971
|
+
const response = await super.getOrCreate(request);
|
|
4972
|
+
this.data = response.call;
|
|
4973
|
+
return response;
|
|
4974
|
+
};
|
|
4975
|
+
this.get = async () => {
|
|
4976
|
+
const response = await super.get();
|
|
4977
|
+
this.data = response.call;
|
|
4978
|
+
return response;
|
|
4979
|
+
};
|
|
4980
|
+
this.createSRTCredetials = (userID) => {
|
|
4981
|
+
if (!this.data) {
|
|
4982
|
+
throw new Error('Object is not initialized, call get() or getOrCreate() first');
|
|
4983
|
+
}
|
|
4984
|
+
const token = this.streamClient.generatePermanentUserToken({
|
|
4985
|
+
user_id: userID,
|
|
4986
|
+
});
|
|
4987
|
+
const segments = token.split('.');
|
|
4988
|
+
if (segments.length !== 3) {
|
|
4989
|
+
throw new Error('Invalid token format');
|
|
4990
|
+
}
|
|
4991
|
+
return {
|
|
4992
|
+
address: this.data.ingress.srt.address
|
|
4993
|
+
.replace('{passphrase}', segments[2])
|
|
4994
|
+
.replace('{token}', token),
|
|
4995
|
+
};
|
|
4996
|
+
};
|
|
4967
4997
|
}
|
|
4968
4998
|
get cid() {
|
|
4969
4999
|
return `${this.type}:${this.id}`;
|
|
@@ -4974,7 +5004,7 @@ class StreamVideoClient extends VideoApi {
|
|
|
4974
5004
|
constructor({ streamClient, apiClient, }) {
|
|
4975
5005
|
super(apiClient);
|
|
4976
5006
|
this.call = (type, id) => {
|
|
4977
|
-
return new StreamCall(this, type, id);
|
|
5007
|
+
return new StreamCall(this, type, id, this.streamClient);
|
|
4978
5008
|
};
|
|
4979
5009
|
this.connectOpenAi = async (options) => {
|
|
4980
5010
|
let doCreateRealtimeClient;
|
|
@@ -6619,7 +6649,7 @@ class ApiClient {
|
|
|
6619
6649
|
const headers = {
|
|
6620
6650
|
Authorization: this.apiConfig.token,
|
|
6621
6651
|
'stream-auth-type': 'jwt',
|
|
6622
|
-
'X-Stream-Client': 'stream-node-' + "0.7.
|
|
6652
|
+
'X-Stream-Client': 'stream-node-' + "0.7.2",
|
|
6623
6653
|
'Accept-Encoding': 'gzip',
|
|
6624
6654
|
'x-client-request-id': clientRequestId,
|
|
6625
6655
|
};
|
|
@@ -7808,6 +7838,17 @@ class StreamClient extends CommonApi {
|
|
|
7808
7838
|
payload.exp = payload.exp ?? payload.iat + validityInSeconds;
|
|
7809
7839
|
return JWTUserToken(this.secret, payload);
|
|
7810
7840
|
};
|
|
7841
|
+
/**
|
|
7842
|
+
*
|
|
7843
|
+
* @param payload
|
|
7844
|
+
* - user_id - the id of the user the token is for
|
|
7845
|
+
* - iat - issued at date of the token, unix timestamp in seconds, by default it's now
|
|
7846
|
+
*/
|
|
7847
|
+
this.generatePermanentUserToken = (payload) => {
|
|
7848
|
+
const defaultIat = Math.floor((Date.now() - 1000) / 1000);
|
|
7849
|
+
payload.iat = payload.iat ?? defaultIat;
|
|
7850
|
+
return JWTUserToken(this.secret, payload);
|
|
7851
|
+
};
|
|
7811
7852
|
/**
|
|
7812
7853
|
*
|
|
7813
7854
|
* @param payload
|