Session API
The Webfuse Session API provides a set of functionality allowing you to start and control the behaviour of your Virtual Sessions.
There are three contexts to gain access to the Session API:
- Via Widget – After having initialized a new Session using the Widget (
browser.webfuse
). - Via Extension – Within Extension script components (
browser.webfuseSession
). - From within the currently augmented application – Only properties and methods marked as public are available on the
webfuse.currentSession
namespace.
started
Section titled “started”Returns true
if the session window is opened.
webfuseSession.started: boolean
Contains a 4-digit PIN code that can be used to join the session. This becomes available only after the session is started.
webfuseSession.pin: string
If a session is opened in an iframe, it contains a reference to its DOM node.
webfuseSession.node: HTMLIFrameElement
window
Section titled “window”Reference to the Session window (either tab window or contentWindow of the iframe container)
webfuseSession.window: Window
General Functionality
Section titled “General Functionality”relocate()
Section titled “relocate()”Navigate current tab to newUrl
, which must begin with a protocol, such as https://
. If newTab
is set to true
, the link will open a new virtual tab inside the Session window.
webfuseSession.relocate(newUrl: string, newTab: boolean): void
uploadFile()
Section titled “uploadFile()”Uploads a file to the current Session which will be opened in a new tab. A file input element can be used to pass the file to the method.
webfuseSession.uploadFile(file: File): void
getSessionInfo()
Section titled “getSessionInfo()”Returns an object containing information related to the current Session and sends it to the widget and all Extensions in the Session:
webfuseSession.getSessionInfo(): void
{ "sessionId": "<session_id>", "opentokSessionId": "<opentok_session_id>", "space": { "access_control": "public", "company_id": 1, "domain": "<space_domain>", "host_rights": "everyone", "id": 1, "identification": "anonymous", "is_paused": false, "link": "<space_url>", "name": "test", "slug": "test", "type": "meeting", "visibility": "members-only" "adminIds": [9, 1], "memberIds": [] }, "metadata": { "foo": "bar" }}
end() public
Section titled “end() ”Gracefully end the current Session (as long as the current user has permissions to do so).
webfuseSession.end(redirectUrl?: string): void
If specified, redirectUrl
should be a valid URL string. The user will be redirected there after the Session ends. The exception is when end_of_session_popup_url
settings is set. In this case, it will have priority over redirectUrl
.
Note that by default a user is redirected to the page that was last visited inside the Session.
Audit Functionality
Section titled “Audit Functionality”log() public
Section titled “log() ”Log custom message to the audit log. entry
must be a plain JSON object. Can be used to track your user’s steps during co-browsing. Handy for metrics and reveiling pain points on your website.
The entry
object can contain arbitrary keys, but there are several reserved keys with special meaning.
webfuseSession.log(entry: object):
Reserved Keys
Section titled “Reserved Keys”varN
- (where N is a natural number from 0 to 9) when provided, must have a string value. These variables can be referenced and used in visualization later on.
takeScreenshot()
Section titled “takeScreenshot()”Async method which uses browser native API to take screenshot of a page/window/screen. If successful sends an event to widget and Session Extensions with image data as ImageBitmap
and returns same value.
webfuseSession.takeScreenshot(keepStreamOpened: boolean): Promise<ImageBitmap>
Parameters
Section titled “Parameters”keepStreamOpened
- If
true
allows to avoid permission request popup showing up on every call, until current stream track is closed manually by user (defaulttrue
).
Returns
Section titled “Returns”A promise that resolved to the screenshot image bitmap object.
Messaging & Event Handling
Section titled “Messaging & Event Handling”on() public
Section titled “on() ”Use this to set an Event handler. Inside the callback
function, this
will be set to the current session
instance.
webfuseSession.on(eventName: string, callback: (message: unknown) => void)
Returns a reference to the current session
, so chained calls are possible:
const session = space.session();session.on('session_started', session => {})
sendMessage() public
Section titled “sendMessage() ”This function is useful when you need to establish a communication channel between your JS code on the original page, and its proxified version inside the Session.
webfuseSession.sendMessage(message: unknown, targetOrigin: string): void
It is available on both sides, and works in symmetric way: it will trigger a message
event on the other side of the channel.section).
message
argument must be a plain JSON-serializable object.
targetOrigin
should be set to the
origin
of the expected recipient. If set to "*"
, message will be delivered regardless
of the recipient’s origin.
if (!webfuse.isInsideSession) { // From outside a co-browsing window, send a message to the co-browsing window var endBtn = document.getElementById('btn-end-queued-session'); endBtn.addEventListener('click', function () { webfuse.listSessions()[0].sendMessage({ message: 'end' }, window.location.origin); });} else { // Check the cobrowsing Session and set the message event listener webfuse.currentSession.on('message', function (session, event) { if (event.data.message === 'end') { // reply to the message sessionEnd(); } });}
broadcastMessage()
Section titled “broadcastMessage()”Broadcast a message to all participants in the Session which will be receivable by all Extension components.
webfuseSession.broadcastMessage(message: string): void
Parameters
Section titled “Parameters”message
- The message to broadcast.
sendChatMessage()
Section titled “sendChatMessage()”Send a message to the chat. Available if chat_enabled
option is enabled.
webfuseSession.sendChatMessage(message: string): void
Parameters
Section titled “Parameters”message
- The message to send to the chat.
Tab Functionality
Section titled “Tab Functionality”openTab()
Section titled “openTab()”Open a new tab with specified url
in the current Session.
webfuseSession.openTab(url: string)
getTabs()
Section titled “getTabs()”Returns a list of opened tabs in Session participants.
webfuseSession.getTabs(): Promise<object[]>;
Returns
Section titled “Returns”A list of opened tabs in Session participants.
activateTab()
Section titled “activateTab()”Activates tab with certain ssid. ssid value could be found in the response of session.getTabs()
method.
webfuseSession.activateTab(ssid: number): void
pauseTabs()
Section titled “pauseTabs()”When called from the tab owner side, pause streaming content to other participants
webfuseSession.pauseTabs(): void
resumeTabs()
Section titled “resumeTabs()”Resume streaming content previously paused with pauseTabs()
webfuseSession.resumeTabs(): void
## openNewTabPage()
Open the new tab page.It will either open the default new tab page or the Extensions new tab page if present
``` tswebfuseSession.openNewTabPage(): void
Collaborative Functionality
Section titled “Collaborative Functionality”getParticipants()
Section titled “getParticipants()”Returns a list of Session participants.
webfuseSession.getParticipants(): Promise<{ name: string; email: string; online: boolean; client_index: number; self: boolean;}[]>
self
is a boolean value that indicates if the participant is the current user.
Returns
Section titled “Returns”A list of Session participants.
toggleDrawing()
Section titled “toggleDrawing()”Toggles your drawing mode. Available only if you are in control of the active tab.
webfuseSession.toggleDrawing()
makeHost()
Section titled “makeHost()”Make the user with specified clientIndex
the host of the Session. clientIndex
is always 0 for the leader and 1 or more for followers.
webfuseSession.makeHost(clientIndex: number): void
requestToHost()
Section titled “requestToHost()”Request to host from the Session Leader. This call will be silently ignored if the user is already hosting, if they are a leader, or if host_switching_allowed
option is disabled.
webfuseSession.requestToHost(): void
requestTabControl()
Section titled “requestTabControl()”Request control over the tabs from the tab owner. This call will be silently ignored if the user is already controlling the tab, or if participants_can_request_to_interact
option is disabled.
webfuseSession.requestTabControl(): void
revokeTabControl()
Section titled “revokeTabControl()”Revokes control over the tabs from the participant in control. This call will be silently ignored if the user is not the owner of the active tab, or if participants_can_request_to_interact
option is disabled.
webfuseSession.revokeTabControl(): void
returnTabControl()
Section titled “returnTabControl()”Returns control over the tabs to the active tab owner. This call will be silently ignored if the user is not in control of the active tab, or if participants_can_request_to_interact
option is disabled.
webfuseSession.returnTabControl(): void
transferTabControl()
Section titled “transferTabControl()”Transfers control of your tabs to a user with specified ‘clientIndex’. clientIndex is always 0 for the first tab_owner and 1 or more for the other participants.
webfuseSession.transferTabControl(clientIndex: number): void
toggleHuddleMode()
Section titled “toggleHuddleMode()”Toggle huddle mode.
webfuseSession.toggleHuddleMode(): void
followParticipant()
Section titled “followParticipant()”Only when huddle mode is enabled. Follow the participant.
webfuseSession.follow_participant(clientIndex: number): void
Parameters
Section titled “Parameters”client_index
- Unique client index.
Videocall Functionality
Section titled “Videocall Functionality”toggleVideochatFullscreen()
Section titled “toggleVideochatFullscreen()”Toggle videochat fullscreen mode.
webfuseSession.toggleVideochatFullscreen(): void
toggleVideochatMode()
Section titled “toggleVideochatMode()”Toggles videochat mode.
webfuseSession.toggleVideochatMode(mode?: 'floating' | 'sidebar'): void
Parameters
Section titled “Parameters”mode
- Designated mode (floating or embedded indie the sidebar).
toggleVideochatMicrophone()
Section titled “toggleVideochatMicrophone()”Mute/unmute the local microphone.
webfuseSession.toggleVideochatMicrophone()
startScreensharing()
Section titled “startScreensharing()”webfuseSession.startScreensharing(): void
Start screensharing only for desktop. Available if screensharing_enabled
option is enabled.