Skip to content

help newbie #99

Closed
Closed
@artem-webdev

Description

I can not understand why the subscription does not work

let centrifuge = new Centrifuge('ws://localhost:8000/connection/websocket');
centrifuge.setToken("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiI0MiJ9.jSjZK6C_SQXVMD_SKU7ZEAa39SKRJtDa4A26uE9Q6EI");

centrifuge.on('connect', function (context) {
    console.log(context);
});
centrifuge.on('disconnect', function (context) {
    console.log(context);
});

let subscription = centrifuge.subscribe("chat", function (message) {
    console.log(message);
});

subscription.on("subscribe", function (context) {
    console.log(context);
});
centrifuge.connect();

this code gives no errors and the subscription does not work

I can not understand what is the reason in centrifugo server or in centrifuge-js

here the server config it is very simple

{
  "history_recover": true,
  "admin_password": "8fe61ef2-23bd-4520-9892-0658709140df",
  "admin_secret": "2db56574-4978-4dd6-bc6a-e6cab276ac6d",
  "api_key": "1a64664d-1205-4b61-8bf4-34c2a0d3a881",
  "secret": "4a56ed9c-37a1-4fdb-8b9d-4067b9a47fe0",
}

run from the working directory

./centrifugo --admin

push example

import requests
import json

command = {
    "method": "publish",
    "params": {
        "channel": "chat",
        "data": {
            "message": "test-message"
        }
    }
}

api_key = "1a64664d-1205-4b61-8bf4-34c2a0d3a881"
data = json.dumps(command)
headers = {'Content-type': 'application/json', 'Authorization': 'apikey ' + api_key}
resp = requests.post("http://localhost:8000/api", data=data, headers=headers)
print(resp.json())

there are no errors from the server side

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions