{"_id":"56acedfed21f1b0d00fd2f70","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"},"user":"56acd6caa040860d00ac94a2","githubsync":"","parentDoc":null,"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"},"__v":4,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-01-30T17:08:14.845Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":1,"body":"[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"OAuth Credentials Needed!\",\n  \"body\": \"Remember Singularity uses OAuth2 credentials to connect and to request channel data. So make sure you review the \\\"Registering an Application\\\" and the \\\"Connecting to a GameWisp Channel\\\" sections of the docs if you haven't yet.\"\n}\n[/block]\nSingularity can be accessed by both client and server side applications. This minimal example was taken from the[ SocketIO-client-app](https://github.com/GameWisp/GameWisp-Singularity-Examples/tree/master/examples/SocketIO-client-app) example.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<!doctype html>\\n<html>\\n    <head>\\n        <script src=\\\"https://cdn.socket.io/socket.io-1.2.0.js\\\"></script>\\n\\n        <script>\\n\\n            // Do not expose your secret! \\n            var devCredentials = {\\n                key: \\\"<OAuth Client ID>\\\",\\n                secret: \\\"<OAuth Client Secret>\\\"\\n            };\\n\\n            var socket = io(\\\"https://singularity.gamewisp.com\\\");\\n\\n            socket.on(\\\"connect\\\", function(){\\n\\n                socket.emit(\\\"authentication\\\", \\n                    {\\n                        key: devCredentials.key, \\n                        secret: devCredentials.secret,\\n                    }\\n                );\\n\\n                socket.on(\\\"authenticated\\\", function(data) {\\n                    socket.emit(\\\"channel-connect\\\", {\\n                       access_token: \\\"<Channel OAuth Token>\\\"\\n                    });\\n\\n                    socket.on(\\\"app-channel-connected\\\", function(response){\\n                        //...                    \\n                    });\\n\\n                    socket.on(\\\"event-of-interest\\\", function(response){\\n                        //...\\n                    });\\n                });\\n              \\t\\n              \\t//listen to the unauthorized event in case your client auth\\n              \\t//fails.\\n                socketClient.on('unauthorized', function(err){\\n                  console.log('Authentication error: ' + err.message);\\n                });\\n            });\\n        </script>\\n    </head>\\n    <body>\\n    </body>\\n</html>\",\n      \"language\": \"html\"\n    }\n  ]\n}\n[/block]","excerpt":"A basic Singularity client-side example","slug":"quick-start","type":"basic","title":"Quick Start"}

Quick Start

A basic Singularity client-side example

[block:callout] { "type": "info", "title": "OAuth Credentials Needed!", "body": "Remember Singularity uses OAuth2 credentials to connect and to request channel data. So make sure you review the \"Registering an Application\" and the \"Connecting to a GameWisp Channel\" sections of the docs if you haven't yet." } [/block] Singularity can be accessed by both client and server side applications. This minimal example was taken from the[ SocketIO-client-app](https://github.com/GameWisp/GameWisp-Singularity-Examples/tree/master/examples/SocketIO-client-app) example. [block:code] { "codes": [ { "code": "<!doctype html>\n<html>\n <head>\n <script src=\"https://cdn.socket.io/socket.io-1.2.0.js\"></script>\n\n <script>\n\n // Do not expose your secret! \n var devCredentials = {\n key: \"<OAuth Client ID>\",\n secret: \"<OAuth Client Secret>\"\n };\n\n var socket = io(\"https://singularity.gamewisp.com\");\n\n socket.on(\"connect\", function(){\n\n socket.emit(\"authentication\", \n {\n key: devCredentials.key, \n secret: devCredentials.secret,\n }\n );\n\n socket.on(\"authenticated\", function(data) {\n socket.emit(\"channel-connect\", {\n access_token: \"<Channel OAuth Token>\"\n });\n\n socket.on(\"app-channel-connected\", function(response){\n //... \n });\n\n socket.on(\"event-of-interest\", function(response){\n //...\n });\n });\n \t\n \t//listen to the unauthorized event in case your client auth\n \t//fails.\n socketClient.on('unauthorized', function(err){\n console.log('Authentication error: ' + err.message);\n });\n });\n </script>\n </head>\n <body>\n </body>\n</html>", "language": "html" } ] } [/block]