centrifugal / adjacent

Centrifugo v1 integration with Django framework, for Centrifugo v2 use cent Python client to integrate
https://github.com/centrifugal/cent
32 stars 5 forks source link

How to use CENTRIFUGE_INFO? #2

Closed aleprovencio closed 9 years ago

aleprovencio commented 9 years ago

Hello, I would like to use CENTRIFUGE_INFO so I can set nicknames for users. Using the context_processor may be the most convenient, but I can't find a way. I also tried without success using on the view this way below, what's wrong?

info = {"nick": request.user.username}
chat_params = get_connection_parameters(
    request.user, json.dumps(info))
FZambia commented 9 years ago

Hi! It seems that you create chat_params in a correct way. Do you have exceptions? Why you decided that you have not succeeded?

aleprovencio commented 9 years ago

Taking 'info' out of Centrifuge objection creation makes the chat work fine, otherwise it will not.

This is the javascript portion:

var centrifuge = new Centrifuge({
    url: '{{ chat_params.sockjs_endpoint }}',
    project: '{{ chat_params.project }}',
    user: '{{ chat_params.user }}',
    timestamp: '{{ chat_params.timestamp }}',
    info: '{{ chat_params.info }}',
    token: '{{ chat_params.token }}',
    debug: true
});

And the rendered html source:

var centrifuge = new Centrifuge({
    url: 'http://127.0.0.1:8000/connection',
    project: 'development',
    user: '5',
    timestamp: '1443622504',
    info: '{"nick": "test1"}',
    token: 'f36efcd0dc5f8dac3b818d1a223ab1a072b24e44873804b7d5af7a3bc5805c62',
    debug: true
});

Maybe it has something to do with the 'quot;' char?

FZambia commented 9 years ago

Have you tried {{ chat_params.info|safe }}?

aleprovencio commented 9 years ago

Did the trick! Thank you for the help e sorry about such a dumb mistake :)

FZambia commented 9 years ago

You are welcome, this is not so clear so I added information to README.md