Class: PeerGroup

PeerGroup(onError, options)

PeerGroup (project name Peer.js Groups) is an abstraction layer over the Peer.js library that allows peers to easily find and communicate with other peers that share an interest in a common group ID tag (e.g. a chat room name or a gaming session name).

Constructor

new PeerGroup(onError, options)

Constructs a PeerGroup object.
Parameters:
Name Type Description
onError PeerGroup~ErrorCallback A function that will be invoked if a networking error occurs that Peer.js Groups cannot handle internally.
options object The options passed to the Peer.js server.
Source:
See:

Members

(static) validSessionID

Specifies what string are valid session IDs.
Source:

Methods

acceptUser(newUserID)

Authorizes a peer to join the peer group.
Parameters:
Name Type Description
newUserID string The user ID of a peer (typically one that is waiting to join the peer group).
Source:

connect(sessionIDToJoin, myUserID)

Attempts to connect to a peer group, or creates the group if it doesn't exist yet.
Parameters:
Name Type Description
sessionIDToJoin string The name of the peer group to try to join.
myUserID string The identifier this peer would like to be known by.
Source:

disconnect()

Disconnects from the peer group (if connected to one) or cancels any pending application to join a peer group.
Source:

rejectUser(remoteUserID)

Prevents a peer with a given user ID from joining the peer group or removes an existing member from the peer group.
Parameters:
Name Type Description
remoteUserID string The user ID of a peer belonging to the peer group or the user ID of a peer waiting to join the peer group.
Source:

send(data)

Sends a message to all members of the peer group.
Parameters:
Name Type Description
data any The data to send.
Source:

sendPrivate(destUser, data)

Sends a message to a particular user.
Parameters:
Name Type Description
destUser string The user ID to send the data to.
data any The data to send.
Source:

Type Definitions

ErrorCallback(error)

Parameters:
Name Type Description
error Error The error that occurred.
Source:

Events

connected

Fired when a peer establishes a connection with the peer group leader (which may be itself). The event is fired on the peer that initiated the connection. The peer doesn't receive any messages addressed to the peer group until after the PeerGroup~event:joined event has been fired.
Type:
Source:

ejected

Fired when this peer is refused permission to join the requested peer group or when it's forcibly removed from the peer group.
Type:
Source:

joined

Fired when the local peer becomes a member of a peer group.
Type:
Source:

joinrequest

Fired when this peer is the peer group leader and another peer asks to join the peer group. If no event listeners have been added to listen for this event then any peer that connects to the group will automatically be accepted as a new member. If you add a listener and later remove it then no new peers will able to join the group until you add another listener (or invoke acceptUser in another context).
Type:
Source:

message

Fired when this peer receives a message (either addressed to the peer group or private).
Type:
Source:

userleft

Fired when the connection to another peer is severed.
Type:
Source:

userpresent

Fired when another peer joins the peer group, or when the local peer joins the peer group and discovers existing members.
Type:
Source: