|
| 1 | +# Genesys Cloud WebRTC SDK Live Screen Monitoring |
| 2 | + |
| 3 | +This SDK supports live screen monitoring functionality that allows real-time viewing of user screens. Live screen monitoring sessions are initiated by the server and provide the ability to observe user activity in real-time for support, training, or compliance purposes. |
| 4 | + |
| 5 | +When the server determines that live screen monitoring should be initiated, it will send a `pendingSession` similar to how other session types work (ie. softphone and video conversations). The consuming client must accept the `pendingSession`, gather screen media, and add the media to that session. |
| 6 | + |
| 7 | +> *Note: live screen monitoring does not support guest users.* |
| 8 | +
|
| 9 | +## WebRTC SDK Live Screen Monitoring Index |
| 10 | +This documentation expands upon the [GenesysCloudWebrtcSdk] documentation but is specific to |
| 11 | +live screen monitoring. |
| 12 | + |
| 13 | +* [Example usage](#example-usage) |
| 14 | +* [Observer vs Target Roles](#observer-vs-target-roles) |
| 15 | + |
| 16 | +## Prerequisites |
| 17 | + |
| 18 | +You must have live screen monitoring policies in place and the WebRTC SDK must be configured to allow live screen monitoring sessions. |
| 19 | + |
| 20 | +## Example Usage |
| 21 | + |
| 22 | +### Automatic Accept (default) |
| 23 | +Signaling is automatically accepted by the SDK. When the live screen monitoring session comes in, you need to add your screen tracks and then call `sdk.acceptSession(session)`. |
| 24 | + |
| 25 | +``` ts |
| 26 | +// set up needed events |
| 27 | +sdk.on('sessionStarted', async (session) => { |
| 28 | + if (sdk.isLiveScreenMonitoringSession(session)) { |
| 29 | + // gather media - the SDK does *not* gather screen media for you |
| 30 | + const screenStream = await navigator.getDisplayMedia(); |
| 31 | + |
| 32 | + // create metadata for the screen being monitored |
| 33 | + const track = screenStream.getTracks()[0]; |
| 34 | + const { height, width, deviceId } = track.getSettings(); |
| 35 | + const liveScreenMonitoringMetadata = [ |
| 36 | + { |
| 37 | + trackId: track.id, |
| 38 | + screenId: deviceId, |
| 39 | + originX: 0, |
| 40 | + originY: 0, |
| 41 | + resolutionX: width, |
| 42 | + resolutionY: height, |
| 43 | + primary: true, |
| 44 | + } |
| 45 | + ]; |
| 46 | + |
| 47 | + sdk.acceptSession({ |
| 48 | + conversationId: session.conversationId, |
| 49 | + sessionType: session.sessionType, |
| 50 | + mediaStream: screenStream, |
| 51 | + liveScreenMonitoringMetadata |
| 52 | + }); |
| 53 | + } |
| 54 | +}); |
| 55 | +``` |
| 56 | + |
| 57 | +### Manual Accept |
| 58 | +If you want to manually control the acceptance of live screen monitoring sessions: |
| 59 | + |
| 60 | +``` ts |
| 61 | +const sdk = new GenesysCloudWebrtcSdk({ |
| 62 | + // other config stuff ... |
| 63 | + autoAcceptPendingLiveScreenMonitoringRequests: false |
| 64 | +}); |
| 65 | + |
| 66 | +sdk.on('pendingSession', (session) => { |
| 67 | + if (session.sessionType === SessionTypes.liveScreenMonitoring) { |
| 68 | + // manually accept the pending session |
| 69 | + sdk.acceptPendingSession({ |
| 70 | + conversationId: session.conversationId, |
| 71 | + sessionType: session.sessionType |
| 72 | + }); |
| 73 | + } |
| 74 | +}); |
| 75 | + |
| 76 | +sdk.on('sessionStarted', async (session) => { |
| 77 | + if (sdk.isLiveScreenMonitoringSession(session)) { |
| 78 | + const screenStream = await navigator.getDisplayMedia(); |
| 79 | + |
| 80 | + const track = screenStream.getTracks()[0]; |
| 81 | + const { height, width, deviceId } = track.getSettings(); |
| 82 | + const liveScreenMonitoringMetadata = [ |
| 83 | + { |
| 84 | + trackId: track.id, |
| 85 | + screenId: deviceId, |
| 86 | + originX: 0, |
| 87 | + originY: 0, |
| 88 | + resolutionX: width, |
| 89 | + resolutionY: height, |
| 90 | + primary: true, |
| 91 | + } |
| 92 | + ]; |
| 93 | + |
| 94 | + sdk.acceptSession({ |
| 95 | + conversationId: session.conversationId, |
| 96 | + sessionType: session.sessionType, |
| 97 | + mediaStream: screenStream, |
| 98 | + liveScreenMonitoringMetadata |
| 99 | + }); |
| 100 | + } |
| 101 | +}); |
| 102 | +``` |
| 103 | + |
| 104 | +### Multiple Screens |
| 105 | +Live screen monitoring supports monitoring up to **four** screens simultaneously. All screen tracks need to be on the same media stream provided in `sdk.acceptSession(...)`. |
| 106 | + |
| 107 | +``` ts |
| 108 | +sdk.on('sessionStarted', async (session) => { |
| 109 | + if (sdk.isLiveScreenMonitoringSession(session)) { |
| 110 | + // gather multiple screens |
| 111 | + const screenStream1 = await navigator.getDisplayMedia(); |
| 112 | + const screenStream2 = await navigator.getDisplayMedia(); |
| 113 | + |
| 114 | + // combine streams |
| 115 | + screenStream2.getVideoTracks().forEach(track => screenStream1.addTrack(track)); |
| 116 | + |
| 117 | + // create metadata for all screens |
| 118 | + const liveScreenMonitoringMetadata = createMultiScreenMetadata(); |
| 119 | + |
| 120 | + sdk.acceptSession({ |
| 121 | + conversationId: session.conversationId, |
| 122 | + sessionType: session.sessionType, |
| 123 | + mediaStream: screenStream1, |
| 124 | + liveScreenMonitoringMetadata |
| 125 | + }); |
| 126 | + } |
| 127 | +}); |
| 128 | +``` |
| 129 | + |
| 130 | +## Observer vs Target Roles |
| 131 | + |
| 132 | +Live screen monitoring sessions involve two distinct roles with different behaviors: |
| 133 | + |
| 134 | +### Target Role |
| 135 | +The **target** is the user whose screen is being monitored. When accepting a session as a target: |
| 136 | +- Must provide a `mediaStream` containing screen capture tracks |
| 137 | +- The session automatically accepts if the `fromUserId` matches the current user |
| 138 | +- Cannot end the monitoring session (only observers can end it) |
| 139 | +- Sends their screen content to observers |
| 140 | + |
| 141 | +``` ts |
| 142 | +// Target accepts with screen media |
| 143 | +sdk.acceptSession({ |
| 144 | + conversationId: session.conversationId, |
| 145 | + sessionType: session.sessionType, |
| 146 | + mediaStream: screenStream, // Required for targets |
| 147 | + liveScreenMonitoringMetadata |
| 148 | +}); |
| 149 | +``` |
| 150 | + |
| 151 | +### Observer Role |
| 152 | +The **observer** is the user monitoring the target's screen. When accepting a session as an observer: |
| 153 | +- Must provide `videoElements` array or `videoElement` to display incoming video |
| 154 | +- Set `liveMonitoringObserver: true` in the accept parameters |
| 155 | +- Receives video streams from the target and displays them in provided video elements |
| 156 | +- Can end the monitoring session |
| 157 | +- Sends empty video tracks to maintain WebRTC connection |
| 158 | + |
| 159 | +``` ts |
| 160 | +// Observer accepts with video elements |
| 161 | +sdk.acceptSession({ |
| 162 | + conversationId: session.conversationId, |
| 163 | + sessionType: session.sessionType, |
| 164 | + liveMonitoringObserver: true, // Identifies this as observer role |
| 165 | + videoElements: [videoElement1, videoElement2], // Required for observers |
| 166 | +}); |
| 167 | +``` |
| 168 | + |
| 169 | +### Role Determination |
| 170 | +The SDK automatically determines the role based on: |
| 171 | +1. If `liveMonitoringObserver: true` is set in accept parameters → Observer |
| 172 | +2. If `fromUserId` matches current user ID → Target (auto-accepted) |
| 173 | +3. Otherwise → Target (manual acceptance required unless specified) |
| 174 | + |
| 175 | +[GenesysCloudWebrtcSdk]: index.md#genesyscloudwebrtcsdk |
0 commit comments