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

DevRig: PubSub Broadcasts for non-default topics are not received by listeners #142

Closed
lettucemode opened this issue Jun 15, 2020 · 1 comment
Labels
product: developer rig Decommissioned stopped investigating An issue that cannot be reproduced and is no longer being actively investigated.

Comments

@lettucemode
Copy link

lettucemode commented Jun 15, 2020

Brief description
When sending a PubSub Broadcast, if the topic/target is something besides "broadcast" or "global" (for example, "whisper-opaque_user_id"), the broadcast is not received by simulated user views in the Developer Rig.

How to reproduce
Frontend code to listen for broadcasts:

twitch.onAuthorized(function (auth) {
  twitch.listen('whisper-' + auth.userId, function (targ, cType, message) {
   twitch.rig.log(message); // this is never hit
  });
});

Backend code to send a PubSub broadcast (C#):

public async Task SendPubSubWhisper(string channelId, IEnumerable<string> userIds, string message)
{
    using var request = new HttpRequestMessage(HttpMethod.Post,
        $"https://api.twitch.tv/extensions/message/{channelId}");
    request.Headers.Add("Client-ID", this._extClientId);
    request.Headers.Add("Authorization", BEARER_PREFIX + this.MakePubSubToken(channelId, true));

    var body = new Dictionary<string, object>
    {
        { "content_type", "application/json" },
        { "message", message },
        { "targets", userIds.Select(uid => $"whisper-{uid}").ToArray() },
    };
    request.Content = new StringContent(
        new JsonNetSerializer().Serialize(body), Encoding.UTF8, "application/json");

    using var client = new HttpClient();
    using var response = await client.SendAsync(request);
}

private string MakePubSubToken(string channelId, bool isWhisper)
{
    var perms = new perms { send = new string[] { isWhisper ? "whisper-*" : "*" } };
    var payload = new Dictionary<string, object>
    {
        { "exp", (DateTimeOffset.Now.ToUnixTimeSeconds() + 60) },
        { "user_id", this._extOwnerId },
        { "role", "external" },
        { "channel_id", channelId },
        { "pubsub_perms", perms }
    };

    IJwtAlgorithm algorithm = new HMACSHA256Algorithm();
    IJsonSerializer serializer = new JsonNetSerializer();
    IBase64UrlEncoder urlEncoder = new JwtBase64UrlEncoder();
    IJwtEncoder encoder = new JwtEncoder(algorithm, serializer, urlEncoder);
    var token = encoder.Encode(payload, Convert.FromBase64String(this._extSecret));
    return token;
}

Expected behavior
Extensions running in the Developer Rig should receive PubSub broadcast events for any topic/target.

Additional context or questions
The example code above DOES work as expected for all topics/targets when running the extension as a Hosted Test in Twitch. In either case the response from the PubSub Broadcast endpoint is 204 No Content.

@jbulava jbulava added the stopped investigating An issue that cannot be reproduced and is no longer being actively investigated. label Apr 18, 2023
@jbulava
Copy link
Member

jbulava commented Apr 18, 2023

Closing since the Developer Rig has reached its end of support date.

@jbulava jbulava closed this as completed Apr 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
product: developer rig Decommissioned stopped investigating An issue that cannot be reproduced and is no longer being actively investigated.
Projects
None yet
Development

No branches or pull requests

3 participants