Created
March 5, 2014 20:56
-
-
Save colinmacdonald/9376397 to your computer and use it in GitHub Desktop.
GoInstant REST API (REST CLIENT) - Channel Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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