Session Events
SurflySession dispatches a number of events which you can use to track the session status. You can set handlers with the SurflySession.on() method. Callback functions should accept two arguments:
- `SurflySession` instance that triggered the event
- JSON object with event attributes
function startCobrowsing () {
Surfly.session({docked_only: true})
.on('session_started', function(session) {
console.log(session, 'is fully initiated');
})
.on('viewer_joined', function(session, event) {
console.log('there are', event.count, 'users in total');
})
.startLeader();
}
Available events
session_created
triggered when a session is created (usually after SurflySession.create() call).
session_started
triggered when a session window has been loaded (usually after a call to SurflySession.startLeader()). Has no additional parameters.
viewer_joined
triggered when a follower joins the session. Parameters:
countupdated number of users in the sessionclientIndexindex of the user. Can be used in subsequentSurflySession.giveControl()callsuserDatadata provided inuserDataargument ofSurflySession.start*()call
viewer_left
triggered when a follower leaves the session. Parameters:
countupdated number of users in the sessionclientIndexindex of the useruserDatadata provided inuserDataargument ofSurflySession.start*()call
session_ended
triggered when the session has been properly finished (normally by SurflySession.end() call)
message
triggered when the message is received. Parameters:
datamessage object sent from the other sideoriginthe origin of the sender window
relocated
(not available inside a session)
triggered when the current tab inside a Surfly session navigates to another page. Parameters:
urlabsolute URL of new location
error
(not available inside a session)
triggered on common errors. Parameters:
reasonerror description. Currently may be one of the following:"other_connection"the leader_link was opened elsewhere. The new window/browser becomes the leader and the old leader is kicked out. It also happens if viewer_link was open twice in the same browser"connect_failed"The WebSocket connection to Surfly cannot be established
control
triggered when control over the session has been transferred. Parameters:
toindex of the client that now has the control. Always 0 for the leader, 1 or more for a vieweruserDatauser data of the user who received the controlgainedset to true if control was given to the current user
agent_status
triggered when a support agent availability changes:
availableis set to true if a support agent has just become available, and false if all agents have become unavailable.