@eluvio/elv-client-js 4.0.60 → 4.0.62

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/src/ElvClient.js CHANGED
@@ -20,7 +20,7 @@ const Pako = require("pako");
20
20
  const {
21
21
  ValidatePresence
22
22
  } = require("./Validation");
23
- const CBOR = require("cbor");
23
+ const CBOR = require("cbor-x");
24
24
 
25
25
  const networks = {
26
26
  "main": "https://main.net955305.contentfabric.io",
@@ -595,24 +595,27 @@ class ElvClient {
595
595
  formatArguments: true
596
596
  });
597
597
 
598
+ let nodeId = this.utils.AddressToNodeId(addr);
599
+
600
+ if(matchNodeId && nodeId !== matchNodeId) {
601
+ return;
602
+ }
603
+
598
604
  let locatorsHex = await this.CallContractMethod({
599
605
  contractAddress: this.contentSpaceAddress,
600
606
  methodName: "activeNodeLocators",
601
607
  methodArgs: [bigi]
602
608
  });
603
609
 
604
- let nodeId = this.utils.AddressToNodeId(addr);
605
-
606
- if(matchNodeId &&nodeId !== matchNodeId) {
607
- return;
608
- }
609
-
610
610
  let node = {id: nodeId, endpoints: []};
611
611
 
612
612
  // Parse locators CBOR
613
- let buffer = locatorsHex.slice(2, locatorsHex.length); // Skip "0x"
614
- let hex = buffer.toString("hex");
615
- let locators = CBOR.decodeAllSync(hex);
613
+ let locators = CBOR.decodeMultiple(
614
+ Buffer.from(
615
+ locatorsHex.slice(2, locatorsHex.length),
616
+ "hex"
617
+ )
618
+ );
616
619
 
617
620
  let match = false;
618
621
 
package/src/Utils.js CHANGED
@@ -743,36 +743,47 @@ const Utils = {
743
743
  }
744
744
  },
745
745
 
