@@ -693,7 +693,8 @@ discover available endpoints supported by a Casting Player.
693
693
### Connect to a Casting Player
694
694
695
695
_{Complete Connection examples: [Linux ](linux/ simple- app- helper. cpp) |
696
- [iOS](darwin/ TvCasting / TvCasting / MCConnectionExampleViewModel . swift)}_
696
+ [Android ](android/ App / app/ src/ main/ java/ com/ matter/ casting/ ConnectionExampleFragment . java)
697
+ | [iOS](darwin/ TvCasting / TvCasting / MCConnectionExampleViewModel . swift)}_
697
698
698
699
Each `CastingPlayer ` object created during
699
700
[Discovery ](#discover- casting- players) contains information such as
@@ -740,6 +741,40 @@ targetCastingPlayer->VerifyOrEstablishConnection(ConnectionHandler,
740
741
...
741
742
```
742
743
744
+ On Android, the Casting Client may call `verifyOrEstablishConnection` on the
745
+ `CastingPlayer` object it wants to connect to and accept or handle exceptions on
746
+ the returned `CompletableFuture` object.
747
+
748
+ ```java
749
+ private static final long MIN_CONNECTION_TIMEOUT_SEC = 3 * 60;
750
+ ...
751
+ ...
752
+
753
+ EndpointFilter desiredEndpointFilter = new EndpointFilter(null, 65521, new ArrayList<DeviceTypeStruct>());
754
+
755
+ // The desired commissioning window timeout and EndpointFilter are optional.
756
+ CompletableFuture<Void> completableFuture = targetCastingPlayer.verifyOrEstablishConnection(MIN_CONNECTION_TIMEOUT_SEC, desiredEndpointFilter);
757
+ completableFuture
758
+ .thenAccept(
759
+ (response) -> {
760
+ Log.i(TAG, "CompletableFuture.thenAccept(), connected to CastingPlayer with deviceId: " + targetCastingPlayer.getDeviceId());
761
+
762
+ getActivity().runOnUiThread(() -> {
763
+ connectionFragmentNextButton.setEnabled(true);
764
+ });
765
+ }
766
+ ).exceptionally(
767
+ exc -> {
768
+ Log.e(TAG, "CompletableFuture.exceptionally(), CastingPLayer connection failed: " + exc.getMessage());
769
+
770
+ getActivity().runOnUiThread(() -> {
771
+ connectionFragmentStatusTextView.setText("Casting Player connection failed due to: " + exc.getMessage());
772
+ });
773
+ return null;
774
+ }
775
+ );
776
+ ```
777
+
743
778
On iOS, the Casting Client may call `verifyOrEstablishConnection` on the
744
779
`MCCastingPlayer` object it wants to connect to and handle any `NSErrors` that
745
780
may happen in the process.
@@ -774,6 +809,8 @@ func connect(selectedCastingPlayer: MCCastingPlayer?) {
774
809
### Select an Endpoint on the Casting Player
775
810
776
811
_{Complete Endpoint selection examples: [Linux](linux/simple-app-helper.cpp) |
812
+ [Android](android/App/app/src/main/java/com/matter/casting/ContentLauncherLaunchURLExampleFragment.java)
813
+ |
777
814
[iOS](darwin/TvCasting/TvCasting/MCContentLauncherLaunchURLExampleViewModel.swift)}_
778
815
779
816
On a successful connection with a `CastingPlayer`, a Casting Client may select
@@ -800,6 +837,29 @@ if (it != endpoints.end())
800
837
}
801
838
```
802
839
840
+ On Android, it can select an `Endpoint` as shown below.
841
+
842
+ ```java
843
+ private static final Integer SAMPLE_ENDPOINT_VID = 65521;
844
+ ...
845
+ List<Endpoint> endpoints = selectedCastingPlayer.getEndpoints();
846
+ if (endpoints == null) {
847
+ Log.e(TAG, "No Endpoints found on CastingPlayer");
848
+ return;
849
+ }
850
+
851
+ Endpoint endpoint = endpoints
852
+ .stream()
853
+ .filter(e -> SAMPLE_ENDPOINT_VID.equals(e.getVendorId()))
854
+ .findFirst()
855
+ .get();
856
+
857
+ if (endpoint == null) {
858
+ Log.e(TAG, "No Endpoint with chosen vendorID: " + SAMPLE_ENDPOINT_VID + " found on CastingPlayer");
859
+ return;
860
+ }
861
+ ```
862
+
803
863
On iOS, it can select an `MCEndpoint` similarly and as shown below.
804
864
805
865
```swift
@@ -834,6 +894,8 @@ response types to use with these APIs:
834
894
### Issuing Commands
835
895
836
896
_{Complete Command invocation examples: [Linux](linux/simple-app-helper.cpp) |
897
+ [Android](android/App/app/src/main/java/com/matter/casting/ContentLauncherLaunchURLExampleFragment.java)
898
+ |
837
899
[iOS](darwin/TvCasting/TvCasting/MCContentLauncherLaunchURLExampleViewModel.swift)}_
838
900
839
901
The Casting Client can get a reference to an `Endpoint` on a `CastingPlayer`,
@@ -880,6 +942,46 @@ void InvokeContentLauncherLaunchURL(matter::casting::memory::Strong<matter::cast
880
942
}
881
943
```
882
944
945
+ On Android, given an `Endpoint` endpoint, it can send a `LaunchURL` command
946
+ (part of the Content Launcher cluster) by calling the `invoke` API on a
947
+ `ContentLauncherClusterLaunchURLCommand`
948
+
949
+ ```java
950
+ if (!endpoint.hasCluster(MatterClusters.ContentLauncherCluster.class)) {
951
+ Log.e(TAG, "Endpoint with chosen vendorID does not support ContentLauncher cluster");
952
+ return;
953
+ }
954
+
955
+ MatterClusters.ContentLauncherCluster cluster = endpoint.getCluster(MatterClusters.ContentLauncherCluster.class);
956
+ MatterCommands.ContentLauncherClusterLaunchURLCommand command = cluster.getCommand(MatterCommands.ContentLauncherClusterLaunchURLCommand.class);
957
+ if (command == null) {
958
+ Log.e(TAG, "ContentLauncher cluster on Endpoint with chosen vendorID does not support LaunchURL command");
959
+ return;
960
+ }
961
+
962
+ // create the request object from GUI inputs
963
+ MatterCommands.ContentLauncherClusterLaunchURLRequest request = new MatterCommands.ContentLauncherClusterLaunchURLRequest();
964
+ request.contentURL = ((EditText) getView().findViewById(R.id.contentUrlEditText)).getText().toString();
965
+ request.displayString = ((EditText) getView().findViewById(R.id.contentDisplayStringEditText)).getText().toString();
966
+ CompletableFuture<MatterCommands.ContentLauncherClusterResponse> responseFuture = command.invoke(request, 5000);
967
+ responseFuture
968
+ .thenAccept(
969
+ response -> {
970
+ Log.d(TAG, "Command response " + response);
971
+ TextView launchUrlStatus = getView().findViewById(R.id.launchUrlStatus);
972
+ getActivity().runOnUiThread(() ->
973
+ launchUrlStatus.setText("Success! Response data: " + response.data));
974
+ }
975
+ ).exceptionally(
976
+ exc -> {
977
+ Log.e(TAG, "Command failure: " + exc.getMessage());
978
+ TextView launchUrlStatus = getView().findViewById(R.id.launchUrlStatus);
979
+ getActivity().runOnUiThread(() -> launchUrlStatus.setText("Command failure: " + exc.getMessage()));
980
+ return null;
981
+ }
982
+ );
983
+ ```
984
+
883
985
On iOS, given an `MCEndpoint` endpoint, it can send a `LaunchURL` command (part
884
986
of the Content Launcher cluster) by calling the `invoke` API on a
885
987
`MCContentLauncherClusterLaunchURLCommand`
@@ -1042,10 +1144,8 @@ vendorIDAttribute!.read(nil) { context, before, after, err in
1042
1144
1043
1145
### Subscriptions
1044
1146
1045
- _{Complete Attribute subscription examples:
1046
- [Linux](linux/simple-app-helper.cpp)}_
1047
-
1048
- _{Complete Attribute Read examples: [Linux](linux/simple-app-helper.cpp) |
1147
+ _{Complete Attribute subscription examples: [Linux](linux/simple-app-helper.cpp)
1148
+ |
1049
1149
[iOS](darwin/TvCasting/TvCasting/MCMediaPlaybackSubscribeToCurrentStateExampleViewModel.swift)}_
1050
1150
1051
1151
A Casting Client may subscribe to an attribute on an `Endpoint` of the
0 commit comments