{"_id":"56aceedb5ac4060d0027866d","__v":6,"githubsync":"","parentDoc":null,"user":"56acd6caa040860d00ac94a2","version":{"_id":"56acd71213ac890d001c3c7d","project":"56acd71213ac890d001c3c7a","__v":15,"createdAt":"2016-01-30T15:30:26.928Z","releaseDate":"2016-01-30T15:30:26.928Z","categories":["56acd71313ac890d001c3c7e","56acd8f113ac890d001c3c81","56acd8f95ac4060d0027865e","56acd93a13ac890d001c3c82","56ad20660ab3c00d00ce3347","56ad356a2a7860170013f714","56ad47eb0ab3c00d00ce334f","56afd523bc304a0d00ace1df","56b29a019621f20d00efb37e","56b657e11bc6970d009feee7","5845cc3c39950c1b002afe77","5845cde163c11b250037967e","5846efd45d064323007b17b4","588604da4674e32300efd160","588627882393d50f00f1322c"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"project":"56acd71213ac890d001c3c7a","category":{"_id":"56acd8f113ac890d001c3c81","__v":6,"pages":["56acecb32a7860170013f6e9","56acedfed21f1b0d00fd2f70","56aceedb5ac4060d0027866d","56acef31693f0a0d0085f0ab","56acf23d2a7860170013f6f3","56ad4b89c00d120d00744353"],"project":"56acd71213ac890d001c3c7a","version":"56acd71213ac890d001c3c7d","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-01-30T15:38:25.293Z","from_sync":false,"order":8,"slug":"singularity","title":"Singularity"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-01-30T17:11:55.173Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":3,"body":"[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Did you properly get a channel's access_token?\",\n  \"body\": \"Remember, an access_token is required to connect to a GameWisp Channel on Singularity.\"\n}\n[/block]\nOnce you have an OAuth2 access_token for a GameWisp channel, you can connect to that channel through Singularity like so:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"socket.emit('channel-connect', {\\n    access_token: 'channel oauth2 access token'\\n});\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nIf the token has expired, you will receive a message indicating as such. If that’s the case, you will need to refresh the token.\n[block:callout]\n{\n  \"type\": \"success\",\n  \"title\": \"You can connect to multiple GameWisp channels\",\n  \"body\": \"Want your app to connect to multiple GameWisp channels? Just use the 'channel-connect' event with another channel's access token and you'll receive real-time data from that channel, too!\"\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Successful Authorization\"\n}\n[/block]\nUpon verifying the channel’s access token, Singularity will emit the **app-channel-connected** event to your application, which you can listen for as follows:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \" socketClient.on('app-channel-connected', function(response){\\n      //Do something with the response                           \\n  });\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nThe **response** is a JSON object of the form:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n  result: {\\n    status: 1,\\n    message: \\\"Channel authenticated.\\\"\\n  },\\n  data: {\\n    channel_id: \\\"channel identifier\\\",\\n    status: 'authenticated',\\n    listening: true\\n  },\\n  channel:{\\n    names:{\\n      gamewisp: 'gamewisp channel name',\\n      twitch: 'twitch channel name',\\n      youtube: 'youtube channel name'\\n    },\\n    ids:{\\n      gamewisp: 'gamewisp channel id',\\n      twitch: 'twitch channel id',\\n      youtube: 'youtube channel id'\\n    }\\n  }\\n}\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]\n**result **contains the overall status of the call. A status of 1 indicates success, 0 indicates failure. \n\n**data** contains the following:\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"parameter\",\n    \"h-1\": \"type\",\n    \"h-2\": \"description\",\n    \"0-0\": \"id\",\n    \"0-1\": \"string\",\n    \"0-2\": \"The channel’s identifying key.\",\n    \"1-0\": \"status\",\n    \"1-1\": \"string\",\n    \"1-2\": \"The status of the authorization attempt. “authenticated” for a successful authorization, “invalid” if there is a problem with the key-identifier pair you passed in for that channel in channels-listen.\",\n    \"2-0\": \"listening\",\n    \"2-1\": \"boolean\",\n    \"2-2\": \"Indicates that you will receive real time data for the channel as it occurs.\\nIf you receive a listening: true for a channel, you will receive data for that channel from singularity in real-time as it occurs.\"\n  },\n  \"cols\": 3,\n  \"rows\": 3\n}\n[/block]\nThe **channel** object identifies the channel’s gamewisp name and id as well as twitch and youtube identifying information if available.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"What Next?\"\n}\n[/block]\nWhy not connect the channel you created in the [Registering an Application](https://gamewisp.readme.io/docs/api-authorization) step to your application and then try to [send some test events](https://gamewisp.readme.io/docs/testing-singularity)?","excerpt":"","slug":"connecting-to-a-gamewisp-channel-on-singularity","type":"basic","title":"Connecting to a GameWisp Channel"}

Connecting to a GameWisp Channel


[block:callout] { "type": "info", "title": "Did you properly get a channel's access_token?", "body": "Remember, an access_token is required to connect to a GameWisp Channel on Singularity." } [/block] Once you have an OAuth2 access_token for a GameWisp channel, you can connect to that channel through Singularity like so: [block:code] { "codes": [ { "code": "socket.emit('channel-connect', {\n access_token: 'channel oauth2 access token'\n});", "language": "javascript" } ] } [/block] If the token has expired, you will receive a message indicating as such. If that’s the case, you will need to refresh the token. [block:callout] { "type": "success", "title": "You can connect to multiple GameWisp channels", "body": "Want your app to connect to multiple GameWisp channels? Just use the 'channel-connect' event with another channel's access token and you'll receive real-time data from that channel, too!" } [/block] [block:api-header] { "type": "basic", "title": "Successful Authorization" } [/block] Upon verifying the channel’s access token, Singularity will emit the **app-channel-connected** event to your application, which you can listen for as follows: [block:code] { "codes": [ { "code": " socketClient.on('app-channel-connected', function(response){\n //Do something with the response \n });", "language": "javascript" } ] } [/block] The **response** is a JSON object of the form: [block:code] { "codes": [ { "code": "{\n result: {\n status: 1,\n message: \"Channel authenticated.\"\n },\n data: {\n channel_id: \"channel identifier\",\n status: 'authenticated',\n listening: true\n },\n channel:{\n names:{\n gamewisp: 'gamewisp channel name',\n twitch: 'twitch channel name',\n youtube: 'youtube channel name'\n },\n ids:{\n gamewisp: 'gamewisp channel id',\n twitch: 'twitch channel id',\n youtube: 'youtube channel id'\n }\n }\n}", "language": "json" } ] } [/block] **result **contains the overall status of the call. A status of 1 indicates success, 0 indicates failure. **data** contains the following: [block:parameters] { "data": { "h-0": "parameter", "h-1": "type", "h-2": "description", "0-0": "id", "0-1": "string", "0-2": "The channel’s identifying key.", "1-0": "status", "1-1": "string", "1-2": "The status of the authorization attempt. “authenticated” for a successful authorization, “invalid” if there is a problem with the key-identifier pair you passed in for that channel in channels-listen.", "2-0": "listening", "2-1": "boolean", "2-2": "Indicates that you will receive real time data for the channel as it occurs.\nIf you receive a listening: true for a channel, you will receive data for that channel from singularity in real-time as it occurs." }, "cols": 3, "rows": 3 } [/block] The **channel** object identifies the channel’s gamewisp name and id as well as twitch and youtube identifying information if available. [block:api-header] { "type": "basic", "title": "What Next?" } [/block] Why not connect the channel you created in the [Registering an Application](https://gamewisp.readme.io/docs/api-authorization) step to your application and then try to [send some test events](https://gamewisp.readme.io/docs/testing-singularity)?