Skip to main content

PHP reference

Markdown

Everything is on wordplus_realtime(), the newest copy of the package on the site. Call it from plugins_loaded on.

Rooms​

MethodReturns
room( $pattern, $rule = null, $options = array() )$thisowns the rooms whose names match $pattern (order:{id}). $rule( $user_id, $params, $room ) answers false, true, or array( 'info' => …, 'emit' => …, 'readOnly' => … ). $options: presence, count, history, emit, webhook, public, seal (rooms, presence)
on( $type, $handler )$thiswhat the realtime server webhook brings: a page event by its name, room.occupied, room.vacated, member.joined, member.left, user.online, user.offline, call.ended, group.joined, group.left, stream.live, stream.ended, or * (sending)
to( $rooms )->except( $tab )->emit( $event, $data = null, $options = array() )ids by room, or WP_Erroran event to up to 1,000 rooms, kept where they keep history. $options['seal'] false sends it plain (sending)
to_user( $users )->emit( $event, $data = null )ids, or WP_Erroran event to every connection of the users, sealed with the key of each
batch( $events )the ids of each, or WP_Errorseveral emits, each rooms, users, event, data, except, seal
in( $room )WordPlus_Realtime_Roomcount(), members(), history( $ask ), forget( $id = null ), kick( $user )
online()WordPlus_Realtime_Onlinehas( $user ), count(), list( $cursor, $limit ), states( $users )
list_rooms( $page = array() )array, or WP_Errorthe rooms someone is in now: count, rooms (name, count, connections), next. $page: prefix, cursor, limit (sending)
for_user( $id )WordPlus_Realtime_Userget(), disconnect(), ask( $event, $data, $options ): their state, out of everything at once, and their pages asked (sending)
usage()array, or WP_Errorconnections (now, limit) and the credits of the account
webhooks()WordPlus_Realtime_Webhooksdeliveries(), resend( $id ), test()
list_calls(), call( $name )array, WordPlus_Realtime_Callthe group calls going on, and get(), mute( $user, $track ), permit( $user, [ 'publish' => true ] ), remove( $user ), end()
list_streams(), stream( $name )array, WordPlus_Realtime_Streamthe streams live now, and get(), people(), chat( $limit ), say( $text, $name, $avatar ), delete_message( $id ), clear_chat(), pin( $id ), slow( $seconds ), timeout( $user, $seconds ), untimeout( $user ), kick( $user ), ban( $user ), unban( $user ), bans(), reactions( $on ), end() (live streams)
tab()stringthe tab that asked, from the page X-Realtime-Tab header, for except()
authorize( $rooms, $user_id )arraywhat the auth route answers: token, exp, keys, denied
public_grants()arraythe grant of the public rooms with no rule, which every page carries
may_join( $room, $user_id )boolwhether the room rule lets the user in, as the auth route asks it
room_options( $room )array or nullthe options of a room, with their defaults and the cloud limits
webhook( $raw, $headers, $path )true or WP_Errora webhook as it came, checked and handed to the handlers: what the webhook route does
script()handlethe page script with its settings in window.wordplusRealtimeConfig. An empty handle on a site without credentials

Calls​

MethodReturns
calls( $pattern, $rule, $options = array() )$thisowns the calls between two people whose names match $pattern. $rule( $user_id, $with, $params, $call, $side ) answers false, true, or array( 'info' => … ) (calls). $side['role'] is caller or callee: which side asks. $options['people']: a callable ( $user_id, $call ) answering the user ids the call screen offers to add (the call screen)
group_calls( $pattern, $rule, $options = array() )$thisowns the group calls whose names match $pattern. $rule( $user_id, $params, $name ) answers false, true, or array( 'info' => …, 'publish' => …, 'subscribe' => …, 'admin' => …, 'hidden' => … ), admin making them its host (the host). $options['encrypt']: true to encrypt their media end to end (group calls)
streams( $pattern, $rule, $settings = array() )$thisowns the live streams whose names match $pattern. $rule( $user_id, $params, $name ) answers false, a role (host, viewer), or array( 'role' => …, 'info' => …, 'chat' => …, 'mod' => …, 'src' => …, 'quality' => … ). $user_id 0, a visitor, is a viewer at most. $settings: stage, reactions, people, chat (offline, links, fresh), each a value or a callable of the parts of the name (live streams)
calls_script()handlethe calls script, window.wordplusRealtimeCalls, after the page script. The empty handle without credentials
call_screen( $args = array() )boolloads the call screen and the other ready-made parts on the page. $args['ring'] false: nothing rings on it
ui()boolthe ready-made parts on a page where nothing rings
stream_screen()boolloads the live stream elements, <live-stream> and <stream-studio>, on the page. Calls ring as they did (live streams)
stream_element( $name, $attributes = array() )stringa <live-stream> for the stream $name, escaped, after the site prefix, or <stream-studio> for 'view' => 'studio'. $attributes: view, title, cover, url, login-url, studio-url, chat, height, sticky
screen()arraythe screen settings: lang, strings, add, and prefix when the site sets one
element_prefix()stringthe site prefix for the element names, from wordplus_realtime_element_prefix. Empty for their own
element_name( $tag )stringan element name on this site: chat-room, or shop-chat-room
call_user()intwho takes part in calls on this page: user()
authorize_call( $request, $user_id )arraywhat the calls route answers: token, exp, key, pair and member for a call (and ring for a ring into it), media_key for the rooms of a call and an encrypted group call, token and exp for a stream, people for array( 'people' => $call ), may for array( 'may' => … ), done for a host act, or denied
WordPlus_Realtime::call_key( $id, $caller, $callee )stringthe key the two pages of a call seal their negotiation with

Keys and the site users​

Encryption explains them. On wordplus_realtime()->keys():

MethodReturns
seal( $value, $label ), seal_json( $data, $label )string or nulla value sealed with the key of a label: only those who may have that key open it
open( $value )string or nullwhat a value this site sealed holds. null for anything else or anything changed
WordPlus_Realtime_Keys::label_of( $value )string or nullthe label of the key that opens a sealed value
day_label(), user_label( $user_id ), room_label( $room )stringthe day key, the key of a user, the newest key of a sealed room
rotate_user( $user_id ), rotate_room( $room )the next key, which someone who lost access never gets
kind( $kind, $may_have, $newest = null )$thiskeys of your own, {kind}:{…}: $may_have( $rest, $user_id, $label ) says who may have one. $newest( $rest, $label ) names the newest of the same thing
may_have( $label, $user_id )boolwhether the user may have a key
media( $what )stringthe key the media of a room is encrypted with: `call
proof( $what )stringa proof only the site makes, that a user is in a call or was rung into it (calls)
entry( $label )stringa key as the site hands it to a browser
user_entries( $user_id )string[]the keys a user starts with: their own, and the day keys from yesterday to tomorrow
profile( $user_id )array or nullthe user entry in the site directory, sealed (pd, pdh)
sealing()boolwhether the site seals (wordplus_realtime_seal)

And on wordplus_realtime():

MethodReturns
user()intwho the site knows on this request: the signed-in user, a visitor negative id (wordplus_realtime_visitor_id), or 0
identity( $user_id )array( 'token', 'exp' ) or nullwho the user is for the realtime server, with their directory entry, signed as the site

The site​

MethodReturns
available()boolthe site has its credentials
credentials()array( 'key', 'secret' ) or nullthe site key and the secret to sign with now
site_key()stringthe site key, or ''
connect()->url( $return_to )URLThe WordPlus Cloud approval, back to $return_to with wordplus_realtime=connected, denied or failed
server(), api_server()URLwhere browsers connect, and where the site requests go
config()arraywhat the page gets in window.wordplusRealtimeConfig
version()stringthe version of this copy

Routes​

Route
POST /wp-json/wordplus/v1/realtime/auth{ rooms } → { token, exp, keys?, denied }
POST /wp-json/wordplus/v1/realtime/calls{ line: true }, { call, id, role, to or from, type }, { room, type } or { stream } → { token, exp, key? } or { denied }. { people } → { people }, { may } → { may }, and a host act { moderate, act, user } → { done }
POST /wp-json/wordplus/v1/realtime/keys{ labels } → { keys }, those the user may have. { labels: [] } → the keys they start with and their identity
POST /?rest_route=/wordplus/v1/realtime/webhookfrom the realtime server, signed with the site webhook key: { events } → 204

Anyone may ask the first three. Your rules decide. A refusal is an answer, not an HTTP error.

Filters​

FilterDefault
wordplus_realtime_token_ttl21600the life of a room token in seconds, at most a day
wordplus_realtime_call_token_ttl21600the lifetime of a calls token, at most 6 hours
wordplus_realtime_visitor_id0the id of a visitor, a negative number: who joins presence rooms, takes part in calls and gets keys
wordplus_realtime_hiddenfalsetrue keeps a user out of who is online ($hidden, $user_id)
wordplus_realtime_sealtruewhether what the site sends through WordPlus Cloud goes sealed
wordplus_realtime_user_has_keystruefalse keeps every key from a user you cut off ($has, $user_id)
wordplus_realtime_profilename, avatar, author pagea user entry in the site directory ($profile, $user_id). Text is sealed
wordplus_realtime_screen_stringsnonethe screen words by their English text
wordplus_realtime_element_prefixnonea name of the site before every element name: shop makes <shop-call-button> (the call screen)
wordplus_realtime_configthe page settingswhat script() gives the page ($config, $user_id). 'perUser' => true gives each user a connection of their own, for a browser that may hold several
wordplus_realtime_serverhttps://ws.wordplus.cloud/where browsers connect
wordplus_realtime_api_serverhttps://rest.wordplus.cloud/where the site requests and the leave of a closing page go
wordplus_realtime_accounthttps://www.wordplus.cloud/where Connect sends the administrator
wordplus_realtime_account_apihttps://api.wordplus.cloud/where the Connect code is exchanged

The option​

The credentials live in wordplus_cloud_license, which every WordPlus plugin on the site shares: on a network, that of the network when the site has none. The package only reads it, but Connect writes it.

The master key every other key is derived from lives in wordplus_realtime_master_key, that of the network on a network. It never leaves the site. Deleting it changes every key, and what was sealed before no longer opens.