Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle empty media stream config #1967

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/api.test/Mocks/IsarServiceMock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public async Task<IsarMission> StartMoveArm(Robot robot, string position)
return isarServiceMissionResponse;
}

public async Task<MediaConfig> GetMediaStreamConfig(Robot robot)
public async Task<MediaConfig?> GetMediaStreamConfig(Robot robot)
{
await Task.Run(() => Thread.Sleep(1));
return new MediaConfig
Expand Down
2 changes: 1 addition & 1 deletion backend/api/Controllers/MediaStreamController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ IRobotService robotService
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<MediaConfig>> GetMediaStreamConfig([FromRoute] string id)
public async Task<ActionResult<MediaConfig?>> GetMediaStreamConfig([FromRoute] string id)
{
try
{
Expand Down
14 changes: 8 additions & 6 deletions backend/api/Services/IsarService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public interface IIsarService

public Task<IsarMission> StartMoveArm(Robot robot, string armPosition);

public Task<MediaConfig> GetMediaStreamConfig(Robot robot);
public Task<MediaConfig?> GetMediaStreamConfig(Robot robot);
}

public class IsarService(
Expand Down Expand Up @@ -305,7 +305,7 @@ HttpResponseMessage response
return (description, (int)statusCode);
}

public async Task<MediaConfig> GetMediaStreamConfig(Robot robot)
public async Task<MediaConfig?> GetMediaStreamConfig(Robot robot)
{
string mediaStreamPath = $"/media/media-stream-config";
var response = await CallApi(HttpMethod.Get, robot.IsarUri, mediaStreamPath);
Expand All @@ -317,11 +317,13 @@ public async Task<MediaConfig> GetMediaStreamConfig(Robot robot)
logger.LogError("{Message}: {ErrorResponse}", message, errorResponse);
throw new ConfigException(message);
}
if (response.Content is null)

if (response.StatusCode == HttpStatusCode.NoContent)
{
string errorMessage = "Could not read content from new robot media stream config";
logger.LogError("{ErrorMessage}", errorMessage);
throw new ConfigException(errorMessage);
logger.LogDebug(
$"Robot with id {robot.Id} did not return any content for media stream config. This is likely because the robot doesn't have a media stream."
);
return null;
}

IsarMediaConfigMessage? isarMediaConfigResponse;
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/api/ApiCaller.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export class BackendAPICaller {
return result.content
}

static async getRobotMediaConfig(robotId: string): Promise<MediaStreamConfig> {
static async getRobotMediaConfig(robotId: string): Promise<MediaStreamConfig | null | undefined> {
const path: string = 'media-stream/' + robotId
const result = await this.GET<MediaStreamConfig>(path).catch(BackendAPICaller.handleError('GET', path))
return result.content
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/components/Contexts/MediaStreamContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ export const MediaStreamProvider: FC<Props> = ({ children }) => {

const refreshRobotMediaConfig = (robotId: string) => {
BackendAPICaller.getRobotMediaConfig(robotId)
.then((conf: MediaStreamConfig) => addConfigToMediaStreams(conf))
.then((conf: MediaStreamConfig | null | undefined) => {
if (conf) addConfigToMediaStreams(conf)
})
.catch((e) => console.error(e))
}

Expand Down
Loading