Private Functions

This document will help you understand what the private functions of plugged do so you can better understand what when happens, certainly not a must read but a nice to have.

Functions

_checkForPreviousVote

Checks if a vote has changed. This prevents the system from adding multiple votes to the state by a single user.

Parameters:

vote: Vote checks if a User’s vote has changed

Return Value:

Boolean true when the vote hasn’t changed or is new, false otherwise

_clearState

Resets the internal state.

Parameters:

undefined

Return Value:

undefined

_clearHeartbeat

Resets the heartbeat state.

Parameters:

undefined

Return Value:

undefined

_cleanUserCache

Removes all expired users from cache. Every user is cached for 5 minutes before their object will be disposed from cache, this is triggering a cleanup.

Parameters:

undefined

Return Value:

undefined

_connectSocket

Connects to the WebSocket.

Parameters:

undefined

Fires:

SOCK_OPEN SOCK_CLOSED SOCK_ERROR

Return Value:

undefined

_getAuthToken

Retrieves auth token.

Parameters:

data: Object placeholder

callback: Function

Return Value:

undefined

_getCSRF

Gets csrf token.

Note

This is one form of a prevention for a Man in the Middle Attack (short MitM). This token is only relevant for login, after that you’ll not need it anymore which is the reason why this call is only successful before you logged in.

Parameters:

credentials: Object login data to use.

callback: function called on retrieval.

callback:

err: String possible error returned.

credentials: Object login data to use.

csrf: String the token.

Return Value:

undefined

_keepAlive

Function that gets called by _heartbeat to check if the connection to the server is still open. The check happens by a constant delta offset. If the server hasn’t responded after 4 checks the connection will be reset by the client.

Parameters:

undefined

Fires:

CONN_WARNING after every failed check

CONN_PART after 6 consequent fails

Return Value:

undefined

_heartbeat

Calls _keepAlive for consequent checks of an etablished server connection.

Parameters:

undefined

Return Value:

undefined

_log

Internal logging function that calls the invoked logger.

Parameters:

number verbosity level of message

string message to be logged

Return Value:

undefined

_loggedIn

Last step in the login chain, this finally sets up the WebSocket connection and sets the initial state.

Parameters:

function callback

Return Value:

undefined

_login

Logs user in with the given credentials.

Parameters:

credentials: Object account information

callback: Function callback

tries: Number amount of unsuccessful tries

Return Value:

undefined

_processChatQueue

Processes a chat message from the buffer and sends it off to the server with some delay. The delay is set after the amount of messages that was sent in the past few seconds. If no messages were sent for a while, the delay will be reset to zero.

Parameters:

lastMessage: Number unix time when last message was sent.

Return Value:

undefined

_removeChatMessageByDelay

Delete a chat message based on its body. This is used by _processChatQueue when a message has the removal tag set.

Parameters:

message: String message to delete

Return Value:

undefined

_removeChatMessage

Delete a chat message. This is the core function of all chat deletion methods. It takes a function (comparator) which decides whether a message should be deleted or not.

Parameters:

compare: Function comparing function to decide whether a message should
be deleted. The passed parameter is the chat message</datatypes/chat> object

cacheOnly: Boolean if the message should only be deleted in cache

count: Number how many messages should be removed before the function
quits. If not set, it will run through the whole chat cache. Default is -1 as in unlimited.

Return Value:

Number amount of messages deleted

_sendMessage

Sends a message to the server via WebSocket.

Parameters:

type: String message type

data: String|Number JSON encoded data

Return Value:

Boolean true when the message was sent successfully

_setLogin

Logs an account in.

Parameters:

credentials: Object login data to use.

csrf: String cross site request forgery token.

callback: function called on retrieval.

callback:

err: String possible error returned.

Return Value:

undefined

_eventProcessor

It processes every message received by the WebSocket and turns them into events and data.

Parameters:

msg: String JSON encoded message as String

flags: Object contains two Boolean options, binary and masked

Fires:

  • ADVANCE
  • BAN
  • BAN_IP
  • CHAT
  • CHAT_COMMAND
  • CHAT_DELETE
  • CHAT_MENTION
  • CHAT_RATE_LIMIT
  • CONN_SUCCESS
  • CONN_ERROR
  • DJ_LIST_CYCLE
  • DJ_LIST_LOCKED
  • EARN
  • FLOOD_API
  • FLOOD_CHAT
  • FRIEND_ACCEPT
  • FRIEND_JOIN
  • FRIEND_REQUEST
  • GIFTED
  • GRAB
  • GUEST_JOIN
  • GUEST_LEAVE
  • KILL_SESSION
  • LEVEL_UP
  • MAINTENANCE_MODE
  • MAINTENANCE_MODE_ALERT
  • MOD_ADD_DJ
  • MOD_BAN
  • MOD_MOVE_DJ
  • MOD_MUTE
  • MOD_REMOVE_DJ
  • MOD_SKIP
  • MOD_STAFF
  • NAME_CHANGED
  • NOTIFY
  • PLAYLIST_CYCLE
  • ROOM_DESCRIPTION_UPDATE
  • ROOM_MIN_CHAT_LEVEL_UPDATE
  • ROOM_NAME_UPDATE
  • ROOM_WELCOME_UPDATE
  • SKIP
  • USER_JOIN
  • USER_LEAVE
  • VOTE
  • WAITLIST_UPDATE

Return Value:

undefined