Skip to content
This repository has been archived by the owner on Jan 7, 2019. It is now read-only.

The current user's special object

Pablo Tejada edited this page Sep 8, 2013 · 7 revisions

The current user's object is an special hybrid object. As of v1.1 the current user's object has it own constructor and prototype, APS.cUser. This object can directly receive events so it has a few methods that a channel would have like on(), trigger(), log(). Therefore the channel's events message and data also apply to this object. Since the current user can not send events or publish to itself the methods pub() and send() are not present.

The update() method is unique to the current object user object. This method changes a public property of the user. For example assuming the the user has a property status. If you change the the status like

	client.user.status = "playing";

The change would only be visible in the current instance of the client, it wont propagate to other clients. In the other hand:

	client.user.update("status", "playing");

Will change the status property while it will also send the update to the server for propagation. The server will then send updates to all clients where a user reference exists.

Also if you want to listen or watch for property change such as status you could add the following event handler:

	client.user.on("userStatusUpdate", function(newValue, function( newValue ){
		alert("Current User status changed to: " + newValue);
	});

for more info in user properties event listeners check the Events list - userUpdate

Clone this wiki locally