Listening for events
The Javascript SDK emits events about the session.
Listening for events
You can listen for events by running the following code.
Upscope('on', ...eventNames, callbackFunction);
List of events
Event Name | Additional arguments | Description |
---|---|---|
agentsAvailable |
— | Indicates that agents are available and waiting for requests on the Upscope dashboard. |
agentRequestUpdate |
status: string |
Gives you updates about the status of the current agent request. One of pending , accepted , unavailable , canceled . |
callAccepted |
— | An audio call has been accepted by the visitor. |
callEnd |
— | An audio call has ended. |
callStart |
— | An audio call has started. |
connection |
— | The connection has been established with Upscope's servers. |
connectionReset |
— | The connection has been reset, and there will be a new visitor created. |
newObserver |
observerId: string |
Someone new is now observing as an agent1. |
observerGone |
observerId: string |
observerGone is no longer observing1. |
sessionContinue |
— | A session has continued from a previous pageload. |
sessionEnd |
— | A session has ended. |
sessionRequest |
— | An agent is asking to start a session.2 |
sessionStart |
— | A session has started. |
waitingForCall |
— | The visitor has gotten to the page from an agent's personal link. |
Example
Here's an example of how to use the events API to show a message to the visitor when a session is active.
<div id="upscope-active" style="display: none;">
Screen sharing active.
</div>
<script>
const activeElement = document.getElementById('upscope-active');
Upscope('on', 'sessionStart', 'sessionContinue', () => {
activeElement.style.display = 'block';
});
Upscope('on', 'sessionEnd', () => {
activeElement.style.display = 'none';
});
</script>
-
If you want to change the authorization flow, you'll need to add a
onSessionRequest
function to the configuration. ↩