Skip to content

Commit

Permalink
add crew sample
Browse files Browse the repository at this point in the history
  • Loading branch information
eskilgh committed Dec 19, 2023
1 parent 1f54751 commit 07ff5a7
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Crew/Crew.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Huddly.Sdk" Version="2.3.1" />
<PackageReference Include="Huddly.Sdk.Extensions" Version="2.3.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
</ItemGroup>

</Project>
70 changes: 70 additions & 0 deletions Crew/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using Huddly.Device.Model;
using Huddly.Sdk;
using Huddly.Sdk.Devices;
using Huddly.Sdk.Models;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

namespace Crew
{
internal class Program
{
static void Main(string[] args)
{
var cts = new CancellationTokenSource();
var services = new ServiceCollection();
services.AddLogging(configure => configure.AddConsole().SetMinimumLevel(LogLevel.Debug));

services.AddHuddlySdk(configure =>
{
configure.UseUsbDeviceMonitor();
configure.UseIpDeviceMonitor();
});

var sp = services.BuildServiceProvider();

// Should always be disposed after use
using var huddlySdk = sp.GetRequiredService<ISdk>();

IDevice? lastDevice = null;
huddlySdk.DeviceConnected += async (o, e) =>
{
if (!(e.Device is { Model: DeviceModel.Crew } and IMultiCameraDevice))
{
Console.WriteLine($"Device {e.Device.Model} is not a Crew-device");
return;
}

// Crew devices support most normal IDevice methods as seen in the other samples.
// In addition, it has an API that is unique for only multicamera devices, which is demonstrated here

lastDevice = e.Device;

IMultiCameraDevice crewDevice = (IMultiCameraDevice)e.Device;
Result<IList<CameraStatus>> connectedCamerasResult = await crewDevice.GetConnectedCameras();
if (!connectedCamerasResult.IsSuccess)
{
Console.WriteLine($"Failed getting connected cameras: {connectedCamerasResult.Message}");
return;
}
IList<CameraStatus> crewCameraStatuses = connectedCamerasResult.Value;
Console.WriteLine($"Crew system with the following cameras connected:");
foreach (CameraStatus cameraStatus in crewCameraStatuses)
{
Console.WriteLine($"\tSerial: {cameraStatus.Serial}, Type: {cameraStatus.Type}, Availability: {cameraStatus.Availability}");
}
};
huddlySdk.DeviceDisconnected += (o, e) =>
{
Console.WriteLine($"Device {e.Device.Id} disconnected");
if (e.Device.Id == lastDevice?.Id)
{
lastDevice = null;
}
};

huddlySdk.StartMonitoring();
Console.ReadKey();
}
}
}
6 changes: 6 additions & 0 deletions Huddly.Sdk.Samples.sln
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
README.md = README.md
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Crew", "Crew\Crew.csproj", "{0D25086C-138A-4AC3-A0EA-884D7858F8EF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -44,6 +46,10 @@ Global
{A29A34E5-0ED4-4298-A03E-65BF3729745A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A29A34E5-0ED4-4298-A03E-65BF3729745A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A29A34E5-0ED4-4298-A03E-65BF3729745A}.Release|Any CPU.Build.0 = Release|Any CPU
{0D25086C-138A-4AC3-A0EA-884D7858F8EF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0D25086C-138A-4AC3-A0EA-884D7858F8EF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0D25086C-138A-4AC3-A0EA-884D7858F8EF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0D25086C-138A-4AC3-A0EA-884D7858F8EF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down

0 comments on commit 07ff5a7

Please sign in to comment.