{"action":"created","issue":{"url":"https://api.github.com/repos/adonisjs/adonis-websocket/issues/55","repository_url":"https://api.github.com/repos/adonisjs/adonis-websocket","labels_url":"https://api.github.com/repos/adonisjs/adonis-websocket/issues/55/labels{/name}","comments_url":"https://api.github.com/repos/adonisjs/adonis-websocket/issues/55/comments","events_url":"https://api.github.com/repos/adonisjs/adonis-websocket/issues/55/events","html_url":"https://github.com/adonisjs/adonis-websocket/issues/55","id":332708407,"node_id":"MDU6SXNzdWUzMzI3MDg0MDc=","number":55,"title":"Issue broadcasting to dynamic channel","user":{"login":"TaylorChristie","id":7576958,"node_id":"MDQ6VXNlcjc1NzY5NTg=","avatar_url":"https://avatars3.githubusercontent.com/u/7576958?v=4","gravatar_id":"","url":"https://api.github.com/users/TaylorChristie","html_url":"https://github.com/TaylorChristie","followers_url":"https://api.github.com/users/TaylorChristie/followers","following_url":"https://api.github.com/users/TaylorChristie/following{/other_user}","gists_url":"https://api.github.com/users/TaylorChristie/gists{/gist_id}","starred_url":"https://api.github.com/users/TaylorChristie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TaylorChristie/subscriptions","organizations_url":"https://api.github.com/users/TaylorChristie/orgs","repos_url":"https://api.github.com/users/TaylorChristie/repos","events_url":"https://api.github.com/users/TaylorChristie/events{/privacy}","received_events_url":"https://api.github.com/users/TaylorChristie/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-06-15T09:36:28Z","updated_at":"2018-06-15T10:35:15Z","closed_at":null,"author_association":"NONE","body":"Basically, I'm implementing live notifications via the websocket connection. I'm just trying to get a working version of the flow going, I'm able to initiate everything properly, but i'm having problems broadcasting to that channel in a HTTP request.\r\n\r\nsocket.js\r\n```js\r\nWs.channel('notifications:*', ({ socket, auth }) => {\r\n  if (auth.user.id !== socket.topic.split(':')[1]) {\r\n    socket.emit('error', 'Invalid topic subscription. You may only subscribe to your own topic.');\r\n    // socket.close()\r\n  }\r\n\r\n  socket.on('message', async (data) => {\r\n    if (auth.user.id !== socket.topic.split(':')[1]) {\r\n      socket.emit('error', 'Invalid topic subscription. You may only subscribe to your own topic.');\r\n    }\r\n    console.log(data)\r\n    if (data.cmd === 'init') {\r\n      socket.emit('init', await getNotifications()) \r\n    }\r\n  })\r\n\r\n\r\n}).middleware(['auth'])\r\n```\r\n\r\nroutes.js\r\n```js\r\nconst Ws = use('Ws')\r\n\r\nRoute.get('sendws', async ({ request }) => {\r\n  await Ws\r\n    .getChannel('notifications:*')\r\n    .topic('notifications:1')\r\n    .broadcast('new:user')\r\n});\r\n```\r\n\r\nI'm getting this error when calling the route: \r\n`Cannot read property 'broadcast' of null` meaning the .topic isn't returning anything. I logged the Channel as below:\r\n```\r\napi_1              | Channel {\r\napi_1              |   name: 'notifications:*',\r\napi_1              |   _onConnect: [Function],\r\napi_1              |   _channelControllerListeners: [],\r\napi_1              |   subscriptions: Map { 'notifications:1' => Set { [Object] } },\r\napi_1              |   _middleware: [ 'auth' ],\r\napi_1              |   deleteSubscription: [Function: bound ] }\r\n```\r\nThe subscription is there but the .topic() call is null. The documentation [states this](https://www.adonisjs.com/docs/4.1/websocket-server#_broadcast_from_anywhere) as an example so either the documentation is outdated/wrong or there is a bug in the code. \r\n"},"comment":{"url":"https://api.github.com/repos/adonisjs/adonis-websocket/issues/comments/397582066","html_url":"https://github.com/adonisjs/adonis-websocket/issues/55#issuecomment-397582066","issue_url":"https://api.github.com/repos/adonisjs/adonis-websocket/issues/55","id":397582066,"node_id":"MDEyOklzc3VlQ29tbWVudDM5NzU4MjA2Ng==","user":{"login":"TaylorChristie","id":7576958,"node_id":"MDQ6VXNlcjc1NzY5NTg=","avatar_url":"https://avatars3.githubusercontent.com/u/7576958?v=4","gravatar_id":"","url":"https://api.github.com/users/TaylorChristie","html_url":"https://github.com/TaylorChristie","followers_url":"https://api.github.com/users/TaylorChristie/followers","following_url":"https://api.github.com/users/TaylorChristie/following{/other_user}","gists_url":"https://api.github.com/users/TaylorChristie/gists{/gist_id}","starred_url":"https://api.github.com/users/TaylorChristie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TaylorChristie/subscriptions","organizations_url":"https://api.github.com/users/TaylorChristie/orgs","repos_url":"https://api.github.com/users/TaylorChristie/repos","events_url":"https://api.github.com/users/TaylorChristie/events{/privacy}","received_events_url":"https://api.github.com/users/TaylorChristie/received_events","type":"User","site_admin":false},"created_at":"2018-06-15T10:35:15Z","updated_at":"2018-06-15T10:35:15Z","author_association":"NONE","body":"Using the second example\r\n\r\n```js\r\n  const chat = Ws.getChannel('notifications:*')\r\n  const { broadcast, emitTo } = chat.topic('notifications:1')\r\n  broadcast('new:user')\r\n```\r\n\r\nGives the message: `Cannot read property 'socket' of undefined`\r\n\r\n\r\n"}}
{"actor":{"display_login":"TaylorChristie"}}