Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust twitch ingest urls #726

Merged
merged 5 commits into from
Jul 19, 2024
Merged

Adjust twitch ingest urls #726

merged 5 commits into from
Jul 19, 2024

Conversation

frostbyte73
Copy link
Member

Uses the ingest endpoint api to choose the best url for twitch streams

@frostbyte73 frostbyte73 requested a review from a team as a code owner July 18, 2024 22:10
"github.com/livekit/protocol/utils"
)

var twitchEndpoint = regexp.MustCompile("^rtmps?://.*\\.contribute\\.live-video\\.net/app/(.*)( live=1)?$")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A nit, but if you use backquote you won't need to escape the slash.

switch outputType {
case types.OutputTypeRTMP:
if parsed.Scheme == "mux" {
rawUrl = fmt.Sprintf("rtmps://global-live.mux.com:443/app/%s", parsed.Host)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fmt.Sprintf could be swapped to +. Up to you, though.

}

func updateTwitchURL(key string) (string, error) {
resp, err := http.Get("https://ingest.twitch.tv/ingests")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could pass context here from the UpdateStream? I see that it's passed to other methods of ipcServiceClient, so it will get cancelled there eventually. We'll just wait a bit longer here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it only gets passed around for projectID in cloud

@@ -264,7 +264,7 @@ func (c *Controller) UpdateStream(ctx context.Context, req *livekit.UpdateStream
// add stream outputs first
for _, rawUrl := range req.AddOutputUrls {
// validate and redact url
url, redacted, err := c.ValidateUrl(rawUrl, types.OutputTypeRTMP)
url, redacted, err := config.ValidateUrl(rawUrl, types.OutputTypeRTMP)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a question about this one. It's called for each output URL and it may eventually call updateTwitchURL. How likely is that its called twice? I guess it's not typical to output to multiple Twitch streams, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've never seen anyone do it. I considered caching the results but it's a pretty cheap call and didn't seem worth the added complexity

@frostbyte73 frostbyte73 merged commit c644ec9 into main Jul 19, 2024
8 checks passed
@frostbyte73 frostbyte73 deleted the twitch-streams branch July 19, 2024 16:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants