سؤال

So I have been trying to do a bit of reading on XMPP and decided to try and mess around with the Strophe JS library. I tried connecting to an XMPP server that I know about (address is http://chat.na1.lol.riotgames.com:5223) with what I believe is the appropriate domain, username, and password and when I attempt a connection (just running the javascript locally) the following is sent to the server:

<body rid='3367062472' xmlns='http://jabber.org/protocol/httpbind' to='pvp.net' 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'/>

But I get a the following error in Chrome:

XMLHttpRequest cannot load https://chat.na1.lol.riotgames.com:5223/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.

In FireFox I see the console output of what was sent but I don't see the error about the Access-Control-Allow-Origin header.

The following is the simple javascript that is attempting the connection:

var SERVER = "http://chat.na1.lol.riotgames.com:5223", 
    username = "name@domain.net",
    password = "AIR_password",
    connection;

function log(msg) 
{
    console.log(msg);
}

function rawInput(data)
{
    log('RECV: ' + data);
}

function rawOutput(data)
{
    log('SENT: ' + data);
}

function onConnect(status)
{
    if (status == Strophe.Status.CONNECTING) {
        log('Strophe is connecting.');
    } else if (status == Strophe.Status.CONNFAIL) {
        log('Strophe failed to connect.');
    } else if (status == Strophe.Status.DISCONNECTING) {
        log('Strophe is disconnecting.');
    } else if (status == Strophe.Status.DISCONNECTED) {
        log('Strophe is disconnected.');
    } else if (status == Strophe.Status.CONNECTED) {
        log('Strophe is connected.');
        connection.disconnect();
    }
}

$(document).ready(function () {
    connection = new Strophe.Connection(SERVER);
    connection.rawInput = rawInput;
    connection.rawOutput = rawOutput;

    connection.connect(username, password, onConnect);
});

Am I running into cross-domain issues? Is something wrong with how I'm trying to connect?

I know that connecting to this server is possible since it is possible to connect via Pidgin and other 3rd party applications have done this as well. Do i need some server setup of my own to accomplish this kind of connection?

هل كانت مفيدة؟

المحلول

5223 is a port for "old style SSL" TCP connections, most XMPP applications uses TCP connection to the server. But javascript apps are impossible (AFAIK) to maintain TCP connection and uses XMPP BOSH extension (long-polling HTTP requests), you need a BOSH connection manager/extension on your server(typically on 5280 port).

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top