@trillet-ai/web-sdk 1.5.8 → 1.6.0
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/dist/BrowserFingerprint.d.ts +46 -0
- package/dist/BrowserFingerprint.js +131 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +21 -4
- package/package.json +1 -1
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser Fingerprinting Utility
|
|
3
|
+
* Generates a deterministic fingerprint based on stable browser/hardware characteristics.
|
|
4
|
+
* Used for demo link usage limit tracking.
|
|
5
|
+
*
|
|
6
|
+
* Strategy:
|
|
7
|
+
* 1. localStorage persistence — generate once, reuse across tabs/sessions forever
|
|
8
|
+
* 2. Stable hardware-only seed — if storage is cleared, the same hardware signals
|
|
9
|
+
* produce the same hash, so the fingerprint stays consistent
|
|
10
|
+
* 3. Server-side IP fallback — handled by the backend when no fingerprint is sent
|
|
11
|
+
*/
|
|
12
|
+
export declare class BrowserFingerprint {
|
|
13
|
+
private static cachedFingerprint;
|
|
14
|
+
/**
|
|
15
|
+
* Generate (or retrieve) a deterministic browser fingerprint.
|
|
16
|
+
* Cached in memory → localStorage → derived from stable hardware signals.
|
|
17
|
+
*/
|
|
18
|
+
static generate(): Promise<string>;
|
|
19
|
+
/**
|
|
20
|
+
* Collect only hardware / environment signals that do NOT change between
|
|
21
|
+
* tabs, sessions, or browser restarts on the same device.
|
|
22
|
+
*
|
|
23
|
+
* Deliberately excluded (volatile / anti-fingerprint randomised):
|
|
24
|
+
* - canvas.toDataURL() — randomised per origin in many browsers
|
|
25
|
+
* - font detection — noisy across rendering states
|
|
26
|
+
* - screen.availWidth/Height — changes with taskbar / dock resize
|
|
27
|
+
* - navigator.doNotTrack — user can toggle
|
|
28
|
+
* - timezoneOffset — changes with DST
|
|
29
|
+
* - navigator.userAgent — changes on browser update
|
|
30
|
+
*/
|
|
31
|
+
private static getStableSignals;
|
|
32
|
+
/**
|
|
33
|
+
* WebGL vendor + renderer string (GPU identifier, very stable)
|
|
34
|
+
*/
|
|
35
|
+
private static getWebGLFingerprint;
|
|
36
|
+
/**
|
|
37
|
+
* SHA-256 hash of the signals object → hex string
|
|
38
|
+
*/
|
|
39
|
+
private static hashComponents;
|
|
40
|
+
private static getStored;
|
|
41
|
+
private static persist;
|
|
42
|
+
/**
|
|
43
|
+
* Clear both in-memory and persisted fingerprint (useful for testing)
|
|
44
|
+
*/
|
|
45
|
+
static clearCache(): void;
|
|
46
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser Fingerprinting Utility
|
|
3
|
+
* Generates a deterministic fingerprint based on stable browser/hardware characteristics.
|
|
4
|
+
* Used for demo link usage limit tracking.
|
|
5
|
+
*
|
|
6
|
+
* Strategy:
|
|
7
|
+
* 1. localStorage persistence — generate once, reuse across tabs/sessions forever
|
|
8
|
+
* 2. Stable hardware-only seed — if storage is cleared, the same hardware signals
|
|
9
|
+
* produce the same hash, so the fingerprint stays consistent
|
|
10
|
+
* 3. Server-side IP fallback — handled by the backend when no fingerprint is sent
|
|
11
|
+
*/
|
|
12
|
+
const STORAGE_KEY = 'trillet_dfp';
|
|
13
|
+
export class BrowserFingerprint {
|
|
14
|
+
/**
|
|
15
|
+
* Generate (or retrieve) a deterministic browser fingerprint.
|
|
16
|
+
* Cached in memory → localStorage → derived from stable hardware signals.
|
|
17
|
+
*/
|
|
18
|
+
static async generate() {
|
|
19
|
+
// 1. In-memory cache (fastest)
|
|
20
|
+
if (this.cachedFingerprint) {
|
|
21
|
+
return this.cachedFingerprint;
|
|
22
|
+
}
|
|
23
|
+
// 2. Persisted in localStorage (survives tab close / browser restart)
|
|
24
|
+
const stored = this.getStored();
|
|
25
|
+
if (stored) {
|
|
26
|
+
this.cachedFingerprint = stored;
|
|
27
|
+
return stored;
|
|
28
|
+
}
|
|
29
|
+
// 3. Derive from stable hardware signals and persist
|
|
30
|
+
const signals = this.getStableSignals();
|
|
31
|
+
const fingerprint = await this.hashComponents(signals);
|
|
32
|
+
this.persist(fingerprint);
|
|
33
|
+
this.cachedFingerprint = fingerprint;
|
|
34
|
+
return fingerprint;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Collect only hardware / environment signals that do NOT change between
|
|
38
|
+
* tabs, sessions, or browser restarts on the same device.
|
|
39
|
+
*
|
|
40
|
+
* Deliberately excluded (volatile / anti-fingerprint randomised):
|
|
41
|
+
* - canvas.toDataURL() — randomised per origin in many browsers
|
|
42
|
+
* - font detection — noisy across rendering states
|
|
43
|
+
* - screen.availWidth/Height — changes with taskbar / dock resize
|
|
44
|
+
* - navigator.doNotTrack — user can toggle
|
|
45
|
+
* - timezoneOffset — changes with DST
|
|
46
|
+
* - navigator.userAgent — changes on browser update
|
|
47
|
+
*/
|
|
48
|
+
static getStableSignals() {
|
|
49
|
+
return {
|
|
50
|
+
// Hardware — fixed for a given device
|
|
51
|
+
screen: {
|
|
52
|
+
width: window.screen.width,
|
|
53
|
+
height: window.screen.height,
|
|
54
|
+
colorDepth: window.screen.colorDepth,
|
|
55
|
+
pixelRatio: window.devicePixelRatio,
|
|
56
|
+
},
|
|
57
|
+
hardwareConcurrency: navigator.hardwareConcurrency,
|
|
58
|
+
deviceMemory: navigator.deviceMemory,
|
|
59
|
+
platform: navigator.platform,
|
|
60
|
+
maxTouchPoints: navigator.maxTouchPoints,
|
|
61
|
+
// WebGL vendor/renderer — GPU-based, stable
|
|
62
|
+
webgl: this.getWebGLFingerprint(),
|
|
63
|
+
// Locale — stable unless user changes OS language or moves timezone
|
|
64
|
+
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
65
|
+
language: navigator.language,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* WebGL vendor + renderer string (GPU identifier, very stable)
|
|
70
|
+
*/
|
|
71
|
+
static getWebGLFingerprint() {
|
|
72
|
+
try {
|
|
73
|
+
const canvas = document.createElement('canvas');
|
|
74
|
+
const gl = canvas.getContext('webgl') || canvas.getContext('experimental-webgl');
|
|
75
|
+
if (!gl)
|
|
76
|
+
return 'no-webgl';
|
|
77
|
+
const glContext = gl;
|
|
78
|
+
const debugInfo = glContext.getExtension('WEBGL_debug_renderer_info');
|
|
79
|
+
const vendor = debugInfo
|
|
80
|
+
? glContext.getParameter(debugInfo.UNMASKED_VENDOR_WEBGL)
|
|
81
|
+
: glContext.getParameter(glContext.VENDOR);
|
|
82
|
+
const renderer = debugInfo
|
|
83
|
+
? glContext.getParameter(debugInfo.UNMASKED_RENDERER_WEBGL)
|
|
84
|
+
: glContext.getParameter(glContext.RENDERER);
|
|
85
|
+
return `${vendor}~${renderer}`;
|
|
86
|
+
}
|
|
87
|
+
catch (_a) {
|
|
88
|
+
return 'webgl-error';
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* SHA-256 hash of the signals object → hex string
|
|
93
|
+
*/
|
|
94
|
+
static async hashComponents(components) {
|
|
95
|
+
const data = new TextEncoder().encode(JSON.stringify(components));
|
|
96
|
+
const hashBuffer = await crypto.subtle.digest('SHA-256', data);
|
|
97
|
+
return Array.from(new Uint8Array(hashBuffer))
|
|
98
|
+
.map((b) => b.toString(16).padStart(2, '0'))
|
|
99
|
+
.join('');
|
|
100
|
+
}
|
|
101
|
+
// ── localStorage helpers ───────────────────────────────────────────
|
|
102
|
+
static getStored() {
|
|
103
|
+
try {
|
|
104
|
+
return localStorage.getItem(STORAGE_KEY);
|
|
105
|
+
}
|
|
106
|
+
catch (_a) {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
static persist(fingerprint) {
|
|
111
|
+
try {
|
|
112
|
+
localStorage.setItem(STORAGE_KEY, fingerprint);
|
|
113
|
+
}
|
|
114
|
+
catch (_a) {
|
|
115
|
+
// Storage full or disabled — fingerprint still works in-memory
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Clear both in-memory and persisted fingerprint (useful for testing)
|
|
120
|
+
*/
|
|
121
|
+
static clearCache() {
|
|
122
|
+
this.cachedFingerprint = null;
|
|
123
|
+
try {
|
|
124
|
+
localStorage.removeItem(STORAGE_KEY);
|
|
125
|
+
}
|
|
126
|
+
catch (_a) {
|
|
127
|
+
// Ignore
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
BrowserFingerprint.cachedFingerprint = null;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { EventEmitter } from 'eventemitter3';
|
|
2
2
|
import { Transcript } from './TranscriptManager.js';
|
|
3
|
+
import { BrowserFingerprint } from './BrowserFingerprint.js';
|
|
4
|
+
export { BrowserFingerprint };
|
|
3
5
|
export interface TrilletAgentConfig {
|
|
4
6
|
apiKey?: string;
|
|
5
7
|
workspaceId?: string;
|
|
@@ -7,6 +9,7 @@ export interface TrilletAgentConfig {
|
|
|
7
9
|
variables?: Record<string, any>;
|
|
8
10
|
callbackUrl?: string;
|
|
9
11
|
mode?: 'voice' | 'text';
|
|
12
|
+
demoHash?: string;
|
|
10
13
|
}
|
|
11
14
|
export declare class TrilletAgent extends EventEmitter {
|
|
12
15
|
private sdk;
|
|
@@ -43,4 +46,9 @@ export declare class TrilletAgent extends EventEmitter {
|
|
|
43
46
|
*/
|
|
44
47
|
sendRpcMessage(method: string, payload: any, responseTimeout?: number): Promise<any>;
|
|
45
48
|
sendTextMessage(text: string): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Get the browser fingerprint for this session
|
|
51
|
+
* Useful for demo pages to send fingerprint when checking limits
|
|
52
|
+
*/
|
|
53
|
+
getBrowserFingerprint(): Promise<string>;
|
|
46
54
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { EventEmitter } from 'eventemitter3';
|
|
2
2
|
import { TrilletWebSDK } from './TrilletWebSDK.js';
|
|
3
3
|
import { TranscriptManager } from './TranscriptManager.js';
|
|
4
|
+
import { BrowserFingerprint } from './BrowserFingerprint.js';
|
|
5
|
+
// Export BrowserFingerprint for external use
|
|
6
|
+
export { BrowserFingerprint };
|
|
4
7
|
const TRILLET_API_URL = {
|
|
5
|
-
CONNECT: 'https://api
|
|
6
|
-
PUBLIC_CONNECT: 'https://api
|
|
8
|
+
CONNECT: 'https://api-trillet.verlatai.com/v1/api/web-call',
|
|
9
|
+
PUBLIC_CONNECT: 'https://api-trillet.verlatai.com/v1/api/web-call/public',
|
|
7
10
|
};
|
|
8
11
|
const decoder = new TextDecoder();
|
|
9
12
|
// Browser compatibility check
|
|
@@ -93,6 +96,8 @@ export class TrilletAgent extends EventEmitter {
|
|
|
93
96
|
}
|
|
94
97
|
async startCall() {
|
|
95
98
|
try {
|
|
99
|
+
// Generate browser fingerprint before making the call
|
|
100
|
+
const browserFingerprint = await BrowserFingerprint.generate();
|
|
96
101
|
// 2. Initialize call with API KEY
|
|
97
102
|
const response = await fetch(TRILLET_API_URL.CONNECT, {
|
|
98
103
|
method: 'POST',
|
|
@@ -106,6 +111,7 @@ export class TrilletAgent extends EventEmitter {
|
|
|
106
111
|
mode: this.config.mode,
|
|
107
112
|
dynamic_variables: this.config.variables || {},
|
|
108
113
|
callback_url: this.config.callbackUrl,
|
|
114
|
+
browser_fingerprint: browserFingerprint,
|
|
109
115
|
}),
|
|
110
116
|
});
|
|
111
117
|
if (!response.ok) {
|
|
@@ -126,7 +132,7 @@ export class TrilletAgent extends EventEmitter {
|
|
|
126
132
|
// Initialize call with LiveKit token
|
|
127
133
|
await this.sdk.initializeCall({
|
|
128
134
|
token: data.token,
|
|
129
|
-
wsUrl: 'wss://
|
|
135
|
+
wsUrl: 'wss://trilletai-ek0j3un1.livekit.cloud/',
|
|
130
136
|
mode: this.config.mode,
|
|
131
137
|
audioSettings: {
|
|
132
138
|
sampleRate: 48000,
|
|
@@ -155,6 +161,8 @@ export class TrilletAgent extends EventEmitter {
|
|
|
155
161
|
}
|
|
156
162
|
}
|
|
157
163
|
async startPublicCall() {
|
|
164
|
+
// Generate browser fingerprint before making the call
|
|
165
|
+
const browserFingerprint = await BrowserFingerprint.generate();
|
|
158
166
|
// 2. Initialize public call
|
|
159
167
|
const response = await fetch(TRILLET_API_URL.PUBLIC_CONNECT, {
|
|
160
168
|
method: 'POST',
|
|
@@ -168,6 +176,8 @@ export class TrilletAgent extends EventEmitter {
|
|
|
168
176
|
mode: this.config.mode,
|
|
169
177
|
dynamic_variables: this.config.variables || {},
|
|
170
178
|
callback_url: this.config.callbackUrl,
|
|
179
|
+
browser_fingerprint: browserFingerprint,
|
|
180
|
+
demo_hash: this.config.demoHash, // Send demo hash if provided
|
|
171
181
|
}),
|
|
172
182
|
});
|
|
173
183
|
if (!response.ok) {
|
|
@@ -188,7 +198,7 @@ export class TrilletAgent extends EventEmitter {
|
|
|
188
198
|
// Initialize call with LiveKit token
|
|
189
199
|
await this.sdk.initializeCall({
|
|
190
200
|
token: data.token,
|
|
191
|
-
wsUrl: 'wss://
|
|
201
|
+
wsUrl: 'wss://trilletai-ek0j3un1.livekit.cloud/',
|
|
192
202
|
mode: this.config.mode,
|
|
193
203
|
audioSettings: {
|
|
194
204
|
sampleRate: 48000,
|
|
@@ -299,4 +309,11 @@ export class TrilletAgent extends EventEmitter {
|
|
|
299
309
|
this.emit('error', new Error(`Failed to send message: ${error instanceof Error ? error.message : String(error)}`));
|
|
300
310
|
}
|
|
301
311
|
}
|
|
312
|
+
/**
|
|
313
|
+
* Get the browser fingerprint for this session
|
|
314
|
+
* Useful for demo pages to send fingerprint when checking limits
|
|
315
|
+
*/
|
|
316
|
+
async getBrowserFingerprint() {
|
|
317
|
+
return await BrowserFingerprint.generate();
|
|
318
|
+
}
|
|
302
319
|
}
|