drab v0.4.1 Drab.Browser

Browser related functions.

Provides information about connected browser, such as local datetime, user agent.

Summary

Functions

Sends the log to the browser console for debugging

Broadcasts the log to the browser consoles for debugging/

Returns browser language

Returns a list of browser supported languages

Returns local browser time as NaiveDateTime. Timezone information is not included

Redirects to the given url

Broadcast version of redirect_to

Returns browser information (userAgent)

Returns utc offset (the difference between local browser time and UTC time), in seconds

Functions

console(socket, log)

Sends the log to the browser console for debugging.

console!(socket, log)

Broadcasts the log to the browser consoles for debugging/

language(socket)

Returns browser language.

Example:

iex> Drab.Browser.language(socket)  
"en-GB"
languages(socket)

Returns a list of browser supported languages.

Example:

iex> Drab.Browser.languages(socket)  
["en-US", "en", "pl"]
now(socket)

Returns local browser time as NaiveDateTime. Timezone information is not included.

Examples:

iex> Drab.Browser.now(socket)                                                  
~N[2017-04-01 15:07:57.027000]
redirect_to(socket, url)

Redirects to the given url.

WARNING: redirection will disconnect the current websocket, so it should be the last function launched in the handler.

redirect_to!(socket, url)

Broadcast version of redirect_to.

WARNING: redirection will disconnect the current websocket, so it should be the last function launched in the handler.

user_agent(socket)

Returns browser information (userAgent).

Examples:

iex> Drab.Browser.user_agent(socket)
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) ..."
utc_offset(socket)

Returns utc offset (the difference between local browser time and UTC time), in seconds.

Examples:

iex> Drab.Browser.utc_offset(socket)
7200 # UTC + 02:00