746
- LiveHLSJSSettings({lowLatency=false, ultraLowLatency=false}) {
746
+ HLSJSSettings({profile="default"}={}) {
747
747
  const isSafari =
748
748
  typeof window !== "undefined" &&
749
749
  typeof window.navigator !== "undefined" &&
750
750
  /^((?!chrome|android).)*safari/i.test(window.navigator.userAgent);
751
751
 
752
- if(ultraLowLatency && !isSafari) {
752
+ const defaultSettings = {
753
+ "maxBufferHole": 2.2,
754
+ "nudgeOffset": 0.2,
755
+ "nudgeMaxRetry": 12,
756
+ "highBufferWatchdogPeriod": 1
757
+ };
758
+
759
+ if(!isSafari && ["ull", "ultraLowLatency"].includes(profile)) {
753
760
  return {
754
- "capLevelToPlayerSize": false,
755
- "enableWorker": true,
756
761
  "lowLatencyMode": true,
757
- "maxBufferLength": 8,
758
- "backBufferLength": 4,
759
762
  "liveSyncDuration": 4,
760
763
  "liveMaxLatencyDuration": 5,
761
764
  "liveDurationInfinity": false,
762
- "highBufferWatchdogPeriod": 1
765
+ "maxBufferLength": 8,
766
+ "backBufferLength": 4,
767
+ ...defaultSettings
768
+ };
769
+ } else if(["ll", "lowLatency", "ull", "ultraLowLatency"].includes(profile)) {
770
+ return {
771
+ "lowLatencyMode": true,
772
+ "liveSyncDuration": 5,
773
+ "liveMaxLatencyDuration": isSafari ? 15 : 10,
774
+ "liveDurationInfinity": false,
775
+ "maxBufferLength": 5,
776
+ "backBufferLength": 5,
777
+ ...defaultSettings
763
778
  };
779
+ } else {
780
+ return defaultSettings;
764
781
  }
782
+ },
765
783
 
766
- return {
767
- "enableWorker": true,
768
- "lowLatencyMode": true,
769
- "maxBufferLength": 5,
770
- "backBufferLength": 5,
771
- "liveSyncDuration": 5,
772
- "liveMaxLatencyDuration": !lowLatency || isSafari ? 15 : 10,
773
- "liveDurationInfinity": false,
774
- "highBufferWatchdogPeriod": 1
775
- };
784
+ // Alias for HLSJSSettings
785
+ LiveHLSJSSettings({lowLatency=false, ultraLowLatency=false}) {
786
+ return Utils.HLSJSSettings({profile: ultraLowLatency ? "ull" : lowLatency ? "ll" : "default"});
776
787
  }
777
788
  };
778
789
 
@@ -33,21 +33,26 @@ exports.ListAccessGroups = async function() {
33
33
  5,
34
34
  addresses,
35
35
  async address => {
36
- const id = this.utils.AddressToHash(address);
37
- const meta = (await this.ContentObjectMetadata({
38
- libraryId: this.contentSpaceLibraryId,
39
- objectId: `iq__${id}`
40
- })) || {};
41
-
42
- return {
43
- address,
44
- id: `igrp${id}`,
45
- meta
46
- };
36
+ try {
37
+ const id = this.utils.AddressToHash(address);
38
+ const meta = (await this.ContentObjectMetadata({
39
+ libraryId: this.contentSpaceLibraryId,
40
+ objectId: `iq__${id}`
41
+ })) || {};
42
+
43
+ return {
44
+ address,
45
+ id: `igrp${id}`,
46
+ meta
47
+ };
48
+ } catch(error) {
49
+ this.Log(error, true);
50
+ }
47
51
  }
48
52
  );
49
53
 
50
54
  return groups
55
+ .filter(g => g)
51
56
  .sort((a, b) => {
52
57
  const name1 = (a.meta.public || {}).name || `zz__${a.address}`;
53
58
  const name2 = (b.meta.public || {}).name || `zz__${b.address}`;
@@ -161,57 +161,50 @@ class LiveConf {
161
161
  }
162
162
 
163
163
  calcSegDuration({sourceTimescale}) {
164
-
165
164
  let videoStream = this.getStreamDataForCodecType("video");
166
165
  let frameRate = videoStream.frame_rate;
167
166
 
168
- let seg ={};
167
+ let seg = {};
168
+ seg.audio = 29.76 * 48000;
169
+
169
170
  switch(frameRate) {
170
171
  case "24":
171
172
  seg.video = 30 * sourceTimescale;
172
- seg.audio = 30 * 48000;
173
173
  seg.keyint = 48;
174
174
  seg.duration = "30";
175
175
  break;
176
176
  case "25":
177
177
  seg.video = 30 * sourceTimescale;
178
- seg.audio = 30 * 48000;
179
178
  seg.keyint = 50;
180
179
  seg.duration = "30";
181
180
  break;
182
181
  case "30":
183
182
  seg.video = 30 * sourceTimescale;
184
- seg.audio = 30 * 48000;
185
183
  seg.keyint = 60;
186
184
  seg.duration = "30";
187
185
  break;
188
186
  case "30000/1001":
189
187
  seg.video = 30.03 * sourceTimescale;
190
- seg.audio = 29.76 * 48000;
191
188
  seg.keyint = 60;
192
189
  seg.duration = "30.03";
193
190
  break;
194
191
  case "48":
195
192
  seg.video = 30 * sourceTimescale;
196
- seg.audio = 30 * 48000;
197
193
  seg.keyint = 96;
198
194
  seg.duration = "30";
199
195
  break;
200
196
  case "50":
201
197
  seg.video = 30 * sourceTimescale;
202
- seg.audio = 30 * 48000;
203
198
  seg.keyint = 100;
204
199
  seg.duration = "30";
205
200
  break;
206
201
  case "60":
207
202
  seg.video = 30 * sourceTimescale;
208
- seg.audio = 30 * 48000;
209
203
  seg.keyint = 120;
210
204
  seg.duration = "30";
211
205
  break;
212
206
  case "60000/1001":
213
207
  seg.video = 30.03 * sourceTimescale;
214
- seg.audio = 29.76 * 48000;
215
208
  seg.keyint = 120;
216
209
  seg.duration = "30.03";
217
210
  break;
@@ -861,8 +861,8 @@ class ElvWalletClient {
861
861
  async LatestMarketplaceHash({marketplaceParams}) {
862
862
  const marketplaceInfo = await this.MarketplaceInfo({marketplaceParams});
863
863
 
864
- if(this.previewMarketplaceId && this.previewMarketplaceId === marketplaceInfo.marketplaceId) {
865
- return this.availableMarketplaces[marketplaceInfo.tenantSlug][marketplaceInfo.marketplaceSlug]["."].source;
864
+ if(this.previewMarketplaceId && Utils.EqualHash(this.previewMarketplaceId, marketplaceInfo.marketplaceId)) {
865
+ return this.previewMarketplaceHash;
866
866
  }
867
867
 
868
868
  const marketplaceLink = await this.client.ContentObjectMetadata({
@@ -887,18 +887,37 @@ class ElvWalletClient {
887
887
  }
888
888
 
889
889
  if(!this.cachedMarketplaces[marketplaceId]) {
890
- let marketplace = await this.client.ContentObjectMetadata({
891
- libraryId: this.mainSiteLibraryId,
892
- objectId: this.mainSiteId,
893
- metadataSubtree: UrlJoin("/public", "asset_metadata", "tenants", marketplaceInfo.tenantSlug, "marketplaces", marketplaceInfo.marketplaceSlug, "info"),
894
- localizationSubtree: this.localization ? UrlJoin("public", "asset_metadata", "localizations", this.localization, "info") : "",
895
- linkDepthLimit: 1,
896
- resolveLinks: true,
897
- resolveIgnoreErrors: true,
898
- resolveIncludeSource: true,
899
- produceLinkUrls: true,
900
- authorizationToken: this.publicStaticToken
901
- });
890
+ let marketplace;
891
+ if(this.previewMarketplaceId && Utils.EqualHash(marketplaceId, this.previewMarketplaceId)) {
892
+ // Load preview marketplace
893
+ marketplace = await this.client.ContentObjectMetadata({
894
+ versionHash: this.previewMarketplaceHash,
895
+ metadataSubtree: "/public/asset_metadata/info",
896
+ localizationSubtree: this.localization ? UrlJoin("public", "asset_metadata", "localizations", this.localization, "info") : undefined,
897
+ linkDepthLimit: 1,
898
+ resolveLinks: true,
899
+ resolveIgnoreErrors: true,
900
+ resolveIncludeSource: true,
901
+ produceLinkUrls: true,
902
+ authorizationToken: this.publicStaticToken
903
+ });
904
+ } else {
905
+ // Load marketplace from main site tree
906
+ marketplace = await this.client.ContentObjectMetadata({
907
+ libraryId: this.mainSiteLibraryId,
908
+ objectId: this.mainSiteId,
909
+ metadataSubtree: UrlJoin("/public", "asset_metadata", "tenants", marketplaceInfo.tenantSlug, "marketplaces", marketplaceInfo.marketplaceSlug, "info"),
910
+ localizationSubtree: this.localization ?
911
+ UrlJoin("/public", "asset_metadata", "tenants", marketplaceInfo.tenantSlug, "marketplaces", marketplaceInfo.marketplaceSlug, "localizations", this.localization, "info") :
912
+ undefined,
913
+ linkDepthLimit: 1,
914
+ resolveLinks: true,
915
+ resolveIgnoreErrors: true,
916
+ resolveIncludeSource: true,
917
+ produceLinkUrls: true,
918
+ authorizationToken: this.publicStaticToken
919
+ });
920
+ }
902
921
 
903
922
  if(marketplace.branding.use_tenant_styling) {
904
923
  marketplace.tenantBranding = (await this.client.ContentObjectMetadata({