1- import type { PlayerWith } from "@flowplayer/player" ;
1+ import type { PlayerWith , Player } from "@flowplayer/player" ;
2+ import flowplayer from "@flowplayer/player" ;
23
34type SampleRate = 1.0 | 0.1 | 0.001 ;
45
56const PACKAGE_NAME = "react-flowplayer" ;
6-
77type Behavior = "flowplayer-component-mounted" ;
88
99type UsageEventDetail = {
@@ -13,17 +13,34 @@ type UsageEventDetail = {
1313} ;
1414
1515type PlayerWithUsage = PlayerWith < {
16+ // internal API
1617 emit ( event : "flowplayer:feature" , detail : UsageEventDetail ) : void ;
18+ opts : Player [ "opts" ] & {
19+ metadata ?: {
20+ media_id : string ;
21+ stream_target_id : string ;
22+ } ;
23+ } ;
1724} > ;
1825
1926export function trackBehaviorUsage (
2027 player : PlayerWithUsage ,
2128 behavior : Behavior ,
2229 sample_rate : SampleRate = 1.0
2330) {
24- player . emit ( "flowplayer:feature" , {
25- feature_name : PACKAGE_NAME ,
26- behavior,
27- sample_rate,
31+ let reportedOnce = false ;
32+ player . on ( flowplayer . events . SOURCE , ( ) => {
33+ const hasMediaIdLike =
34+ typeof player . opts . metadata ?. media_id === "string" ||
35+ typeof player . opts . metadata ?. stream_target_id === "string" ;
36+
37+ if ( ! reportedOnce && hasMediaIdLike ) {
38+ player . emit ( "flowplayer:feature" , {
39+ feature_name : PACKAGE_NAME ,
40+ behavior,
41+ sample_rate,
42+ } ) ;
43+ reportedOnce = true ;
44+ }
2845 } ) ;
2946}
0 commit comments