Question

So I set up an ejabberd XMPP server and use nginx as a proxy on an EC2 instance. The Strophe.js echobot example can connect from my Chrome browser. Here are the Request Headers:

Request URL:http://foo.eu-west-1.compute.amazonaws.com/http-bind
Request Method:POST
Status Code:200 OK
Request Headers
Accept:*/*
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4
Connection:keep-alive
Content-Length:115
Content-Type:application/xml
Host:foo.compute.amazonaws.com
Origin:foo.eu-west-1.compute.amazonaws.com
Referer:foo.eu-west-1.compute.amazonaws.com/examples/echobot.html
User-Agent:Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11
Request Payload
<body rid='2692151172' xmlns='http://jabber.org/protocol/httpbind' sid='15f6dc6cbc7a7d69b5db531c2ebf7828e094f043'/>
Response Headers
Access-Control-Allow-Headers:Content-Type
Access-Control-Allow-Origin:*
Connection:keep-alive
Content-Length:286
Content-Type:text/xml; charset=utf-8
Date:Fri, 04 Jan 2013 11:14:14 GMT
Server:nginx/1.2.4

I ported the echobot example to work in Spotify as an app. However, Strophe cannot connect. Here is the Web Inspector network log:

Request URL:http://foo.eu-west-1.compute.amazonaws.com/http-bind
Request Headers
POST http://foo.eu-west-1.compute.amazonaws.com/http-bind HTTP/1.1
Origin: sp://chatify
User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.15 Safari/535.11
Content-Type: application/xml
Request Payload
<body rid='790399813' xmlns='http://jabber.org/protocol/httpbind' to='ec2-54-246-45-111.eu-west-1.compute.amazonaws.com' xml:lang='en' wait='60' hold='1' content='text/xml; charset=utf-8' ver='1.6' xmpp:version='1.0' xmlns:xmpp='urn:xmpp:xbosh'/>

Now. The RequiredPermissons in the manifest.json look as follows:

"RequiredPermissons": [
    "http://foo.eu-west-1.compute.amazonaws.com",
    "foo.eu-west-1.compute.amazonaws.com",
    "http://foo.eu-west-1.compute.amazonaws.com/http-bind",
    "foo.eu-west-1.compute.amazonaws.com/http-bind"
]

I can load sources from foo.eu-west-1.compute.amazonaws.com so I think the permissons work. The Spotify app uses a different origin, "sp://chatify". I read that this can cause problems. And Access-Control-Allow-Origin:* should be added to the header. I did so in the nginx config just to find out that it had been sent all along. You can see it in Response Headers of the first request.

Strophe.js itself says in the logs of the example if turned on:

error 0 happened

So any suggestions? The manifest seems to be right Access-Control-Allow-Origin;* seem right It works in a browser but not Spotify.

Thx for your help!

Update: If I open the echobot.html locally it still works. The Origin is then null.

Was it helpful?

Solution

Okay, I got it to work. And the solution is a classic. However, my debugging might help others.

  1. At first I looked at the Web Inspector. It showed that all request were canceled. No the inspector is not always right as mentioned in many places. This time it was, though.

  2. So Strophe.js could not establish a connection. To see if any custom Spotify App could establish a connection I tried the Google Maps example from the tutorial app. It did not work with the native Linux version and the Windows under wine. It did however work under windows.

  3. My next step was to see if my app could load any resources from the net. So I simply added an iframe: . It did not load my page.

  4. I took a close look at the manifest of the tutorial app and my app. I could not find any difference. So I just copied "RequiredPermissions" to see that I had a typo. Once that was fixed the iframe and eventually strophe.js worked.

It is funny. I looked for typos a few days ago I could not find any.

To sum up:

  • Make sure your server sets Access-Control-Allow-Origin;*
  • Set the Permissions. E.g.

    "RequiredPermissions": [ "http://ec2-foo.eu-west-1.compute.amazonaws.com", "ec2-foo.eu-west-1.compute.amazonaws.com", "http://ec2-foo.eu-west-1.compute.amazonaws.com/http-bind", "ec2-foo.eu-west-1.compute.amazonaws.com/http-bind" ]

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top