Skip to content

Commit fd85b73

Browse files
author
Alec Gibson
committed
Make local presence ID optional
Local presence IDs should be unique. If consumers do not want the responsibility of taking care of this (and don't care about what ID is assigned to them), then we will automatically assign a random ID for them.
1 parent 9e19efb commit fd85b73

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ presence.create(presenceId): LocalPresence;
707707

708708
Create an instance of [`LocalPresence`](#class-sharedblocalpresence), which can be used to represent local presence. Many or none such local presences may exist on a `Presence` instance.
709709

710-
* `presenceId` _string_: a unique ID representing the local presence. Remember - depending on use-case - the same client might have multiple presences, so this might not necessarily be a user or client ID.
710+
* `presenceId` _string (optional)_: a unique ID representing the local presence. Remember - depending on use-case - the same client might have multiple presences, so this might not necessarily be a user or client ID. If one is not provided, a random ID will be assigned for you.
711711

712712
#### `destroy`
713713

lib/client/presence/presence.js

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var LocalPresence = require('./local-presence');
33
var RemotePresence = require('./remote-presence');
44
var util = require('../../util');
55
var async = require('async');
6+
var hat = require('hat');
67

78
module.exports = Presence;
89
function Presence(connection, channel) {
@@ -35,6 +36,7 @@ Presence.prototype.unsubscribe = function(callback) {
3536
};
3637

3738
Presence.prototype.create = function(id) {
39+
id = id || hat();
3840
var localPresence = this._createLocalPresence(id);
3941
this.localPresences[id] = localPresence;
4042
return localPresence;

0 commit comments

Comments
 (0)