@codenkay/video-nsgplayer-angular 5.0.0 → 5.1.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/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Changelog
2
2
 
3
+ ## 5.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Add student lease wiring to `nsg-video-player`. Inputs: `lease` (`StudentLeaseConfig`), `leaseMediaType`, `leaseDomWatermark`. Outputs: `leaseStarted` (the `/student/playback` data), `leaseError` (`StudentLeaseError`; check `code` for `PLATFORM_IN_USE` and `PLAYBACK_NOT_READY`), `leasePreparing`, and `leaseWatermark`. The lease starts for `videoId`, heartbeats, and releases on destroy, `ended`, and `pagehide`. A token-only change to `lease` updates the live client.
8
+ - Lease watermark text is drawn by the core client in the player container; `config.watermark.text` is the fallback when the lease has none.
9
+ - Add watch-time analytics wiring: input `watchAnalytics` (`NsgWatchAnalyticsInput`, the core `AnalyticsClientOptions` without `video`/`onError`) and output `watchAnalyticsError`. The final heartbeat is sent on destroy.
10
+ - Peer range is now `@codenkay/video-nsgplayer-core@^5.3.0`. `streaming.nativeSessionMode`, `streaming.onNativeAuthUpdate`, and `streaming.useAppexHlsProfile` already pass through `config.streaming`. Control chrome is not part of this package.
11
+
3
12
  ## 5.0.0
4
13
 
5
14
  ### Minor Changes
package/README.md CHANGED
@@ -29,7 +29,22 @@ import { NsgVideoPlayerComponent } from "@codenkay/video-nsgplayer-angular";
29
29
  export class MyPage {}
30
30
  ```
31
31
 
32
- Requires Angular 17+, `rxjs` ^7, and `hls.js`. Same `PlayerConfig` shape as the React package.
32
+ Requires Angular 17+, `rxjs` ^7, and `hls.js`. Same `PlayerConfig` shape as the React package. Requires core **5.3.0** or newer. Settings and listen-audio are React-only.
33
+
34
+ ## Student lease and watch analytics
35
+
36
+ ```html
37
+ <nsg-video-player
38
+ [videoId]="videoId"
39
+ [lease]="{ baseUrl: 'https://playback.example.com', userId: 'student-1', authorizationToken: studentToken }"
40
+ [watchAnalytics]="{ origin, videoKey, playbackToken, deviceId }"
41
+ (leaseStarted)="onLease($event)"
42
+ (leaseError)="onLeaseError($event)"
43
+ (leasePreparing)="preparing = $event">
44
+ </nsg-video-player>
45
+ ```
46
+
47
+ The lease releases on destroy, `ended`, and `pagehide`. `leaseError` carries `code` (`PLATFORM_IN_USE`, `PLAYBACK_NOT_READY`) and `activePlatform`. The lease watermark overrides `config.watermark.text`, which is the fallback.
33
48
 
34
49
  ## Samples
35
50
 
package/dist/README.md CHANGED
@@ -29,7 +29,22 @@ import { NsgVideoPlayerComponent } from "@codenkay/video-nsgplayer-angular";
29
29
  export class MyPage {}
30
30
  ```
31
31
 
32
- Requires Angular 17+, `rxjs` ^7, and `hls.js`. Same `PlayerConfig` shape as the React package.
32
+ Requires Angular 17+, `rxjs` ^7, and `hls.js`. Same `PlayerConfig` shape as the React package. Requires core **5.3.0** or newer. Settings and listen-audio are React-only.
33
+
34
+ ## Student lease and watch analytics
35
+
36
+ ```html
37
+ <nsg-video-player
38
+ [videoId]="videoId"
39
+ [lease]="{ baseUrl: 'https://playback.example.com', userId: 'student-1', authorizationToken: studentToken }"
40
+ [watchAnalytics]="{ origin, videoKey, playbackToken, deviceId }"
41
+ (leaseStarted)="onLease($event)"
42
+ (leaseError)="onLeaseError($event)"
43
+ (leasePreparing)="preparing = $event">
44
+ </nsg-video-player>
45
+ ```
46
+
47
+ The lease releases on destroy, `ended`, and `pagehide`. `leaseError` carries `code` (`PLATFORM_IN_USE`, `PLAYBACK_NOT_READY`) and `activePlatform`. The lease watermark overrides `config.watermark.text`, which is the fallback.
33
48
 
34
49
  ## Samples
35
50
 
@@ -1,7 +1,15 @@
1
1
  import * as i0 from '@angular/core';
2
2
  import { output, Input, ViewChild, Component } from '@angular/core';
3
- import { mergePlayerConfig, createVideoPlayer, themeToCssVars } from '@codenkay/video-nsgplayer-core';
3
+ import { StudentLeaseError, mergePlayerConfig, StudentLeaseClient, AnalyticsClient, createVideoPlayer, themeToCssVars } from '@codenkay/video-nsgplayer-core';
4
4
 
5
+ const PLAYBACK_CANCELLED = "Playback request cancelled";
6
+ function toLeaseError(error) {
7
+ if (error instanceof StudentLeaseError)
8
+ return error;
9
+ return new StudentLeaseError(error instanceof Error
10
+ ? error.message
11
+ : "Student playback authorization unavailable.");
12
+ }
5
13
  class NsgVideoPlayerComponent {
6
14
  videoRef;
7
15
  containerRef;
@@ -11,16 +19,47 @@ class NsgVideoPlayerComponent {
11
19
  sourceUrl;
12
20
  config;
13
21
  analytics;
22
+ /**
23
+ * Student lease (online institutions). When set, the component acquires a
24
+ * lease for `videoId`, heartbeats, and releases on destroy, `ended`, and
25
+ * `pagehide`. A token-only change updates the live client without a new lease.
26
+ */
27
+ lease;
28
+ leaseMediaType = "video";
29
+ /**
30
+ * Let the lease client draw its intermittent watermark in the player
31
+ * container. The lease text wins; `config.watermark.text` is the fallback.
32
+ */
33
+ leaseDomWatermark = true;
34
+ /** Watch-time analytics. Starts once set; restarts when `videoId` changes. */
35
+ watchAnalytics;
14
36
  ready = output();
15
37
  error = output();
16
38
  play = output();
17
39
  pause = output();
18
40
  autherror = output();
41
+ /** `/student/playback` data once a lease is held (map it to `playback`). */
42
+ leaseStarted = output();
43
+ /**
44
+ * Lease failure: acquire or heartbeat. Check `code` for `PLATFORM_IN_USE`
45
+ * (`activePlatform`) and `PLAYBACK_NOT_READY`.
46
+ */
47
+ leaseError = output();
48
+ /** True while `PLAYBACK_NOT_READY` is being retried, false afterwards. */
49
+ leasePreparing = output();
50
+ /** Effective watermark text (lease text or static fallback), or null. */
51
+ leaseWatermark = output();
52
+ watchAnalyticsError = output();
19
53
  player = null;
20
54
  viewReady = false;
55
+ leaseClient = null;
56
+ leaseRun = 0;
57
+ analyticsClient = null;
21
58
  ngAfterViewInit() {
22
59
  this.viewReady = true;
23
60
  this.recreate();
61
+ this.setupLease();
62
+ this.setupAnalytics();
24
63
  }
25
64
  ngOnChanges(changes) {
26
65
  if (!this.viewReady)
@@ -36,14 +75,131 @@ class NsgVideoPlayerComponent {
36
75
  this.player.updateConfig(this.config);
37
76
  this.applyTheme();
38
77
  }
78
+ const leaseChange = changes["lease"];
79
+ if (leaseChange || changes["leaseDomWatermark"]) {
80
+ if (this.canUpdateLeaseToken(changes)) {
81
+ this.leaseClient?.updateAuthorizationToken(this.lease.authorizationToken);
82
+ }
83
+ else {
84
+ this.setupLease();
85
+ }
86
+ }
87
+ else if (changes["videoId"] || changes["leaseMediaType"]) {
88
+ void this.startLease();
89
+ }
90
+ if (changes["watchAnalytics"] || changes["videoId"]) {
91
+ this.setupAnalytics();
92
+ }
39
93
  }
40
94
  ngOnDestroy() {
95
+ this.leaseRun += 1;
96
+ const lease = this.leaseClient;
97
+ this.leaseClient = null;
98
+ void lease?.close();
99
+ const analytics = this.analyticsClient;
100
+ this.analyticsClient = null;
101
+ void analytics?.destroy();
41
102
  this.player?.destroy();
42
103
  this.player = null;
43
104
  }
44
105
  getPlayer() {
45
106
  return this.player;
46
107
  }
108
+ /** Token-only renewal of the same lease identity keeps the client. */
109
+ canUpdateLeaseToken(changes) {
110
+ if (changes["leaseDomWatermark"] || !this.leaseClient)
111
+ return false;
112
+ const change = changes["lease"];
113
+ const prev = change?.previousValue;
114
+ const next = this.lease;
115
+ return Boolean(prev &&
116
+ next &&
117
+ prev.baseUrl === next.baseUrl &&
118
+ prev.userId === next.userId &&
119
+ (prev.platform ?? "web") === (next.platform ?? "web") &&
120
+ prev.watermarkText === next.watermarkText);
121
+ }
122
+ setupLease() {
123
+ this.leaseRun += 1;
124
+ const previous = this.leaseClient;
125
+ this.leaseClient = null;
126
+ void previous?.close();
127
+ const video = this.videoRef?.nativeElement;
128
+ const config = this.lease;
129
+ if (!video || !config)
130
+ return;
131
+ const staticText = mergePlayerConfig(this.config).watermark.text?.trim();
132
+ try {
133
+ this.leaseClient = new StudentLeaseClient(video, {
134
+ ...config,
135
+ watermarkText: config.watermarkText ?? (staticText || undefined),
136
+ }, {
137
+ watermarkContainer: this.leaseDomWatermark
138
+ ? this.containerRef?.nativeElement
139
+ : null,
140
+ sleep: (ms) => {
141
+ this.leasePreparing.emit(true);
142
+ return new Promise((resolve) => setTimeout(resolve, ms));
143
+ },
144
+ onError: (error) => {
145
+ this.leaseRun += 1;
146
+ this.leasePreparing.emit(false);
147
+ this.leaseError.emit(error);
148
+ },
149
+ });
150
+ }
151
+ catch (error) {
152
+ this.leaseError.emit(toLeaseError(error));
153
+ return;
154
+ }
155
+ void this.startLease();
156
+ }
157
+ async startLease() {
158
+ const client = this.leaseClient;
159
+ const videoId = this.videoId;
160
+ if (!client || !videoId)
161
+ return;
162
+ const run = ++this.leaseRun;
163
+ try {
164
+ const data = await client.start(videoId, this.leaseMediaType);
165
+ if (run !== this.leaseRun)
166
+ return;
167
+ this.leasePreparing.emit(false);
168
+ const leaseText = data.student_session.watermark_text?.trim();
169
+ const staticText = mergePlayerConfig(this.config).watermark.text?.trim();
170
+ const text = leaseText || staticText || null;
171
+ // The API may omit watermark text; keep the static config as fallback.
172
+ if (!leaseText && staticText)
173
+ client.scheduleWatermark(staticText);
174
+ this.leaseWatermark.emit(text);
175
+ this.leaseStarted.emit(data);
176
+ }
177
+ catch (error) {
178
+ if (run !== this.leaseRun)
179
+ return;
180
+ const leaseError = toLeaseError(error);
181
+ if (leaseError.message === PLAYBACK_CANCELLED)
182
+ return;
183
+ this.leasePreparing.emit(false);
184
+ this.leaseError.emit(leaseError);
185
+ }
186
+ }
187
+ setupAnalytics() {
188
+ const previous = this.analyticsClient;
189
+ this.analyticsClient = null;
190
+ void previous?.destroy();
191
+ const video = this.videoRef?.nativeElement;
192
+ const options = this.watchAnalytics;
193
+ if (!video || !options)
194
+ return;
195
+ const client = new AnalyticsClient({
196
+ ...options,
197
+ video,
198
+ onError: (error) => this.watchAnalyticsError.emit(error),
199
+ });
200
+ this.analyticsClient = client;
201
+ void client.start();
202
+ }
47
203
  recreate() {
48
204
  this.player?.destroy();
49
205
  const video = this.videoRef?.nativeElement;
@@ -84,7 +240,7 @@ class NsgVideoPlayerComponent {
84
240
  }
85
241
  }
86
242
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: NsgVideoPlayerComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
87
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.25", type: NsgVideoPlayerComponent, isStandalone: true, selector: "nsg-video-player", inputs: { videoId: "videoId", auth: "auth", playback: "playback", sourceUrl: "sourceUrl", config: "config", analytics: "analytics" }, outputs: { ready: "ready", error: "error", play: "play", pause: "pause", autherror: "autherror" }, viewQueries: [{ propertyName: "videoRef", first: true, predicate: ["video"], descendants: true, static: true }, { propertyName: "containerRef", first: true, predicate: ["container"], descendants: true, static: true }], usesOnChanges: true, ngImport: i0, template: `
243
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.25", type: NsgVideoPlayerComponent, isStandalone: true, selector: "nsg-video-player", inputs: { videoId: "videoId", auth: "auth", playback: "playback", sourceUrl: "sourceUrl", config: "config", analytics: "analytics", lease: "lease", leaseMediaType: "leaseMediaType", leaseDomWatermark: "leaseDomWatermark", watchAnalytics: "watchAnalytics" }, outputs: { ready: "ready", error: "error", play: "play", pause: "pause", autherror: "autherror", leaseStarted: "leaseStarted", leaseError: "leaseError", leasePreparing: "leasePreparing", leaseWatermark: "leaseWatermark", watchAnalyticsError: "watchAnalyticsError" }, viewQueries: [{ propertyName: "videoRef", first: true, predicate: ["video"], descendants: true, static: true }, { propertyName: "containerRef", first: true, predicate: ["container"], descendants: true, static: true }], usesOnChanges: true, ngImport: i0, template: `
88
244
  <div
89
245
  #container
90
246
  data-player-theme
@@ -131,6 +287,14 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImpo
131
287
  type: Input
132
288
  }], analytics: [{
133
289
  type: Input
290
+ }], lease: [{
291
+ type: Input
292
+ }], leaseMediaType: [{
293
+ type: Input
294
+ }], leaseDomWatermark: [{
295
+ type: Input
296
+ }], watchAnalytics: [{
297
+ type: Input
134
298
  }] } });
135
299
 
136
300
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"codenkay-video-nsgplayer-angular.mjs","sources":["../../src/lib/nsg-video-player.component.ts","../../src/codenkay-video-nsgplayer-angular.ts"],"sourcesContent":["import {\n AfterViewInit,\n Component,\n ElementRef,\n Input,\n OnChanges,\n OnDestroy,\n SimpleChanges,\n ViewChild,\n output,\n} from \"@angular/core\";\nimport {\n createVideoPlayer,\n mergePlayerConfig,\n themeToCssVars,\n type AnalyticsConfig,\n type AuthConfig,\n type PlaybackCredentialConfig,\n type VideoPlayer,\n} from \"@codenkay/video-nsgplayer-core\";\n\n@Component({\n selector: \"nsg-video-player\",\n standalone: true,\n template: `\n <div\n #container\n data-player-theme\n [style.width]=\"'100%'\"\n [style.position]=\"'relative'\"\n [style.background]=\"'#000'\"\n >\n <video #video playsinline style=\"width:100%;display:block\"></video>\n </div>\n `,\n})\nexport class NsgVideoPlayerComponent\n implements AfterViewInit, OnChanges, OnDestroy\n{\n @ViewChild(\"video\", { static: true })\n videoRef!: ElementRef<HTMLVideoElement>;\n\n @ViewChild(\"container\", { static: true })\n containerRef!: ElementRef<HTMLDivElement>;\n\n @Input() videoId?: string;\n @Input() auth?: AuthConfig;\n @Input() playback?: PlaybackCredentialConfig;\n @Input() sourceUrl?: string;\n @Input() config?: Parameters<typeof mergePlayerConfig>[0];\n @Input() analytics?: AnalyticsConfig;\n\n readonly ready = output<void>();\n readonly error = output<{ code: string; message: string; fatal: boolean }>();\n readonly play = output<void>();\n readonly pause = output<void>();\n readonly autherror = output<{ message: string; retryable: boolean }>();\n\n private player: VideoPlayer | null = null;\n private viewReady = false;\n\n ngAfterViewInit(): void {\n this.viewReady = true;\n this.recreate();\n }\n\n ngOnChanges(changes: SimpleChanges): void {\n if (!this.viewReady) return;\n if (\n changes[\"videoId\"] ||\n changes[\"sourceUrl\"] ||\n changes[\"auth\"] ||\n changes[\"playback\"] ||\n changes[\"analytics\"]\n ) {\n this.recreate();\n } else if (changes[\"config\"] && this.player) {\n this.player.updateConfig(this.config);\n this.applyTheme();\n }\n }\n\n ngOnDestroy(): void {\n this.player?.destroy();\n this.player = null;\n }\n\n getPlayer(): VideoPlayer | null {\n return this.player;\n }\n\n private recreate(): void {\n this.player?.destroy();\n const video = this.videoRef?.nativeElement;\n if (!video) return;\n\n const resolved = mergePlayerConfig(this.config);\n this.player = createVideoPlayer({\n videoId: this.videoId,\n mount: video,\n auth: this.auth,\n playback: this.playback,\n sourceUrl: this.sourceUrl,\n player: resolved.player,\n controls: resolved.controls,\n theme: resolved.theme,\n watermark: resolved.watermark,\n streaming: resolved.streaming,\n logging: resolved.logging,\n debug: resolved.debug,\n analytics: this.analytics,\n accessibility: resolved.accessibility,\n });\n\n this.player.on(\"ready\", () => this.ready.emit());\n this.player.on(\"error\", (e) => this.error.emit(e));\n this.player.on(\"play\", () => this.play.emit());\n this.player.on(\"pause\", () => this.pause.emit());\n this.player.on(\"autherror\", (e) => this.autherror.emit(e));\n this.applyTheme();\n }\n\n private applyTheme(): void {\n const resolved = mergePlayerConfig(this.config);\n const vars = themeToCssVars(resolved.theme);\n const el = this.containerRef?.nativeElement;\n if (!el) return;\n for (const [key, value] of Object.entries(vars)) {\n el.style.setProperty(key, value);\n }\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;MAoCa,uBAAuB,CAAA;AAIlC,IAAA,QAAQ;AAGR,IAAA,YAAY;AAEH,IAAA,OAAO;AACP,IAAA,IAAI;AACJ,IAAA,QAAQ;AACR,IAAA,SAAS;AACT,IAAA,MAAM;AACN,IAAA,SAAS;IAET,KAAK,GAAG,MAAM,EAAQ;IACtB,KAAK,GAAG,MAAM,EAAqD;IACnE,IAAI,GAAG,MAAM,EAAQ;IACrB,KAAK,GAAG,MAAM,EAAQ;IACtB,S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AEU,uBAAuB,EAAA,UAAA,EAAA,CAAA;kBAfnC,SAAS;AAAC,YAAA,IAAA,EAAA,CAAA;AACT,oBAAA,QAAQ,EAAE,kBAAkB;AAC5B,oBAAA,UAAU,EAAE,IAAI;AAChB,oBAAA,QAAQ,EAAE;;;;;;;;;;AAUT,EAAA,CAAA;AACF,iBAAA;8BAKC,QAAQ,EAAA,CAAA;sBADP,SAAS;AAAC,gBAAA,IAAA,EAAA,CAAA,OAAO,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE;gBAIpC,YAAY,EAAA,CAAA;sBADX,SAAS;AAAC,gBAAA,IAAA,EAAA,CAAA,WAAW,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE;gBAG/B,OAAO,EAAA,CAAA;sBAAf;gBACQ,IAAI,EAAA,CAAA;sBAAZ;gBACQ,QAAQ,EAAA,CAAA;sBAAhB;gBACQ,SAAS,EAAA,CAAA;sBAAjB;gBACQ,MAAM,EAAA,CAAA;sBAAd;gBACQ,SAAS,EAAA,CAAA;sBAAjB;;;AClDH;;AAEG;;"}
1
+ {"version":3,"file":"codenkay-video-nsgplayer-angular.mjs","sources":["../../src/lib/nsg-video-player.component.ts","../../src/codenkay-video-nsgplayer-angular.ts"],"sourcesContent":["import {\n AfterViewInit,\n Component,\n ElementRef,\n Input,\n OnChanges,\n OnDestroy,\n SimpleChanges,\n ViewChild,\n output,\n} from \"@angular/core\";\nimport {\n AnalyticsClient,\n StudentLeaseClient,\n StudentLeaseError,\n createVideoPlayer,\n mergePlayerConfig,\n themeToCssVars,\n type AnalyticsClientOptions,\n type AnalyticsConfig,\n type AuthConfig,\n type PlaybackCredentialConfig,\n type StudentLeaseConfig,\n type StudentMediaType,\n type StudentPlaybackData,\n type VideoPlayer,\n} from \"@codenkay/video-nsgplayer-core\";\n\n/**\n * Watch-time analytics wiring (`AnalyticsClient`). The component supplies the\n * `<video>` and `onError`; the host provides the rest.\n */\nexport type NsgWatchAnalyticsInput = Omit<\n AnalyticsClientOptions,\n \"video\" | \"onError\"\n>;\n\nconst PLAYBACK_CANCELLED = \"Playback request cancelled\";\n\nfunction toLeaseError(error: unknown): StudentLeaseError {\n if (error instanceof StudentLeaseError) return error;\n return new StudentLeaseError(\n error instanceof Error\n ? error.message\n : \"Student playback authorization unavailable.\",\n );\n}\n\n@Component({\n selector: \"nsg-video-player\",\n standalone: true,\n template: `\n <div\n #container\n data-player-theme\n [style.width]=\"'100%'\"\n [style.position]=\"'relative'\"\n [style.background]=\"'#000'\"\n >\n <video #video playsinline style=\"width:100%;display:block\"></video>\n </div>\n `,\n})\nexport class NsgVideoPlayerComponent\n implements AfterViewInit, OnChanges, OnDestroy\n{\n @ViewChild(\"video\", { static: true })\n videoRef!: ElementRef<HTMLVideoElement>;\n\n @ViewChild(\"container\", { static: true })\n containerRef!: ElementRef<HTMLDivElement>;\n\n @Input() videoId?: string;\n @Input() auth?: AuthConfig;\n @Input() playback?: PlaybackCredentialConfig;\n @Input() sourceUrl?: string;\n @Input() config?: Parameters<typeof mergePlayerConfig>[0];\n @Input() analytics?: AnalyticsConfig;\n /**\n * Student lease (online institutions). When set, the component acquires a\n * lease for `videoId`, heartbeats, and releases on destroy, `ended`, and\n * `pagehide`. A token-only change updates the live client without a new lease.\n */\n @Input() lease?: StudentLeaseConfig;\n @Input() leaseMediaType: StudentMediaType = \"video\";\n /**\n * Let the lease client draw its intermittent watermark in the player\n * container. The lease text wins; `config.watermark.text` is the fallback.\n */\n @Input() leaseDomWatermark = true;\n /** Watch-time analytics. Starts once set; restarts when `videoId` changes. */\n @Input() watchAnalytics?: NsgWatchAnalyticsInput;\n\n readonly ready = output<void>();\n readonly error = output<{ code: string; message: string; fatal: boolean }>();\n readonly play = output<void>();\n readonly pause = output<void>();\n readonly autherror = output<{ message: string; retryable: boolean }>();\n /** `/student/playback` data once a lease is held (map it to `playback`). */\n readonly leaseStarted = output<StudentPlaybackData>();\n /**\n * Lease failure: acquire or heartbeat. Check `code` for `PLATFORM_IN_USE`\n * (`activePlatform`) and `PLAYBACK_NOT_READY`.\n */\n readonly leaseError = output<StudentLeaseError>();\n /** True while `PLAYBACK_NOT_READY` is being retried, false afterwards. */\n readonly leasePreparing = output<boolean>();\n /** Effective watermark text (lease text or static fallback), or null. */\n readonly leaseWatermark = output<string | null>();\n readonly watchAnalyticsError = output<unknown>();\n\n private player: VideoPlayer | null = null;\n private viewReady = false;\n private leaseClient: StudentLeaseClient | null = null;\n private leaseRun = 0;\n private analyticsClient: AnalyticsClient | null = null;\n\n ngAfterViewInit(): void {\n this.viewReady = true;\n this.recreate();\n this.setupLease();\n this.setupAnalytics();\n }\n\n ngOnChanges(changes: SimpleChanges): void {\n if (!this.viewReady) return;\n if (\n changes[\"videoId\"] ||\n changes[\"sourceUrl\"] ||\n changes[\"auth\"] ||\n changes[\"playback\"] ||\n changes[\"analytics\"]\n ) {\n this.recreate();\n } else if (changes[\"config\"] && this.player) {\n this.player.updateConfig(this.config);\n this.applyTheme();\n }\n\n const leaseChange = changes[\"lease\"];\n if (leaseChange || changes[\"leaseDomWatermark\"]) {\n if (this.canUpdateLeaseToken(changes)) {\n this.leaseClient?.updateAuthorizationToken(\n this.lease!.authorizationToken,\n );\n } else {\n this.setupLease();\n }\n } else if (changes[\"videoId\"] || changes[\"leaseMediaType\"]) {\n void this.startLease();\n }\n\n if (changes[\"watchAnalytics\"] || changes[\"videoId\"]) {\n this.setupAnalytics();\n }\n }\n\n ngOnDestroy(): void {\n this.leaseRun += 1;\n const lease = this.leaseClient;\n this.leaseClient = null;\n void lease?.close();\n const analytics = this.analyticsClient;\n this.analyticsClient = null;\n void analytics?.destroy();\n this.player?.destroy();\n this.player = null;\n }\n\n getPlayer(): VideoPlayer | null {\n return this.player;\n }\n\n /** Token-only renewal of the same lease identity keeps the client. */\n private canUpdateLeaseToken(changes: SimpleChanges): boolean {\n if (changes[\"leaseDomWatermark\"] || !this.leaseClient) return false;\n const change = changes[\"lease\"];\n const prev = change?.previousValue as StudentLeaseConfig | undefined;\n const next = this.lease;\n return Boolean(\n prev &&\n next &&\n prev.baseUrl === next.baseUrl &&\n prev.userId === next.userId &&\n (prev.platform ?? \"web\") === (next.platform ?? \"web\") &&\n prev.watermarkText === next.watermarkText,\n );\n }\n\n private setupLease(): void {\n this.leaseRun += 1;\n const previous = this.leaseClient;\n this.leaseClient = null;\n void previous?.close();\n\n const video = this.videoRef?.nativeElement;\n const config = this.lease;\n if (!video || !config) return;\n\n const staticText = mergePlayerConfig(this.config).watermark.text?.trim();\n try {\n this.leaseClient = new StudentLeaseClient(\n video,\n {\n ...config,\n watermarkText: config.watermarkText ?? (staticText || undefined),\n },\n {\n watermarkContainer: this.leaseDomWatermark\n ? this.containerRef?.nativeElement\n : null,\n sleep: (ms) => {\n this.leasePreparing.emit(true);\n return new Promise<void>((resolve) => setTimeout(resolve, ms));\n },\n onError: (error) => {\n this.leaseRun += 1;\n this.leasePreparing.emit(false);\n this.leaseError.emit(error);\n },\n },\n );\n } catch (error) {\n this.leaseError.emit(toLeaseError(error));\n return;\n }\n void this.startLease();\n }\n\n private async startLease(): Promise<void> {\n const client = this.leaseClient;\n const videoId = this.videoId;\n if (!client || !videoId) return;\n const run = ++this.leaseRun;\n try {\n const data = await client.start(videoId, this.leaseMediaType);\n if (run !== this.leaseRun) return;\n this.leasePreparing.emit(false);\n const leaseText = data.student_session.watermark_text?.trim();\n const staticText = mergePlayerConfig(this.config).watermark.text?.trim();\n const text = leaseText || staticText || null;\n // The API may omit watermark text; keep the static config as fallback.\n if (!leaseText && staticText) client.scheduleWatermark(staticText);\n this.leaseWatermark.emit(text);\n this.leaseStarted.emit(data);\n } catch (error) {\n if (run !== this.leaseRun) return;\n const leaseError = toLeaseError(error);\n if (leaseError.message === PLAYBACK_CANCELLED) return;\n this.leasePreparing.emit(false);\n this.leaseError.emit(leaseError);\n }\n }\n\n private setupAnalytics(): void {\n const previous = this.analyticsClient;\n this.analyticsClient = null;\n void previous?.destroy();\n\n const video = this.videoRef?.nativeElement;\n const options = this.watchAnalytics;\n if (!video || !options) return;\n\n const client = new AnalyticsClient({\n ...options,\n video,\n onError: (error) => this.watchAnalyticsError.emit(error),\n });\n this.analyticsClient = client;\n void client.start();\n }\n\n private recreate(): void {\n this.player?.destroy();\n const video = this.videoRef?.nativeElement;\n if (!video) return;\n\n const resolved = mergePlayerConfig(this.config);\n this.player = createVideoPlayer({\n videoId: this.videoId,\n mount: video,\n auth: this.auth,\n playback: this.playback,\n sourceUrl: this.sourceUrl,\n player: resolved.player,\n controls: resolved.controls,\n theme: resolved.theme,\n watermark: resolved.watermark,\n streaming: resolved.streaming,\n logging: resolved.logging,\n debug: resolved.debug,\n analytics: this.analytics,\n accessibility: resolved.accessibility,\n });\n\n this.player.on(\"ready\", () => this.ready.emit());\n this.player.on(\"error\", (e) => this.error.emit(e));\n this.player.on(\"play\", () => this.play.emit());\n this.player.on(\"pause\", () => this.pause.emit());\n this.player.on(\"autherror\", (e) => this.autherror.emit(e));\n this.applyTheme();\n }\n\n private applyTheme(): void {\n const resolved = mergePlayerConfig(this.config);\n const vars = themeToCssVars(resolved.theme);\n const el = this.containerRef?.nativeElement;\n if (!el) return;\n for (const [key, value] of Object.entries(vars)) {\n el.style.setProperty(key, value);\n }\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;AAqCA,MAAM,kBAAkB,GAAG,4BAA4B;AAEvD,SAAS,YAAY,CAAC,KAAc,EAAA;IAClC,IAAI,KAAK,YAAY,iBAAiB;AAAE,QAAA,OAAO,KAAK;AACpD,IAAA,OAAO,IAAI,iBAAiB,CAC1B,KAAK,YAAY;UACb,KAAK,CAAC;UACN,6CAA6C,CAClD;AACH;MAiBa,uBAAuB,CAAA;AAIlC,IAAA,QAAQ;AAGR,IAAA,YAAY;AAEH,IAAA,OAAO;AACP,IAAA,IAAI;AACJ,IAAA,QAAQ;AACR,IAAA,SAAS;AACT,IAAA,MAAM;AACN,IAAA,SAAS;AAClB;;;;AAIG;AACM,IA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gBAKQ,iBAAiB,EAAA,CAAA;sBAAzB;gBAEQ,cAAc,EAAA,CAAA;sBAAtB;;;AC3FH;;AAEG;;"}
package/dist/index.d.ts CHANGED
@@ -1 +1 @@
1
- export { NsgVideoPlayerComponent } from "./lib/nsg-video-player.component";
1
+ export { NsgVideoPlayerComponent, type NsgWatchAnalyticsInput, } from "./lib/nsg-video-player.component";
@@ -1,6 +1,11 @@
1
1
  import { AfterViewInit, ElementRef, OnChanges, OnDestroy, SimpleChanges } from "@angular/core";
2
- import { mergePlayerConfig, type AnalyticsConfig, type AuthConfig, type PlaybackCredentialConfig, type VideoPlayer } from "@codenkay/video-nsgplayer-core";
2
+ import { StudentLeaseError, mergePlayerConfig, type AnalyticsClientOptions, type AnalyticsConfig, type AuthConfig, type PlaybackCredentialConfig, type StudentLeaseConfig, type StudentMediaType, type StudentPlaybackData, type VideoPlayer } from "@codenkay/video-nsgplayer-core";
3
3
  import * as i0 from "@angular/core";
4
+ /**
5
+ * Watch-time analytics wiring (`AnalyticsClient`). The component supplies the
6
+ * `<video>` and `onError`; the host provides the rest.
7
+ */
8
+ export type NsgWatchAnalyticsInput = Omit<AnalyticsClientOptions, "video" | "onError">;
4
9
  export declare class NsgVideoPlayerComponent implements AfterViewInit, OnChanges, OnDestroy {
5
10
  videoRef: ElementRef<HTMLVideoElement>;
6
11
  containerRef: ElementRef<HTMLDivElement>;
@@ -10,6 +15,20 @@ export declare class NsgVideoPlayerComponent implements AfterViewInit, OnChanges
10
15
  sourceUrl?: string;
11
16
  config?: Parameters<typeof mergePlayerConfig>[0];
12
17
  analytics?: AnalyticsConfig;
18
+ /**
19
+ * Student lease (online institutions). When set, the component acquires a
20
+ * lease for `videoId`, heartbeats, and releases on destroy, `ended`, and
21
+ * `pagehide`. A token-only change updates the live client without a new lease.
22
+ */
23
+ lease?: StudentLeaseConfig;
24
+ leaseMediaType: StudentMediaType;
25
+ /**
26
+ * Let the lease client draw its intermittent watermark in the player
27
+ * container. The lease text wins; `config.watermark.text` is the fallback.
28
+ */
29
+ leaseDomWatermark: boolean;
30
+ /** Watch-time analytics. Starts once set; restarts when `videoId` changes. */
31
+ watchAnalytics?: NsgWatchAnalyticsInput;
13
32
  readonly ready: import("@angular/core").OutputEmitterRef<void>;
14
33
  readonly error: import("@angular/core").OutputEmitterRef<{
15
34
  code: string;
@@ -22,14 +41,34 @@ export declare class NsgVideoPlayerComponent implements AfterViewInit, OnChanges
22
41
  message: string;
23
42
  retryable: boolean;
24
43
  }>;
44
+ /** `/student/playback` data once a lease is held (map it to `playback`). */
45
+ readonly leaseStarted: import("@angular/core").OutputEmitterRef<StudentPlaybackData>;
46
+ /**
47
+ * Lease failure: acquire or heartbeat. Check `code` for `PLATFORM_IN_USE`
48
+ * (`activePlatform`) and `PLAYBACK_NOT_READY`.
49
+ */
50
+ readonly leaseError: import("@angular/core").OutputEmitterRef<StudentLeaseError>;
51
+ /** True while `PLAYBACK_NOT_READY` is being retried, false afterwards. */
52
+ readonly leasePreparing: import("@angular/core").OutputEmitterRef<boolean>;
53
+ /** Effective watermark text (lease text or static fallback), or null. */
54
+ readonly leaseWatermark: import("@angular/core").OutputEmitterRef<string>;
55
+ readonly watchAnalyticsError: import("@angular/core").OutputEmitterRef<unknown>;
25
56
  private player;
26
57
  private viewReady;
58
+ private leaseClient;
59
+ private leaseRun;
60
+ private analyticsClient;
27
61
  ngAfterViewInit(): void;
28
62
  ngOnChanges(changes: SimpleChanges): void;
29
63
  ngOnDestroy(): void;
30
64
  getPlayer(): VideoPlayer | null;
65
+ /** Token-only renewal of the same lease identity keeps the client. */
66
+ private canUpdateLeaseToken;
67
+ private setupLease;
68
+ private startLease;
69
+ private setupAnalytics;
31
70
  private recreate;
32
71
  private applyTheme;
33
72
  static ɵfac: i0.ɵɵFactoryDeclaration<NsgVideoPlayerComponent, never>;
34
- static ɵcmp: i0.ɵɵComponentDeclaration<NsgVideoPlayerComponent, "nsg-video-player", never, { "videoId": { "alias": "videoId"; "required": false; }; "auth": { "alias": "auth"; "required": false; }; "playback": { "alias": "playback"; "required": false; }; "sourceUrl": { "alias": "sourceUrl"; "required": false; }; "config": { "alias": "config"; "required": false; }; "analytics": { "alias": "analytics"; "required": false; }; }, { "ready": "ready"; "error": "error"; "play": "play"; "pause": "pause"; "autherror": "autherror"; }, never, never, true, never>;
73
+ static ɵcmp: i0.ɵɵComponentDeclaration<NsgVideoPlayerComponent, "nsg-video-player", never, { "videoId": { "alias": "videoId"; "required": false; }; "auth": { "alias": "auth"; "required": false; }; "playback": { "alias": "playback"; "required": false; }; "sourceUrl": { "alias": "sourceUrl"; "required": false; }; "config": { "alias": "config"; "required": false; }; "analytics": { "alias": "analytics"; "required": false; }; "lease": { "alias": "lease"; "required": false; }; "leaseMediaType": { "alias": "leaseMediaType"; "required": false; }; "leaseDomWatermark": { "alias": "leaseDomWatermark"; "required": false; }; "watchAnalytics": { "alias": "watchAnalytics"; "required": false; }; }, { "ready": "ready"; "error": "error"; "play": "play"; "pause": "pause"; "autherror": "autherror"; "leaseStarted": "leaseStarted"; "leaseError": "leaseError"; "leasePreparing": "leasePreparing"; "leaseWatermark": "leaseWatermark"; "watchAnalyticsError": "watchAnalyticsError"; }, never, never, true, never>;
35
74
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codenkay/video-nsgplayer-angular",
3
- "version": "5.0.0",
3
+ "version": "5.1.0",
4
4
  "description": "Angular bindings for NSG video player (headless)",
5
5
  "license": "MIT",
6
6
  "author": "NSG Player",
@@ -32,7 +32,7 @@
32
32
  "CHANGELOG.md"
33
33
  ],
34
34
  "peerDependencies": {
35
- "@codenkay/video-nsgplayer-core": "^5.0.0",
35
+ "@codenkay/video-nsgplayer-core": "^5.3.0",
36
36
  "@angular/core": ">=17",
37
37
  "@angular/common": ">=17",
38
38
  "rxjs": "^7.8.0"