Open coxley opened 9 years ago
Yup, it's not documented as we're still ironing it out. Basically you listen to a socket.io event for messages:new
after you send the server room:join
.
Here's an example:
'use strict';
var socket = require('socket.io-client');
var io = socket(YOUR_SERVER_URL_GOES_HERE, {
autoConnect: true,
reconnect: true,
query: {
token: YOUR_TOKEN_GOES_HERE
}
});
io.on('connect', function() {
console.log('connected!');
io.emit('rooms:list', function(rooms) {
console.log('Found', rooms.length, 'rooms');
});
io.emit('rooms:join', YOUR_ROOM_ID_GOES_HERE, function(room) {
console.log('joined', room.name);
});
io.on('messages:new', function(message) {
console.log('<' + message.owner.username + '>:', message.text);
});
});
I should also add that you can connect very easily with any language/platform that has a socket.io client library (Ruby, Python, etc).
Are the events/commands documented to for if you wanted to send messages?
@coxley not at this moment.
If you want to create a new message, something like this would work:
io.emit('messages:new', {
room: SOME_ROOM_ID,
text: SOME_TEXT
});
Could you mimic a user like that?
What do you mean?
Whatever token you give it will always belong to a user.
The REST API seems great to fit most use cases, just wondering if there's a way to perhaps get a consistently updated stream of chats for a room since you probably wouldn't want to just keep issuing GETs and risk being out of order.