@@ -71,8 +71,6 @@ const initialStats: StreamStats = {
7171 targetStats : { } ,
7272} ;
7373
74- const lastSamplesByGroup = new Map < string , { size : number ; time : number } > ( ) ;
75-
7674export const useStreamStore = create < StreamState > ( ( set , get ) => ( {
7775 isStreaming : false ,
7876 activeGroups : new Set ( ) ,
@@ -95,10 +93,6 @@ export const useStreamStore = create<StreamState>((set, get) => ({
9593 const activeGroups = new Set ( activeGroupIds ) ;
9694 const isStreaming = activeCount > 0 ;
9795
98- if ( ! isStreaming ) {
99- lastSamplesByGroup . clear ( ) ;
100- }
101-
10296 set ( {
10397 activeStreamCount : activeCount ,
10498 activeGroups,
@@ -163,19 +157,18 @@ export const useStreamStore = create<StreamState>((set, get) => ({
163157 set ( { globalStatus : 'connecting' , error : null } ) ;
164158
165159 try {
166- for ( const group of groups ) {
167- // Skip groups with no targets at all
168- if ( group . streamTargets . length === 0 ) {
169- continue ;
170- }
160+ const eligibleGroups = groups . filter ( ( group ) => group . streamTargets . length > 0 ) ;
161+ if ( eligibleGroups . length === 0 ) {
162+ throw new Error ( 'At least one stream target is required' ) ;
163+ }
171164
172- // Send all targets - backend will filter disabled ones
173- await api . stream . start ( group , incomingUrl ) ;
165+ await api . stream . startAll ( eligibleGroups , incomingUrl ) ;
174166
175- const activeGroups = new Set ( get ( ) . activeGroups ) ;
167+ const activeGroups = new Set ( get ( ) . activeGroups ) ;
168+ for ( const group of eligibleGroups ) {
176169 activeGroups . add ( group . id ) ;
177- set ( { activeGroups } ) ;
178170 }
171+ set ( { activeGroups } ) ;
179172
180173 set ( {
181174 isStreaming : true ,
@@ -191,7 +184,6 @@ export const useStreamStore = create<StreamState>((set, get) => ({
191184 stopAllGroups : async ( ) => {
192185 try {
193186 await api . stream . stopAll ( ) ;
194- lastSamplesByGroup . clear ( ) ;
195187 set ( {
196188 activeGroups : new Set ( ) ,
197189 isStreaming : false ,
@@ -265,23 +257,7 @@ export const useStreamStore = create<StreamState>((set, get) => ({
265257
266258 updateStats : ( groupId , ffmpegStats ) => {
267259 const currentGroupStats = get ( ) . groupStats ;
268- let bitrate = ffmpegStats . bitrate ;
269- const lastSample = lastSamplesByGroup . get ( groupId ) ;
270-
271- if (
272- lastSample &&
273- ffmpegStats . time > lastSample . time &&
274- ffmpegStats . size >= lastSample . size
275- ) {
276- const deltaBytes = ffmpegStats . size - lastSample . size ;
277- const deltaSeconds = ffmpegStats . time - lastSample . time ;
278- const instantaneousKbps = ( deltaBytes * 8 ) / 1000 / deltaSeconds ;
279- if ( Number . isFinite ( instantaneousKbps ) ) {
280- bitrate = instantaneousKbps ;
281- }
282- }
283-
284- lastSamplesByGroup . set ( groupId , { size : ffmpegStats . size , time : ffmpegStats . time } ) ;
260+ const bitrate = ffmpegStats . bitrate ;
285261
286262 // Update per-group stats
287263 const newGroupStats = {
@@ -327,7 +303,6 @@ export const useStreamStore = create<StreamState>((set, get) => ({
327303 } ,
328304
329305 setStreamEnded : ( groupId ) => {
330- lastSamplesByGroup . delete ( groupId ) ;
331306 const activeGroups = new Set ( get ( ) . activeGroups ) ;
332307 activeGroups . delete ( groupId ) ;
333308
@@ -356,7 +331,6 @@ export const useStreamStore = create<StreamState>((set, get) => ({
356331 } ,
357332
358333 setStreamError : ( groupId , error ) => {
359- lastSamplesByGroup . delete ( groupId ) ;
360334 const activeGroups = new Set ( get ( ) . activeGroups ) ;
361335 activeGroups . delete ( groupId ) ;
362336
@@ -394,7 +368,6 @@ export const useStreamStore = create<StreamState>((set, get) => ({
394368 setError : ( error ) => set ( { error } ) ,
395369
396370 reset : ( ) => {
397- lastSamplesByGroup . clear ( ) ;
398371 set ( {
399372 isStreaming : false ,
400373 activeGroups : new Set ( ) ,
0 commit comments