Skip to content

Instantly share code, notes, and snippets.

@colinmacdonald
Created March 5, 2014 20:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save colinmacdonald/9376397 to your computer and use it in GitHub Desktop.
Save colinmacdonald/9376397 to your computer and use it in GitHub Desktop.
GoInstant REST API (REST CLIENT) - Channel Example
<!doctype html>
<html>
<head>
<script src="https://cdn.goinstant.net/v1/platform.min.js"></script>
<script>
var url = "https://goinstant.net/youraccount/yourapp"; // replace with your account and app
goinstant.connect(url, function(err, conn, room) {
if (err) {
throw err;
}
console.log('joined room:', room.name);
var channelA = room.channel('myChannelA');
var channelB = room.channel('myChannelB');
channelA.on('message', function(msg) {
console.log('chanA', msg);
});
channelB.on('message', function(msg) {
console.log('chanB', msg);
});
});
</script>
</head>
<body>
</body>
</html>
// npm install goinstant-rest
var GoInstant = require('goinstant-rest').v1;
// id and secret from here: https://goinstant.com/dashboard/credentials
var client = new GoInstant({
client_id: 'id',
client_secret: 'secret'
});
var APP = 'yourapp'; // replace with your app name
var ROOM = 'lobby';
var chanA = {
app_id: APP,
room_id: ROOM,
channel: 'myChannelA',
value: 0
};
var chanB = {
app_id: APP,
room_id: ROOM,
channel: 'myChannelB',
value: 0
};
setInterval(function() {
client.channels.message(chanA, function(err, value) { console.log('chanA message sent'); });
chanA.value++;
}, 2000);
setInterval(function() {
client.channels.message(chanB, function(err, value) { console.log('chanB message sent'); });
chanB.value--;
}, 5000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment