Can't get PubSub listener to work


I am trying to get a hang on PubSub for my extension.
I am trying to listen on a “send” call from my EBS by doing:

window.Twitch.ext.listen("broadcast", function(target, contentType, message) {

My EBS is getting a 204 http code, which means it was created.
My body for the PubSub creation looks like this:
{"content_type":"application/json", "message":"{\"foo\":\"bar\"}", "targets":["broadcast"]}

I tried to create a PubSub message with window.Twitch.ext.send() and I am getting a 204 on the request in the chrome dev “network” tab, but nothing happens in the listen() function.

Can you show as your full EBS Send call with secrets removed?

Are you posting to similar to the example:

curl -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MDMzNDM5NDcsInVzZXJfaWQiOiIyNzQxOTAxMSIsImNoYW5uZWxfaWQiOiIyNzQxOTAxMSIsInJvbGUiOiJleHRlcm5hbCIsInB1YnN1Yl9wZXJtcyI6eyJzZW5kIjpbIioiXX19.TiDAzrq58XczdymAozwsdVilRkjr9KN8C0pCv7px-FM" \
-H "Client-Id: pxifeyz7vxk9v6yb202nq4cwsnsp1t" \
-H "Content-Type: application/json" \
-d '{"content_type":"application/json", "message":"{\"foo\":\"bar\"}", "targets":["broadcast"]}' \

Note that ChannelID in your JWT payload needs to casted to a string.
And you need to post to the right channelID in

If you post a VALID JWT payload with one channelID to the DIFFERENT channel ID it 204’s in error.

I am following the docs, yes. It’s in php.

       $url = "" . $jwt->getClaim(”channel_id”);
	   $headers = array(
			"Authorization: Bearer " . (string)$jwt,
			"Client-Id: " . EXT_CLIENT_ID,
			"Content-Type: application/json"

		$data = array(
			"content_type" => "application/json",
			"targets" => array("broadcast"),
			"message" => '{"content_type":"application/json", "message":"{\"foo\":\"bar\"}", "targets":["broadcast"]}'

		$ch = curl_init($url);
		curl_setopt($ch, CURLOPT_POST, true);
		curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

Posted from my phone so bear with me.
Will try with casting the channel_id to string when I am home.

Also, my extension is in testing mode, if that matters.

I noticed now that the “onError()” function prints this on first load of the extension:

    at e.notifyOnError (twitch-ext.min.js:8)
    at Object.failure (twitch-ext.min.js:8)
    at t.value (twitch-ext.min.js:8)
    at t.value (twitch-ext.min.js:1)
    at t.value (twitch-ext.min.js:8)

If I right click the iframe and refresh this message doesn’t come up.
Casting the channel_id to string didn’t work, also I am pretty sure it’s a string already but even with explicit casting it didn’t change anything.

Hmm that feels like theres something awry in your extension javascript, can you post that more fully for us to take a peek at.

For some reason it doesn’t work with Twitch’s JWT, I had to create my own signed jwt.
It works now, thanks for responding! :smiley:

Yes, to send from your EBS you must craft a JWT using your extension secret (making sure to cast channel_id in the JSON to a string)

I assumed you were doing that and not using a “client side” JWT :stuck_out_tongue:

Yeah, I guess I misunderstood the docs… It says “Authentication
Signed JWT (Twitch or EBS JWTs are allowed)” which I interpreted as either the JWT from Twitch or a self-crafted one.

Another question. Is it possible to use another target than “broadcast”? I get the ERR_BADAUTH error if I try to listen to something else than “broadcast”. I am signed in as the channel user.

There is only broadcast and whisper-userID

1 Like

Soon… :wink:

1 Like