Socketize.js Full Reference

Authentication

register()

Registers a user.

Arguments

credentials - a JSON object containing user's email, username and password. Password is optional, in this case user will be able to login with payload only.

Response

{
    email: user@email.com,
    username: username,
    created_at: datetime,
}

Example


showRegisterPopup()

Shows a popup/modal to make your users easily signup.

Return

void

Response

No response as no request is sent.


login()

Logs a user in using email/username and password if credentials are correct.

Arguments

credentials - a JSON object containing email/username and password.

Response

{
    email: user@email.com,
    username: username,
    created_at: datetime,
}

Example


auth()

Logs a user in using email/username and payload if credentials are correct.

Arguments

credentials - a JSON object containing email/username and payload.

Response

{
    email: user@email.com,
    username: username,
    created_at: datetime,
}

Example


showLoginPopup()

Shows a popup/modal to make your users easily sign in.

Arguments

None

Return

void


logout()

Logs out the logged in user.

Arguments

None

Response

true

__

isLoggedIn()

Returns if user logged in or not.

Arguments

None

Return

true or false

Example


getUser()

Get the logged in user's information.

Arguments

None

Return

{
    email: user@email.com,
    username: username,
    created_at: datetime,
}

Example


Write

set()

Saves a value to Socketize database against a key.

Arguments

key - a string to identify the value.

value - a string, JSON array or JSON object.

Response

true

Example


pushOnList()

Appends the a value to the list, list is created if it doesn't exist.

Arguments

key - a string to identify the list.

value - JSON object(associative array).

Response

true

Example


Read

get()

Gets a value from Socketize database against a key.

Arguments

key - the identifier of the value.

Response

Value, as it was stored. Null if key doesn't exist.

Example


getListItems()

Gets the values/items from the list against a key.

Arguments

key - the identifier of the list.

Response

Array of list items. Null if key doesn't exist.

Example


searchList()

Gets the values/items from the list against a key.

Arguments

key - the identifier of the list.

query - an array of query arrays. like [ ['name', '=', 'foo'], ['city', 'like', 'Syl%'] ]. Supported operators are =, !=, <, >, like, regex.

Response

Array of list items.

Example


Realtime

subscribe()

Subscribes for an event.

Arguments

channel (event name) - a string to identify the event.

callback - a callback to be fired when something is published to the event.

Response

true

Example


publish()

Publishes data to event subscribers.

Arguments

channel (event name) - a string to identify the event.

data - data to be passed to subscribers, can be a string, JSON object or JSON array.

Response

Total number of subscribers to the event

Example


subscribeToKey()

Subscribe to a key, you will be notified when the value against the key is changed.

Arguments

key - a string as an identifier of the value. Can be scoped too, like public/messages.

callback - a callback to be fired when the value associated with the key is changed.

options - pass subscription options, like {ignore_me: false}

Response

None

Example


Other

ping()

Just sends a ping request to server to check if everything is working.

Arguments

None.

Response

pong


on()

Listens to various local events in Socketize.js.

Supported events:

on('success', function() {})

Fired when application has made first successful contact with the server and initialization params are valid.

on('fail', function() {})

Fired when application is unable to make first contact with the server or initialization params are invalid

on('login', function(user) {})

When a user is successfully logged in.

on('register', function(user) {})

When a user is successfully registered.

on('logout', function() {})

When a user has logged out.

on('disconnect', function() {})

When a connection with the server is interrupted. Socketize automatically tries to reconnect in this case.

on('close', function() {})

When a connection with the server is closed and will not reconnect.

Arguments

event - a string.

callback - an action or callback which will be fired when event occurs.

Example


request()

You can send any command to Socketize server, almost all Socketize.js methods are wrapper on top of this. This will be useful when Socketize adds a new command it's not available as a method in your Socketize.js. An example to execute pushOnList() through this method:

var params = {
    key: key,
    value: value
};
socketize.request('push_on_list', params);

Arguments

command - a string to specify name of the command you want to execute (snake cased).

params - a JSON object of params to be passed to server.

Response

Depends on the command.