Skip to content

Commit 621a7c9

Browse files
authored
Merge pull request #11 from taj54/main
docs: changelog updated version 0.0.2
2 parents 13ead8d + 3deb98a commit 621a7c9

File tree

5 files changed

+100
-51
lines changed

5 files changed

+100
-51
lines changed

.prettierrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
"trailingComma": "es5",
33
"tabWidth": 2,
44
"semi": true,
5-
"singleQuote": true
5+
"singleQuote": true,
6+
"endOfLine": "lf"
67
}

CHANGELOG.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
## [0.0.2] - 2025-08-10
6+
7+
### Style
8+
9+
- Configure prettier to use lf line endings
10+
11+
### Chore
12+
13+
- Support code lint and commit lint
14+
- Add test lint
15+
- Tsup config file confugured
16+
17+
### Test
18+
19+
- Fix test error
20+
21+
### Docs
22+
23+
- Add CONTRIBUTING.md guide
24+
- Add DEVELOPER.md guide
25+
- Update README.md with detailed project information
26+
- Add horizontal rule to README
27+
28+
### Features
29+
30+
- Migrate tsup configuration to tsup.config.ts
31+
- Add React wrapper and example
32+
- Update package metadata and dependencies
33+
- Setup project structure and CI workflows
34+
35+
### Bug Fixes
36+
37+
- Resolve race condition on initialization

examples/index.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import ReactDOM from 'react-dom/client';
3-
import { InteractiveVideo } from '../dist/index';
3+
import { InteractiveVideo } from '@interactive-video-labs/react';
44

55
const App = () => {
66
return (
@@ -13,6 +13,17 @@ const App = () => {
1313
onAnalyticsEvent={(event, payload) => {
1414
console.log('Analytics Event:', event, payload);
1515
}}
16+
cues={[
17+
{
18+
id: 'cue1',
19+
time: 2,
20+
payload: {
21+
type: 'quiz',
22+
question: 'What is the capital of France?',
23+
answers: ['Paris', 'London', 'Berlin', 'Madrid'],
24+
},
25+
},
26+
]}
1627
/>
1728
</div>
1829
</div>

src/index.tsx

Lines changed: 39 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -59,55 +59,35 @@ export const InteractiveVideo: React.FC<InteractiveVideoProps> = ({
5959
const uniqueIdRef = useRef<string>(generateUniqueId());
6060

6161
useEffect(() => {
62-
if (containerRef.current && !playerRef.current) {
63-
const playerConfig: PlayerConfig = {
64-
videoUrl,
65-
...restOptions,
66-
};
62+
if (!containerRef.current) return;
6763

68-
try {
69-
setTimeout(() => {
70-
if (containerRef.current) {
71-
const player = new IVLabsPlayer(uniqueIdRef.current, playerConfig);
72-
playerRef.current = player;
73-
74-
if (onAnalyticsEvent) {
75-
player.on('PLAYER_LOADED', (payload?: AnalyticsPayload) =>
76-
onAnalyticsEvent('PLAYER_LOADED', payload)
77-
);
78-
player.on('VIDEO_STARTED', (payload?: AnalyticsPayload) =>
79-
onAnalyticsEvent('VIDEO_STARTED', payload)
80-
);
81-
player.on('VIDEO_PAUSED', (payload?: AnalyticsPayload) =>
82-
onAnalyticsEvent('VIDEO_PAUSED', payload)
83-
);
84-
player.on('VIDEO_ENDED', (payload?: AnalyticsPayload) =>
85-
onAnalyticsEvent('VIDEO_ENDED', payload)
86-
);
87-
player.on('CUE_TRIGGERED', (payload?: AnalyticsPayload) =>
88-
onAnalyticsEvent('CUE_TRIGGERED', payload)
89-
);
90-
player.on('INTERACTION_COMPLETED', (payload?: AnalyticsPayload) =>
91-
onAnalyticsEvent('INTERACTION_COMPLETED', payload)
92-
);
93-
player.on('ERROR', (payload?: AnalyticsPayload) =>
94-
onAnalyticsEvent('ERROR', payload)
95-
);
96-
}
64+
const playerConfig: PlayerConfig = {
65+
videoUrl,
66+
...restOptions,
67+
};
9768

98-
if (cues) {
99-
player.loadCues(cues);
100-
}
69+
try {
70+
const player = new IVLabsPlayer(uniqueIdRef.current, playerConfig);
71+
playerRef.current = player;
10172

102-
if (translations) {
103-
const locale = restOptions.locale || 'en';
104-
player.loadTranslations(locale, translations);
105-
}
106-
}
107-
}, 0);
108-
} catch (error) {
109-
console.error('Error initializing IVLabsPlayer:', error);
73+
if (onAnalyticsEvent) {
74+
const events: AnalyticsEvent[] = [
75+
'PLAYER_LOADED',
76+
'VIDEO_STARTED',
77+
'VIDEO_PAUSED',
78+
'VIDEO_ENDED',
79+
'CUE_TRIGGERED',
80+
'INTERACTION_COMPLETED',
81+
'ERROR',
82+
];
83+
events.forEach((event) => {
84+
player.on(event, (payload?: AnalyticsPayload) =>
85+
onAnalyticsEvent(event, payload)
86+
);
87+
});
11088
}
89+
} catch (error) {
90+
console.error('Error initializing IVLabsPlayer:', error);
11191
}
11292

11393
return () => {
@@ -116,7 +96,20 @@ export const InteractiveVideo: React.FC<InteractiveVideoProps> = ({
11696
playerRef.current = null;
11797
}
11898
};
119-
}, [videoUrl, onAnalyticsEvent, cues, translations, restOptions]);
99+
}, [videoUrl, onAnalyticsEvent, restOptions]);
100+
101+
useEffect(() => {
102+
if (playerRef.current && cues) {
103+
playerRef.current.loadCues(cues);
104+
}
105+
}, [cues]);
106+
107+
useEffect(() => {
108+
if (playerRef.current && translations) {
109+
const locale = restOptions.locale || 'en';
110+
playerRef.current.loadTranslations(locale, translations);
111+
}
112+
}, [translations, restOptions.locale]);
120113

121114
return (
122115
<div

tsup.config.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
import { defineConfig } from 'tsup';
22
import pkg from './package.json';
33

4-
export default defineConfig({
4+
export default defineConfig((options) => ({
55
entry: ['src/index.tsx'],
66
format: ['esm', 'cjs'],
7+
outExtension({ format }) {
8+
return {
9+
js: `.${format === 'esm' ? 'mjs' : 'cjs'}`,
10+
};
11+
},
712
dts: true,
13+
watch: options.watch,
814
clean: true,
915
banner: {
1016
js: `/**
1117
* ${pkg.name} v${pkg.version}
1218
* Author: ${pkg.author}
19+
* @license MIT
1320
*/
14-
`,
21+
`,
1522
},
16-
});
23+
}));

0 commit comments

Comments
 (0)