Skip to content

Releases: cayasso/primus-rooms

.empty, updates to primus .join .leave

08 Jan 23:49
Compare
Choose a tag to compare

.join(sparks, room) .leave(sparks, room)

This release adds some additional features to the already known join/leave server methods, you can now pass either a spark instance(as before), id or an array of sparks (instances or ids or a mix) to primus.join and primus.leave methods.

primus.join('1389028863093$0', 'news', fn);
primus.join([spark1, spark2, spark3], 'news', fn);
primus.join([spark1, spark2, spark3], 'news sport', fn);
primus.join(['1389028863093$0', '1389028863093$1', spark3], 'news sport', fn);

The same apply for leave:

primus.leave('1389028863093$0', 'news', fn);
primus.leave([spark1, spark2, spark3], 'news', fn);
primus.leave([spark1, spark2, spark3], 'news sport', fn);
primus.leave(['1389028863093$0', '1389028863093$1', spark3], 'news sport', fn);

empty

Remove all clients from a room or multiple rooms.

primus.room('sport').empty();
// or
primus.empty('sport');

or multiple rooms at the same time:

primus.room('news sport').empty();
// or
primus.empty('news sport');

Infinite recursion bug solved

This release also fixes an important bug reported by @ruimarinho #22

Check bellow for complete change log and thanks to all contributors.

Changelog

  • 8d7264 [doc] Documenting new primus join/leave features
  • e02e122 [feature] Allowing passing array of sparks to primus.join and primus.leave
  • 21e154e [feature] Adding an empty method to server #21
  • d437dc0 [minor] Refactoring and cleaning up methods
  • 37af1be [bug] Disabling broadcast flag on non brodcast methods #22
  • 4c8e1d2 [minor] Fixing typo
  • 458be39 [minor] Cleaning up examples
  • 4c24bcf Merge branch 'master' of https://github.com/cayasso/primus-rooms
  • b4ed030 [fix] Stop brodcasting from a destroyed spark
  • 6991b3e Merge pull request #20 from Dshankar/master
  • 87923fa minor fix on README for leaveallrooms event

New methods except, isRoomEmpty and primus.rooms

04 Dec 19:52
Compare
Choose a tag to compare

except

Broadcast messages to clients in a room except to those specified.

spark.room('room').except('1386018854525$0 1386018854526$1').write('hi');

or pass an array:

var except = ['1386018854525$0', '1386018854526$1'];
spark.room('room').except(except).write('hi');

This method works the same on the way on the spark object.

isRoomEmpty

This release also adds isRoomEmpty for checking to see if a room is empty:

On the server:

// on the server
primus.isRoomEpty('sport');
primus.in('sport').isRoomEpty();

// on the spark
spark.isRoomEpty('sport');
spark.in('sport').isRoomEpty();

primus.rooms

Now you can get all active rooms on the server or still get all rooms a spark is in with the same method, initially this method was only supported by the spark object.

primus.rooms();
primus.rooms(spark, fn);

There were also some bug fixes, test refactoring and documentation improvements, thanks to all who helped reporting and resolving issues @lpinca, @davedoesdev, @Dshankar.

Changelog

  • 06649cf [test] Some minor changes
  • 8efe49c [minor] primus.isRoomEmpty change
  • a29d8f9 [minor] clients method refactoring
  • 30d5899 [fix] Small correction
  • 7c11809 [fix] Small fix
  • f8db25e [doc] Adding primus.rooms documentation
  • c4d4d6f [feature] Adding primus.rooms method
  • b9525b9 Merge pull request #19 from Dshankar/master
  • 317b636 added getRooms
  • 2ad126f [doc] Documenting except on the server
  • 5f2b996 [feature] Adding except method to server
  • 82c07be [doc] Documenting isRoomEmpty and except
  • 96dfb3a [feature] Adding isRoomEmpty method to server
  • 9605989 [fix] Small fix
  • 838d23c [feature] Adding isRoomEmpty method
  • 502e391 [feature] Adding except method for brodcasting
  • 99a846f [test] Adding not allowed ack test
  • fc7f0aa [fix] Do not allow broadcasting messages with ack
  • a1e929e Merge pull request #17 from lpinca/test/chaining-support
  • 52a6bfd [test] Adding test for chaining support when sending to a room from server
  • ef6129b Merge pull request #16 from lpinca/tests
  • 45277bb [test] Removing a redundant test
  • 2176c8a [fix] Fixing some tests
  • 8e875b4 [doc] Adding primus-resource to plugins list

Server send method and changes to rooms namespace

05 Nov 04:22
Compare
Choose a tag to compare

Normalizing namespace

This release add some changes to normalize the rooms name space, the $ is used as a way to access the plugins namespaces directly, using the built-in primus.plugin('emitter') to obtain the plugin is a very handy alternative but if someone declare the plugin with a different name like primus.use('my-rooms', 'primus-rooms), this will make the other plugins like primus-multiplex, primus-emitter fail to recognize it, so as a way to avoid this issue the $ is used, ensuring that we will always get the right plugin event if it was declared with a different name.

New server send method

Now is possible to broadcast a message by using the new send method when the primus-emitter is defined, this is very handy in cases where you just want to broadcast to all users in a room or in various rooms at the same time. Checkout the new test cases for usage. https://github.com/cayasso/primus-rooms/blob/master/test/test.js

Server

// send message to all clients in room 'sport'
primus.in('sport').send('update', 'Brazil World Cup is near');

Client

primus.on('update', function(msg){
   console.log(msg); //-> Brazil World Cup is near'
});

Cheers,
JB

Broadcast messages to a room from the server

19 Sep 06:32
Compare
Choose a tag to compare

This release adds the ability to broadcast to room from the primus server itself.

primus.room('sport').write('hi');

or

primus.in('sport').write('hi');

This will send "hi" to all clients in the "sport" room.

Another addition is that you can now use the join and leave methods directly from the Primus server instance:

primus.join(spark, 'sport', fn);

and

primus.leave(spark, 'sport', fn);

Best,
JB