@observertc/client-monitor-js 1.3.1 → 1.3.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.
@@ -78,10 +78,10 @@ class ClientDevices {
78
78
  }
79
79
  }
80
80
  this._actualHashes = {
81
- os: (0, hash_1.hash)(this._os),
82
- browser: (0, hash_1.hash)(this._browser),
83
- platform: (0, hash_1.hash)(this._platform),
84
- engine: (0, hash_1.hash)(this._engine),
81
+ os: (0, hash_1.makeStamp)(this._os),
82
+ browser: (0, hash_1.makeStamp)(this._browser),
83
+ platform: (0, hash_1.makeStamp)(this._platform),
84
+ engine: (0, hash_1.makeStamp)(this._engine),
85
85
  };
86
86
  }
87
87
  get os() {
@@ -6,12 +6,12 @@ const hash_1 = require("../utils/hash");
6
6
  /*eslint-disable @typescript-eslint/no-explicit-any */
7
7
  function hash(obj) {
8
8
  if (!obj)
9
- return (0, hash_1.hash)(obj);
9
+ return (0, hash_1.makeStamp)(obj);
10
10
  // we strip out the timestamp field to create a hash here.
11
11
  // timestamp in w3c means the last time it was accessed, and that
12
12
  // is irrelevant for us in this situation when we do hash
13
13
  obj.timestamp = undefined;
14
- return (0, hash_1.hash)(obj);
14
+ return (0, hash_1.makeStamp)(obj);
15
15
  }
16
16
  /*eslint-disable @typescript-eslint/no-explicit-any */
17
17
  function hashMediaSourceStat(obj) {
@@ -1,2 +1,2 @@
1
- export declare function hash(obj: any): string;
1
+ export declare function makeStamp(obj: any): string;
2
2
  //# sourceMappingURL=hash.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../src/utils/hash.ts"],"names":[],"mappings":"AAGA,wBAAgB,IAAI,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM,CA2CrC"}
1
+ {"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../src/utils/hash.ts"],"names":[],"mappings":"AACA,wBAAgB,SAAS,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM,CAiC1C"}
package/lib/utils/hash.js CHANGED
@@ -1,50 +1,38 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.hash = void 0;
4
- const js_sha256_1 = require("js-sha256");
3
+ exports.makeStamp = void 0;
5
4
  /*eslint-disable @typescript-eslint/no-explicit-any */
6
- function hash(obj) {
7
- const digester = js_sha256_1.sha256.create();
5
+ function makeStamp(obj) {
6
+ // const digester = sha256.create();
8
7
  if (obj === undefined) {
9
- digester.update("undefined");
10
- return digester.hex();
8
+ // digester.update("undefined");
9
+ return '0';
11
10
  }
12
11
  if (obj === null) {
13
- digester.update("undefined");
14
- return digester.hex();
12
+ // digester.update("undefined");
13
+ return '1';
15
14
  }
16
15
  const type = typeof obj;
17
16
  if (type === "function") {
18
- digester.update("function");
19
- return digester.hex();
17
+ // digester.update("function");
18
+ return '2';
20
19
  }
21
20
  if (type === "object") {
21
+ const stringbuffer = [];
22
22
  for (const [key, value] of Object.entries(obj)) {
23
- const valueHash = hash(value);
24
- digester.update(key + valueHash);
23
+ stringbuffer.push(makeStamp(value));
25
24
  }
26
- return digester.hex();
27
- }
28
- switch (type) {
29
- case "bigint":
30
- digester.update(obj.toString());
31
- break;
32
- case "boolean":
33
- digester.update(obj.toString());
34
- break;
35
- case "number":
36
- digester.update(obj.toString());
37
- break;
38
- case "string":
39
- digester.update(obj);
40
- break;
41
- case "undefined":
42
- digester.update("undefined");
43
- break;
44
- case "symbol":
45
- digester.update(obj.toString());
46
- break;
25
+ let result = stringbuffer.join('');
26
+ while (256 < result.length) {
27
+ const charcodes = [];
28
+ for (let i = 0; i < result.length; i += 2) {
29
+ const charCode = result.charCodeAt(i) ^ result.charCodeAt(i + 1);
30
+ charcodes.push(charCode);
31
+ }
32
+ result = String.fromCharCode(...charcodes);
33
+ }
34
+ return result;
47
35
  }
48
- return digester.hex();
36
+ return `${obj}`;
49
37
  }
50
- exports.hash = hash;
38
+ exports.makeStamp = makeStamp;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@observertc/client-monitor-js",
3
- "version": "1.3.1",
3
+ "version": "1.3.2",
4
4
  "description": "ObserveRTC Client Integration Javascript Library",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -31,7 +31,6 @@
31
31
  "@types/uuid": "^8.3.4",
32
32
  "bowser": "^2.11.0",
33
33
  "js-base64": "^3.7.2",
34
- "js-sha256": "^0.9.0",
35
34
  "loglevel": "^1.8.0",
36
35
  "protobufjs": "^6.11.3",
37
36
  "uuid": "^8.3.2"
@@ -1,7 +1,7 @@
1
1
  import * as Bowser from "bowser";
2
2
  import { Browser, Engine, OperationSystem, Platform } from "@observertc/monitor-schemas";
3
3
  import { createLogger } from "./utils/logger";
4
- import { hash } from "./utils/hash";
4
+ import { makeStamp } from "./utils/hash";
5
5
 
6
6
  // import * as proto from "./ProtobufSamples"
7
7
  const logger = createLogger("ClientDevices");
@@ -67,10 +67,10 @@ export class ClientDevices {
67
67
  }
68
68
  }
69
69
  this._actualHashes = {
70
- os: hash(this._os),
71
- browser: hash(this._browser),
72
- platform: hash(this._platform),
73
- engine: hash(this._engine),
70
+ os: makeStamp(this._os),
71
+ browser: makeStamp(this._browser),
72
+ platform: makeStamp(this._platform),
73
+ engine: makeStamp(this._engine),
74
74
  };
75
75
  }
76
76
 
@@ -22,7 +22,7 @@ import {
22
22
  PeerConnectionEntry,
23
23
  AudioPlayoutEntry,
24
24
  } from "./StatsEntryInterfaces";
25
- import { hash as objHash } from "../utils/hash";
25
+ import { makeStamp as objHash } from "../utils/hash";
26
26
  import { W3CStats as W3C } from "@observertc/monitor-schemas";
27
27
 
28
28
  /*eslint-disable @typescript-eslint/no-explicit-any */
package/src/utils/hash.ts CHANGED
@@ -1,47 +1,35 @@
1
- import { sha256 } from "js-sha256";
2
-
3
1
  /*eslint-disable @typescript-eslint/no-explicit-any */
4
- export function hash(obj: any): string {
5
- const digester = sha256.create();
2
+ export function makeStamp(obj: any): string {
3
+ // const digester = sha256.create();
6
4
  if (obj === undefined) {
7
- digester.update("undefined");
8
- return digester.hex();
5
+ // digester.update("undefined");
6
+ return '0';
9
7
  }
10
8
  if (obj === null) {
11
- digester.update("undefined");
12
- return digester.hex();
9
+ // digester.update("undefined");
10
+ return '1';
13
11
  }
14
12
  const type = typeof obj;
15
13
  if (type === "function") {
16
- digester.update("function");
17
- return digester.hex();
14
+ // digester.update("function");
15
+ return '2';
18
16
  }
17
+
19
18
  if (type === "object") {
19
+ const stringbuffer: string[] = [];
20
20
  for (const [key, value] of Object.entries(obj)) {
21
- const valueHash = hash(value);
22
- digester.update(key + valueHash);
21
+ stringbuffer.push(makeStamp(value));
23
22
  }
24
- return digester.hex();
25
- }
26
- switch (type) {
27
- case "bigint":
28
- digester.update((obj as bigint).toString());
29
- break;
30
- case "boolean":
31
- digester.update((obj as boolean).toString());
32
- break;
33
- case "number":
34
- digester.update((obj as number).toString());
35
- break;
36
- case "string":
37
- digester.update(obj as string);
38
- break;
39
- case "undefined":
40
- digester.update("undefined");
41
- break;
42
- case "symbol":
43
- digester.update((obj as symbol).toString());
44
- break;
23
+ let result = stringbuffer.join('');
24
+ while (256 < result.length) {
25
+ const charcodes: number[] = [];
26
+ for (let i = 0; i < result.length; i += 2) {
27
+ const charCode = result.charCodeAt(i) ^ result.charCodeAt(i + 1);
28
+ charcodes.push(charCode);
29
+ }
30
+ result = String.fromCharCode(...charcodes);
31
+ }
32
+ return result;
45
33
  }
46
- return digester.hex();
34
+ return `${obj}`;
47
35
  }
@@ -1,4 +1,4 @@
1
- import { hash } from "../../src/utils/hash";
1
+ import { makeStamp as hash } from "../../src/utils/hash";
2
2
  describe("hash", () => {
3
3
  describe("executions on differnet type of inputs", () => {
4
4
  it("When undefined is hashed Then its not undefined", () => {
@@ -21,10 +21,10 @@ describe("hash", () => {
21
21
  const hashedObj = hash(source);
22
22
  expect(hashedObj).not.toBe(source);
23
23
  });
24
- it("When string is hashed Then its not the same", () => {
24
+ it("When string is hashed Then its the same", () => {
25
25
  const source = "Simpsons";
26
26
  const hashedObj = hash(source);
27
- expect(hashedObj).not.toBe(source);
27
+ expect(hashedObj).toBe(source);
28
28
  });
29
29
  it("When function is hashed Then its not the same", () => {
30
30
  const source = function (): string { return "something"; }