Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit 0c5f0f8

Browse files
committed
Added the possibility to show remote/local screen share on video controllers
1 parent 5c425d3 commit 0c5f0f8

File tree

4 files changed

+139
-2
lines changed

4 files changed

+139
-2
lines changed

Runtime/Components/ConferenceController.cs

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ public class ConferenceController : MonoBehaviour
1919

2020
private List<VideoController> _videoControllers = new List<VideoController>();
2121

22+
private VideoFrameHandler _cameraVideoFrameHandler = null;
23+
private VideoFrameHandler _screenShareVideoFrameHandler = null;
24+
2225
[Tooltip("The conference alias to join.")]
2326
[SerializeField]
2427
private string _conferenceAlias;
@@ -39,6 +42,7 @@ public string ConferenceAlias
3942
public bool AutoJoin = false;
4043

4144
public GameObject VideoDevice;
45+
public GameObject ScreenShareSource;
4246

4347
void Start()
4448
{
@@ -133,10 +137,17 @@ public void StartVideo()
133137
}
134138
}
135139

140+
var controller = _videoControllers.Find(c => c.IsLocal == true);
141+
if (controller)
142+
{
143+
_cameraVideoFrameHandler = new VideoFrameHandler();
144+
_cameraVideoFrameHandler.Sink = controller.VideoRenderer;
145+
}
146+
136147
DolbyIOManager.QueueOnMainThread(() =>
137148
{
138149

139-
_sdk.Video.Local.StartAsync(device).ContinueWith
150+
_sdk.Video.Local.StartAsync(device, _cameraVideoFrameHandler).ContinueWith
140151
(
141152
t => Debug.LogError(t.Exception),
142153
TaskContinuationOptions.OnlyOnFaulted
@@ -153,7 +164,53 @@ public void StopVideo()
153164
}
154165
catch (DolbyIOException e)
155166
{
156-
Debug.LogError(e.Message);
167+
Debug.LogError("Failed to stop video." + e);
168+
}
169+
}
170+
171+
public void StartScreenShare()
172+
{
173+
try
174+
{
175+
if (ScreenShareSource)
176+
{
177+
var dropdown = ScreenShareSource.GetComponent<ScreenShareSourceDropdown>();
178+
if (dropdown.CurrentSource.Id != 0)
179+
{
180+
var controller = _videoControllers.Find(c => c.IsLocal && c.IsScreenShare);
181+
if (controller)
182+
{
183+
_screenShareVideoFrameHandler = new VideoFrameHandler();
184+
_screenShareVideoFrameHandler.Sink = controller.VideoRenderer;
185+
}
186+
187+
_sdk.Video.Local.StartScreenShareAsync(dropdown.CurrentSource, _screenShareVideoFrameHandler)
188+
.ContinueWith
189+
(
190+
t => Debug.LogError(t.Exception),
191+
TaskContinuationOptions.OnlyOnFaulted
192+
);
193+
}
194+
else
195+
{
196+
throw new Exception("No source selected");
197+
}
198+
}
199+
}
200+
catch (DolbyIOException e)
201+
{
202+
Debug.LogError("Failed to start screen share" + e);
203+
}
204+
}
205+
206+
public void StopScreenShare()
207+
{
208+
try
209+
{
210+
}
211+
catch (DolbyIOException e)
212+
{
213+
Debug.LogError("Failed to stop screen share" + e);
157214
}
158215
}
159216

@@ -209,6 +266,11 @@ private async Task UpdateVideoControllers()
209266
{
210267
string participantId = "";
211268

269+
if (c.IsLocal)
270+
{
271+
return;
272+
}
273+
212274
switch (c.FilterBy)
213275
{
214276
case ParticipantFilter.ParticipantId:
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using UnityEngine;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using DolbyIO.Comms;
5+
using DolbyIO.Comms.Unity;
6+
using TMPro;
7+
using System.Threading.Tasks;
8+
9+
[AddComponentMenu("Dolby.io Comms/Devices/Screen Share Source Dropdown", 252)]
10+
public class ScreenShareSourceDropdown : MonoBehaviour
11+
{
12+
private DolbyIOSDK _sdk = DolbyIOManager.Sdk;
13+
private TMP_Dropdown _dropdown;
14+
15+
private List<ScreenShareSource> _currentSources;
16+
17+
public ScreenShareSource CurrentSource;
18+
19+
// Use this for initialization
20+
void Awake()
21+
{
22+
_dropdown = GetComponent<TMP_Dropdown>();
23+
_dropdown.onValueChanged.AddListener(delegate
24+
{
25+
OnDropdownSelect(_dropdown);
26+
});
27+
}
28+
29+
void Start()
30+
{
31+
LoadDevices().ContinueWith(t => Debug.LogError(t.Exception.Message), TaskContinuationOptions.OnlyOnFaulted);
32+
}
33+
34+
35+
public async Task LoadDevices()
36+
{
37+
try
38+
{
39+
_dropdown.ClearOptions();
40+
41+
_currentSources = await _sdk.MediaDevice.GetScreenShareSourcesAsync();
42+
43+
var titles = _currentSources.ConvertAll(device => device.Title);
44+
45+
_dropdown.AddOptions(titles);
46+
}
47+
catch (DolbyIOException e)
48+
{
49+
Debug.LogError(e.Message);
50+
}
51+
}
52+
53+
private void OnDropdownSelect(TMP_Dropdown value)
54+
{
55+
CurrentSource = _currentSources[_dropdown.value];
56+
}
57+
}
58+

Runtime/Components/devices/ScreenShareSourceDropdown.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Runtime/Components/video/VideoController.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ public class VideoController : MonoBehaviour
2727

2828
[Tooltip("The filter value.")]
2929
public string Filter;
30+
31+
[Tooltip("Whether to display local or remote video.")]
32+
public bool IsLocal = false;
33+
34+
[Tooltip("Wether to display screenshare.")]
35+
public bool IsScreenShare = false;
3036

3137
private VideoTrack _videoTrack;
3238

0 commit comments

Comments
 (0)