{"metadata":{"image":[],"title":"","description":""},"api":{"url":"","auth":"required","results":{"codes":[]},"settings":"","params":[],"examples":{"codes":[]},"method":"get"},"next":{"description":"","pages":[]},"title":"Socket API","type":"basic","slug":"socket-api","excerpt":"","body":"Socket Token can be fetched using **[/socket/token endpoint](https://streamlabs.readme.io/docs/sockettoken)**\nSample Code:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<script src='https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.3/socket.io.js' type='text/javascript'></script>\\n<script type = 'text/javascript'>\\n  const socketToken = ''; //Socket token from /socket/token end point\\n\\t\\n\\t//Connect to socket\\n\\tconst streamlabs = io(`https://sockets.streamlabs.com?token=${socketToken}`);\\n\\t\\n\\t//Perform Action on event\\n\\tstreamlabs.on('event', (eventData) => {\\n    if (!eventData.for || eventData.for === 'streamlabs' && eventData.type === 'donation') {\\n    \\t//code to handle donation events\\n      console.log(eventData.message);\\n    }\\n    if (eventData.for === 'twitch_account') {\\n      switch(eventData.type) {\\n        case 'follow':\\n          //code to handle follow events\\n          console.log(eventData.message);\\n          break;\\n        case 'subscription':\\n          //code to handle subscription events\\n          console.log(eventData.message);\\n          break;\\n        default:\\n          //default case\\n          console.log(eventData.message);\\n      }\\n    }\\n  });\\n</script>\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"danger\",\n  \"title\": \"eventData.message\",\n  \"body\": \"This will always be an array\"\n}\n[/block]\n***type*** and ***for*** values for different events are described below\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"type\",\n    \"h-1\": \"for\",\n    \"1-0\": \"follow\",\n    \"1-1\": \"twitch_account\",\n    \"h-2\": \"Event\",\n    \"1-2\": \"Twitch Follow\",\n    \"2-0\": \"subscription\",\n    \"3-0\": \"host\",\n    \"4-0\": \"bits\",\n    \"2-1\": \"twitch_account\",\n    \"3-1\": \"twitch_account\",\n    \"4-1\": \"twitch_account\",\n    \"2-2\": \"Twitch Subscription\",\n    \"3-2\": \"Twitch Host\",\n    \"4-2\": \"Twitch Bits/Cheers\",\n    \"0-0\": \"donation\",\n    \"0-1\": \"'' || streamlabs\",\n    \"0-2\": \"Donations\",\n    \"5-0\": \"follow\",\n    \"6-0\": \"subscription\",\n    \"7-0\": \"superchat\",\n    \"5-1\": \"youtube_account\",\n    \"6-1\": \"youtube_account\",\n    \"7-1\": \"youtube_account\",\n    \"5-2\": \"Youtube Subscriber\",\n    \"6-2\": \"Youtube Sponsor\",\n    \"7-2\": \"Youtube Superchats\",\n    \"8-0\": \"follow\",\n    \"8-1\": \"mixer_account\",\n    \"8-2\": \"Mixer Follow\",\n    \"9-0\": \"subscription\",\n    \"9-1\": \"mixer_account\",\n    \"9-2\": \"Mixer Subscription\",\n    \"10-0\": \"host\",\n    \"10-1\": \"mixer_account\",\n    \"10-2\": \"Mixer Host\"\n  },\n  \"cols\": 3,\n  \"rows\": 11\n}\n[/block]\n# Sample Responses:\nDonations\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n  \\\"type\\\": \\\"donation\\\",\\n  \\\"message\\\": [\\n    {\\n      \\\"id\\\": 96164121,\\n      \\\"name\\\": \\\"test\\\",\\n      \\\"amount\\\": \\\"13.37\\\",\\n      \\\"formatted_amount\\\": \\\"$13.37\\\",\\n      \\\"formattedAmount\\\": \\\"$13.37\\\",\\n      \\\"message\\\": \\\"test donation\\\",\\n      \\\"currency\\\": \\\"USD\\\",\\n      \\\"emotes\\\": null,\\n      \\\"iconClassName\\\": \\\"user\\\",\\n      \\\"to\\\": {\\n        \\\"name\\\": \\\"Sai Harsha Maddela\\\"\\n      },\\n      \\\"from\\\": \\\"test\\\",\\n      \\\"from_user_id\\\": null,\\n      \\\"_id\\\": \\\"0820c9d5bafd768c9843f5e35c885e71\\\"\\n    }\\n  ],\\n  \\\"event_id\\\": \\\"evt_17e5f4dc6888767ed9799f78dfa2cabc\\\"\\n}\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]\nTwitch Subscription\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n  \\\"type\\\": \\\"subscription\\\",\\n  \\\"message\\\": [\\n    {\\n      \\\"name\\\": \\\"kevin\\\",\\n      \\\"months\\\": 7,\\n      \\\"message\\\": \\\"sub message\\\",\\n      \\\"emotes\\\": null,\\n      \\\"sub_plan\\\": 1000,\\n      \\\"sub_plan_name\\\": \\\"Sample Plan name\\\",\\n      \\\"sub_type\\\": \\\"resub\\\",\\n      \\\"_id\\\": \\\"a226a8c223634afdc368439c1da7aaba\\\"\\n    }\\n  ],\\n  \\\"for\\\": \\\"twitch_account\\\"\\n}\",\n      \"language\": \"json\",\n      \"name\": null\n    }\n  ]\n}\n[/block]\nTwitch Follow\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n  \\\"type\\\": \\\"follow\\\",\\n  \\\"message\\\": [\\n    {\\n      \\\"created_at\\\": \\\"2017-08-22 00:14:35\\\",\\n      \\\"id\\\": \\\"170884026\\\",\\n      \\\"name\\\": \\\"h4r5h48002\\\",\\n      \\\"_id\\\": \\\"74a0b93e736f1f14762111f8ae34bf42\\\"\\n    }\\n  ],\\n  \\\"for\\\": \\\"twitch_account\\\"\\n}\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]\nTwitch Host\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n  \\\"type\\\": \\\"host\\\",\\n  \\\"message\\\": [\\n    {\\n      \\\"name\\\": \\\"h4r5h48002\\\",\\n      \\\"viewers\\\": \\\"1\\\",\\n      \\\"type\\\": \\\"manual\\\",\\n      \\\"_id\\\": \\\"74a0b93e736f1f14762111f8ae34bf42\\\"\\n    }\\n  ],\\n  \\\"for\\\": \\\"twitch_account\\\"\\n}\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]\nTwitch Bits\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n  \\\"type\\\": \\\"bits\\\",\\n  \\\"message\\\": [\\n    {\\n      \\\"id\\\": \\\"fc546f7d-aab8-42b2-9933-8681e9fb5eb0\\\",\\n      \\\"name\\\": \\\"h4r5h48002\\\",\\n      \\\"amount\\\": \\\"1\\\",\\n\\t\\t\\t\\\"emotes\\\": null,\\n\\t\\t\\t\\\"message\\\": \\\"streamlabs1\\\",\\n      \\\"_id\\\": \\\"74a0b93e736f1f14762111f8ae34bf42\\\"\\n    }\\n  ],\\n  \\\"for\\\": \\\"twitch_account\\\"\\n}\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]\nYoutube Subscriber\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n  \\\"type\\\": \\\"follow\\\",\\n  \\\"message\\\": [\\n    {\\n      \\\"publishedAt\\\": \\\"2017-08-22 00:25:57\\\",\\n      \\\"id\\\": \\\"UCec4hVEu3ZXE8qlRtUeK0DA\\\",\\n      \\\"name\\\": \\\"Kappa Lord\\\",\\n      \\\"_id\\\": \\\"6af0964e548a6d93c192c9e31e0959cc\\\"\\n    }\\n  ],\\n  \\\"for\\\": \\\"youtube_account\\\"\\n}\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]\nYoutube Sponsor\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n  \\\"type\\\": \\\"subscription\\\",\\n  \\\"message\\\": [\\n    {\\n      \\\"sponsorSince\\\": \\\"2017-08-22 00:45:48\\\",\\n      \\\"id\\\": \\\"UCec4hVEu3ZXE8qlRtUeK0DA\\\",\\n      \\\"name\\\": \\\"Kappa Lord\\\",\\n      \\\"channelUrl\\\": \\\"http://www.youtube.com/channel/UCec4hVEu3ZXE8qlRtUeK0DA\\\",\\n      \\\"months\\\": 3,\\n      \\\"_id\\\": \\\"33d396edab6e2e2e8b37a7b6f1b60b82\\\"\\n    }\\n  ],\\n  \\\"for\\\": \\\"youtube_account\\\"\\n}\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]\nYoutube Superchat\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n  \\\"type\\\": \\\"superchat\\\",\\n  \\\"message\\\": [\\n    {\\n      \\\"id\\\": \\\"LCC.Cg8KDQoLWmpUemdzdU1vM2sSHAoaQ05PcW01UzJ3dElDRll2WkhBb2RLd0lBOWc0.028141892513880107\\\",\\n      \\\"channelId\\\": \\\"UCec4hVEu3ZXE8qlRtUeK0DA\\\",\\n      \\\"channelUrl\\\": \\\"http://www.youtube.com/channel/UCec4hVEu3ZXE8qlRtUeK0DA\\\",\\n      \\\"name\\\": \\\"Kappa Lord\\\",\\n      \\\"comment\\\": \\\"love the stream\\\",\\n      \\\"amount\\\": \\\"2000000\\\",\\n      \\\"currency\\\": \\\"USD\\\",\\n      \\\"displayString\\\": \\\"$2.00\\\",\\n      \\\"messageType\\\": 2,\\n      \\\"createdAt\\\": \\\"2017-08-22 00:51:57\\\",\\n      \\\"_id\\\": \\\"ad46c7e468331c5e39373e05876fa17e\\\"\\n    }\\n  ],\\n  \\\"for\\\": \\\"youtube_account\\\"\\n}\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]\nMixer Follow\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n  \\\"type\\\": \\\"follow\\\",\\n  \\\"message\\\": [\\n    {\\n      \\\"id\\\": 1816,\\n      \\\"name\\\": \\\"Jamacanbacn\\\",\\n      \\\"created_at\\\": \\\"2017-08-22 00:30:25\\\",\\n      \\\"_id\\\": \\\"4fbcdd82bc9fd39467572b24ee20a766\\\"\\n    }\\n  ],\\n  \\\"for\\\": \\\"mixer_account\\\"\\n}\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]\nMixer Subscription\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n  \\\"type\\\": \\\"subscription\\\",\\n  \\\"message\\\": [\\n    {\\n      \\\"id\\\": \\\"123456\\\",\\n      \\\"name\\\": \\\"h4r5h4\\\",\\n      \\\"months\\\": 2,\\n      \\\"message\\\": null,\\n      \\\"emotes\\\": null,\\n      \\\"since\\\": \\\"2017-08-22 00:36:59\\\",\\n      \\\"_id\\\": \\\"68f034214d68dce22431801b940d2b90\\\"\\n    }\\n  ],\\n  \\\"for\\\": \\\"mixer_account\\\"\\n}\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]\nMixer Host\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n  \\\"type\\\": \\\"host\\\",\\n  \\\"message\\\": [\\n    {\\n      \\\"name\\\": \\\"h4r5h47\\\",\\n      \\\"viewers\\\": \\\"5\\\",\\n      \\\"type\\\": \\\"manual\\\",\\n      \\\"_id\\\": \\\"4ee5fcf7e34128f4f07bb978c9e35fd4\\\"\\n    }\\n  ],\\n  \\\"for\\\": \\\"mixer_account\\\"\\n}\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]","updates":[],"order":1,"isReference":false,"hidden":false,"sync_unique":"","link_url":"","link_external":false,"_id":"599bb2fec03fa2000f83d97c","project":"55baca9cd0736b3100bf1008","version":{"version":"1.0","version_clean":"1.0.0","codename":"","is_stable":true,"is_beta":true,"is_hidden":false,"is_deprecated":false,"categories":["55baca9dd0736b3100bf100c","55bacba0d0736b3100bf1017","55bad8f33f0767230008f517","55baf3f01b0d66370078166e","55baf4151b0d66370078166f","55f1cca35fe76419007dc794","573e2d6e610a090e00ca2b97","58d97ce57718211b0028e6bc","599b510cb683b50031a35299","5a871c493948fd004697e677"],"_id":"55baca9cd0736b3100bf100b","createdAt":"2015-07-31T01:08:44.540Z","project":"55baca9cd0736b3100bf1008","__v":10,"releaseDate":"2015-07-31T01:08:44.540Z"},"category":{"sync":{"isSync":false,"url":""},"pages":[],"title":"Sockets","slug":"sockets","order":5,"from_sync":false,"reference":false,"_id":"599b510cb683b50031a35299","project":"55baca9cd0736b3100bf1008","version":"55baca9cd0736b3100bf100b","createdAt":"2017-08-21T21:30:52.713Z","__v":0},"user":"58c9ded6c108331b00c1fee4","createdAt":"2017-08-22T04:28:46.592Z","githubsync":"","__v":0,"parentDoc":null}
Socket Token can be fetched using **[/socket/token endpoint](https://streamlabs.readme.io/docs/sockettoken)** Sample Code: [block:code] { "codes": [ { "code": "<script src='https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.3/socket.io.js' type='text/javascript'></script>\n<script type = 'text/javascript'>\n const socketToken = ''; //Socket token from /socket/token end point\n\t\n\t//Connect to socket\n\tconst streamlabs = io(`https://sockets.streamlabs.com?token=${socketToken}`);\n\t\n\t//Perform Action on event\n\tstreamlabs.on('event', (eventData) => {\n if (!eventData.for || eventData.for === 'streamlabs' && eventData.type === 'donation') {\n \t//code to handle donation events\n console.log(eventData.message);\n }\n if (eventData.for === 'twitch_account') {\n switch(eventData.type) {\n case 'follow':\n //code to handle follow events\n console.log(eventData.message);\n break;\n case 'subscription':\n //code to handle subscription events\n console.log(eventData.message);\n break;\n default:\n //default case\n console.log(eventData.message);\n }\n }\n });\n</script>", "language": "javascript" } ] } [/block] [block:callout] { "type": "danger", "title": "eventData.message", "body": "This will always be an array" } [/block] ***type*** and ***for*** values for different events are described below [block:parameters] { "data": { "h-0": "type", "h-1": "for", "1-0": "follow", "1-1": "twitch_account", "h-2": "Event", "1-2": "Twitch Follow", "2-0": "subscription", "3-0": "host", "4-0": "bits", "2-1": "twitch_account", "3-1": "twitch_account", "4-1": "twitch_account", "2-2": "Twitch Subscription", "3-2": "Twitch Host", "4-2": "Twitch Bits/Cheers", "0-0": "donation", "0-1": "'' || streamlabs", "0-2": "Donations", "5-0": "follow", "6-0": "subscription", "7-0": "superchat", "5-1": "youtube_account", "6-1": "youtube_account", "7-1": "youtube_account", "5-2": "Youtube Subscriber", "6-2": "Youtube Sponsor", "7-2": "Youtube Superchats", "8-0": "follow", "8-1": "mixer_account", "8-2": "Mixer Follow", "9-0": "subscription", "9-1": "mixer_account", "9-2": "Mixer Subscription", "10-0": "host", "10-1": "mixer_account", "10-2": "Mixer Host" }, "cols": 3, "rows": 11 } [/block] # Sample Responses: Donations [block:code] { "codes": [ { "code": "{\n \"type\": \"donation\",\n \"message\": [\n {\n \"id\": 96164121,\n \"name\": \"test\",\n \"amount\": \"13.37\",\n \"formatted_amount\": \"$13.37\",\n \"formattedAmount\": \"$13.37\",\n \"message\": \"test donation\",\n \"currency\": \"USD\",\n \"emotes\": null,\n \"iconClassName\": \"user\",\n \"to\": {\n \"name\": \"Sai Harsha Maddela\"\n },\n \"from\": \"test\",\n \"from_user_id\": null,\n \"_id\": \"0820c9d5bafd768c9843f5e35c885e71\"\n }\n ],\n \"event_id\": \"evt_17e5f4dc6888767ed9799f78dfa2cabc\"\n}", "language": "json" } ] } [/block] Twitch Subscription [block:code] { "codes": [ { "code": "{\n \"type\": \"subscription\",\n \"message\": [\n {\n \"name\": \"kevin\",\n \"months\": 7,\n \"message\": \"sub message\",\n \"emotes\": null,\n \"sub_plan\": 1000,\n \"sub_plan_name\": \"Sample Plan name\",\n \"sub_type\": \"resub\",\n \"_id\": \"a226a8c223634afdc368439c1da7aaba\"\n }\n ],\n \"for\": \"twitch_account\"\n}", "language": "json", "name": null } ] } [/block] Twitch Follow [block:code] { "codes": [ { "code": "{\n \"type\": \"follow\",\n \"message\": [\n {\n \"created_at\": \"2017-08-22 00:14:35\",\n \"id\": \"170884026\",\n \"name\": \"h4r5h48002\",\n \"_id\": \"74a0b93e736f1f14762111f8ae34bf42\"\n }\n ],\n \"for\": \"twitch_account\"\n}", "language": "json" } ] } [/block] Twitch Host [block:code] { "codes": [ { "code": "{\n \"type\": \"host\",\n \"message\": [\n {\n \"name\": \"h4r5h48002\",\n \"viewers\": \"1\",\n \"type\": \"manual\",\n \"_id\": \"74a0b93e736f1f14762111f8ae34bf42\"\n }\n ],\n \"for\": \"twitch_account\"\n}", "language": "json" } ] } [/block] Twitch Bits [block:code] { "codes": [ { "code": "{\n \"type\": \"bits\",\n \"message\": [\n {\n \"id\": \"fc546f7d-aab8-42b2-9933-8681e9fb5eb0\",\n \"name\": \"h4r5h48002\",\n \"amount\": \"1\",\n\t\t\t\"emotes\": null,\n\t\t\t\"message\": \"streamlabs1\",\n \"_id\": \"74a0b93e736f1f14762111f8ae34bf42\"\n }\n ],\n \"for\": \"twitch_account\"\n}", "language": "json" } ] } [/block] Youtube Subscriber [block:code] { "codes": [ { "code": "{\n \"type\": \"follow\",\n \"message\": [\n {\n \"publishedAt\": \"2017-08-22 00:25:57\",\n \"id\": \"UCec4hVEu3ZXE8qlRtUeK0DA\",\n \"name\": \"Kappa Lord\",\n \"_id\": \"6af0964e548a6d93c192c9e31e0959cc\"\n }\n ],\n \"for\": \"youtube_account\"\n}", "language": "json" } ] } [/block] Youtube Sponsor [block:code] { "codes": [ { "code": "{\n \"type\": \"subscription\",\n \"message\": [\n {\n \"sponsorSince\": \"2017-08-22 00:45:48\",\n \"id\": \"UCec4hVEu3ZXE8qlRtUeK0DA\",\n \"name\": \"Kappa Lord\",\n \"channelUrl\": \"http://www.youtube.com/channel/UCec4hVEu3ZXE8qlRtUeK0DA\",\n \"months\": 3,\n \"_id\": \"33d396edab6e2e2e8b37a7b6f1b60b82\"\n }\n ],\n \"for\": \"youtube_account\"\n}", "language": "json" } ] } [/block] Youtube Superchat [block:code] { "codes": [ { "code": "{\n \"type\": \"superchat\",\n \"message\": [\n {\n \"id\": \"LCC.Cg8KDQoLWmpUemdzdU1vM2sSHAoaQ05PcW01UzJ3dElDRll2WkhBb2RLd0lBOWc0.028141892513880107\",\n \"channelId\": \"UCec4hVEu3ZXE8qlRtUeK0DA\",\n \"channelUrl\": \"http://www.youtube.com/channel/UCec4hVEu3ZXE8qlRtUeK0DA\",\n \"name\": \"Kappa Lord\",\n \"comment\": \"love the stream\",\n \"amount\": \"2000000\",\n \"currency\": \"USD\",\n \"displayString\": \"$2.00\",\n \"messageType\": 2,\n \"createdAt\": \"2017-08-22 00:51:57\",\n \"_id\": \"ad46c7e468331c5e39373e05876fa17e\"\n }\n ],\n \"for\": \"youtube_account\"\n}", "language": "json" } ] } [/block] Mixer Follow [block:code] { "codes": [ { "code": "{\n \"type\": \"follow\",\n \"message\": [\n {\n \"id\": 1816,\n \"name\": \"Jamacanbacn\",\n \"created_at\": \"2017-08-22 00:30:25\",\n \"_id\": \"4fbcdd82bc9fd39467572b24ee20a766\"\n }\n ],\n \"for\": \"mixer_account\"\n}", "language": "json" } ] } [/block] Mixer Subscription [block:code] { "codes": [ { "code": "{\n \"type\": \"subscription\",\n \"message\": [\n {\n \"id\": \"123456\",\n \"name\": \"h4r5h4\",\n \"months\": 2,\n \"message\": null,\n \"emotes\": null,\n \"since\": \"2017-08-22 00:36:59\",\n \"_id\": \"68f034214d68dce22431801b940d2b90\"\n }\n ],\n \"for\": \"mixer_account\"\n}", "language": "json" } ] } [/block] Mixer Host [block:code] { "codes": [ { "code": "{\n \"type\": \"host\",\n \"message\": [\n {\n \"name\": \"h4r5h47\",\n \"viewers\": \"5\",\n \"type\": \"manual\",\n \"_id\": \"4ee5fcf7e34128f4f07bb978c9e35fd4\"\n }\n ],\n \"for\": \"mixer_account\"\n}", "language": "json" } ] } [/block]