google-home / smart-home-java

Apache License 2.0
92 stars 47 forks source link

how to get stop camera stream request in smart home action as no traits availabe for stop camera stream. #16

Closed amiya-elear closed 4 years ago

amiya-elear commented 4 years ago

Hi Team,

I have written one google home action to stream data from a camera to Chromecast here is my code.

 @NotNull
  @Override
  public SyncResponse onSync(@NotNull SyncRequest syncRequest, @Nullable Map<?, ?> headers) {
    SyncResponse.Payload payload = new SyncResponse.Payload();
    payload.setAgentUserId("1836.15267389");
    payload.setDevices(
            new SyncResponse.Payload.Device[] {
                    new SyncResponse.Payload.Device.Builder()
                            .setId("5e0f5d1820a57b00113d7a7c")
                            .setType("action.devices.types.CAMERA")
                            .addTrait("action.devices.traits.CameraStream")
                            .setName(
                                    Collections.singletonList("living room camera"),
                                    "camera",
                                    Collections.singletonList("Camera"))
                            .setWillReportState(true)
                            .setAttributes(
                                    new JSONObject()
                                            .put("cameraStreamSupportedProtocols", new String[] {"hls"})
                                            .put("cameraStreamNeedAuthToken", false)
                                            .put("cameraStreamNeedDrmEncryption", false)
                                            )
                            .setDeviceInfo("blinds manufacturer", "xyz", "3.2", "11.4")
                            .build()
            });

    return new SyncResponse(syncRequest.getRequestId(), payload);
  }

  @NotNull
  @Override
  public ExecuteResponse onExecute(
          @NotNull ExecuteRequest executeRequest, @Nullable Map<?, ?> map) {
    ExecuteResponse.Payload payload = new ExecuteResponse.Payload();
   streamUrl = "https://cph-p2p-msl.akamaized.net/hls/live/2000341/test/master.m3u8";
    payload.setCommands(
            new ExecuteResponse.Payload.Commands[] {
                    new ExecuteResponse.Payload.Commands(
                            new String[] {"5e0f5d1820a57b00113d7a7c"},
                            "SUCCESS",
                            new HashMap<String, Object>() {
                              {
                                put("cameraStreamAccessUrl",streamUrl);
                              }
                            },

                            null,
                            null)
            });
    return new ExecuteResponse(executeRequest.getRequestId(), payload);
  }

  @NotNull
  @Override
  public void onDisconnect(DisconnectRequest disconnectRequest, Map<?, ?> headers) {
    String token = (String) headers.get("authorization");

  }
}

when I am saying to google assistance "show camera in bedroom tv" it's able to stream the data from hardcoded HSL URL to Chromecast (set as deb room Tv) and to stop the stream I am saying "cancel" its stop the stream but in my action application, I am not getting any request for stop stream. I have to handle some error cases(like stream close properly or not ) when I am saying cancel google assistance directly stoping the stream not even sending any request to my action application for stop stream(cancel request)

1: How to get an end stream or stop stream request in my action application for a camera stream? 2: What is the right way to stop a particular camera stream ? as I check there is not traits to stop a camera stream in the documentation. 3:If cancel is the right way to stop camera stream then if I have multiple cameras streaming in different devices(TV1,TV2, TV3) how it will decide which camera to stop?

Fleker commented 4 years ago

There is no command that the Assistant will send when the stream is ended.

If you do have multiple camera streams at one time I'm not sure what will happen. It may provide a disambiguation prompt to select a particular TV.

amiya-elear commented 4 years ago

Thanks, Fleker for your response.

We are generating an HLS stream on-demand whenever we receive a request to start camera streaming from google home. We need a way to stop the HLS generation micro-service once the user has stopped watching the stream. If not our service will keep running forever. Kindly help with a few suggestions.

proppy commented 4 years ago

@amiya-elear I would suggest reporting a platform issue at https://issuetracker.google.com/issues/new?component=655104&template=1284148, as this project only track issues related to the Java sample.