@@ -239,6 +239,27 @@ export class TwitchService
239239 return ;
240240 }
241241
242+ const channelInfo = goLiveSettings ?. platforms . twitch ;
243+
244+ // Resolve enhanced broadcasting before the stream key is written below. The key is only sent
245+ // to the display's OBS context when Twitch is not going out through restream, and that
246+ // depends on whether this stream is an enhanced broadcast — deciding afterwards means the
247+ // check answers for the previous stream instead of this one.
248+ if ( channelInfo ) {
249+ if ( this . streamingService . views . isLiveOutputEditingEnabled ) {
250+ await this . setupLiveOutputStream ( goLiveSettings ) ;
251+ } else if ( channelInfo . display === 'both' ) {
252+ await this . setupDualStream ( goLiveSettings ) ;
253+ } else {
254+ // Update enhanced broadcasting setting based on go live settings
255+ this . settingsService . setEnhancedBroadcasting ( channelInfo . isEnhancedBroadcasting ) ;
256+ }
257+ } else if ( this . streamingService . views . isTwitchDualStreamEnabled ) {
258+ // Failsafe to guarantee that enhanced broadcasting is enabled if dual streaming is active
259+
260+ await this . setupDualStream ( goLiveSettings ) ;
261+ }
262+
242263 if (
243264 this . streamSettingsService . protectedModeEnabled &&
244265 this . streamSettingsService . isSafeToModifyStreamKey ( )
@@ -265,34 +286,8 @@ export class TwitchService
265286 }
266287 }
267288
268- if ( goLiveSettings ) {
269- const channelInfo = goLiveSettings ?. platforms . twitch ;
270-
271- if ( channelInfo ) {
272- if ( channelInfo ?. display === 'both' ) {
273- try {
274- await this . setupDualStream ( goLiveSettings ) ;
275- } catch ( e : unknown ) {
276- console . error ( 'Error setting up dual stream:' , e ) ;
277- }
278- } else if ( this . streamingService . views . isLiveOutputEditingEnabled ) {
279- // When live output editing is enabled enhanced broadcasting won't work because it
280- // uses restream, which is incompatible with enhanced broadcasting.
281- this . settingsService . setEnhancedBroadcasting ( false ) ;
282- } else {
283- // Update enhanced broadcasting setting based on go live settings
284- this . settingsService . setEnhancedBroadcasting ( channelInfo . isEnhancedBroadcasting ) ;
285- }
286-
287- await this . putChannelInfo ( channelInfo ) ;
288- }
289- } else if ( this . streamingService . views . isTwitchDualStreamEnabled ) {
290- // Failsafe to guarantee that enhanced broadcasting is enabled if dual streaming is active
291- try {
292- await this . setupDualStream ( goLiveSettings ) ;
293- } catch ( e : unknown ) {
294- console . error ( 'Error setting up dual stream:' , e ) ;
295- }
289+ if ( channelInfo ) {
290+ await this . putChannelInfo ( channelInfo ) ;
296291 }
297292
298293 this . setPlatformContext ( 'twitch' ) ;
@@ -456,6 +451,9 @@ export class TwitchService
456451 return ;
457452 }
458453
454+ // Stream shift not compatible with enhanced broadcasting
455+ this . settingsService . setEnhancedBroadcasting ( false ) ;
456+
459457 const [ channelInfo ] = await Promise . all ( [
460458 this . requestTwitch < {
461459 data : {
@@ -467,7 +465,7 @@ export class TwitchService
467465 } [ ] ;
468466 } > ( `${ this . apiBase } /helix/channels?broadcaster_id=${ this . twitchId } ` ) . then ( json => {
469467 return {
470- title : settings ?. stream_title ?? json . data [ 0 ] . title ,
468+ title : json . data [ 0 ] . title ,
471469 game : json . data [ 0 ] . game_name ,
472470 gameId : json . data [ 0 ] . game_id ,
473471 gameName : json . data [ 0 ] . game_name ,
@@ -481,7 +479,22 @@ export class TwitchService
481479 ] ) ;
482480
483481 const title = settings ?. stream_title ?? channelInfo . title ;
484- const game = settings ?. game_id ?? channelInfo . game ;
482+
483+ // Stream Shift reports the category as an id, but `game` and `gameName` hold the category
484+ // *name* everywhere else in this service — the Go Live form renders `game` directly. Resolve
485+ // the id to a name so a shifted stream doesn't show a bare number as its category.
486+ let game = channelInfo . game ;
487+ let gameId = channelInfo . gameId ;
488+
489+ if ( settings ?. game_id ) {
490+ gameId = settings . game_id ;
491+ try {
492+ game = ( await this . fetchGame ( settings . game_id ) ) . name ;
493+ } catch ( e : unknown ) {
494+ console . error ( 'Stream Shift: could not resolve game name for id' , settings . game_id , e ) ;
495+ game = channelInfo . game ;
496+ }
497+ }
485498
486499 const tags : string [ ] = this . twitchTagsService . views . hasTags
487500 ? this . twitchTagsService . views . tags
@@ -491,16 +504,23 @@ export class TwitchService
491504 tags,
492505 title,
493506 game,
494- gameId : channelInfo . gameId ,
495- gameName : channelInfo . gameName ,
507+ gameId,
508+ gameName : game ,
496509 isBrandedContent : channelInfo . is_branded_content ,
497- isEnhancedBroadcasting : this . settingsService . isEnhancedBroadcasting ( ) ,
510+ // The user's persisted preference, not the OBS runtime flag. Stream shift already forced the OBS flag off,
511+ // so reading the OBS runtime flag here would overwrite the preference with `false` every time a stream is shifted.
512+ isEnhancedBroadcasting : this . state . settings . isEnhancedBroadcasting ,
498513 contentClassificationLabels : channelInfo . content_classification_labels ,
499514 } ) ;
500515
501516 this . setPlatformContext ( 'twitch' ) ;
502517 }
503518
519+ async setupLiveOutputStream ( options ?: IGoLiveSettings ) : Promise < void > {
520+ // Live output editing not compatible with enhanced broadcasting, so disable it here
521+ this . settingsService . setEnhancedBroadcasting ( false ) ;
522+ }
523+
504524 fetchFollowers ( ) : Promise < number > {
505525 return this . requestTwitch < { total : number } > ( {
506526 url : `${ this . apiBase } /helix/users/follows?to_id=${ this . twitchId } ` ,
0 commit comments