forked from project-chip/connectedhomeip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tv-casting-app: Skeleton for simplified Android discovery
- Loading branch information
1 parent
f47aed4
commit 97cabdf
Showing
3 changed files
with
179 additions
and
0 deletions.
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
...les/tv-casting-app/android/App/app/src/main/java/com/matter/casting/DiscoveryExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright (c) 2023 Project CHIP Authors | ||
* All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.matter.casting; | ||
|
||
import android.util.Log; | ||
import com.matter.casting.core.CastingPlayer; | ||
import com.matter.casting.core.CastingPlayerDiscovery; | ||
import com.matter.casting.core.CastingPlayerDiscovery.CastingPlayerChangeListener; | ||
import java.util.List; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.ScheduledExecutorService; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
public class DiscoveryExample { | ||
private static final ScheduledExecutorService executorService = | ||
Executors.newSingleThreadScheduledExecutor(); | ||
|
||
/** | ||
* Implementation of a CastingPlayerChangeListener used to listen to changes in the discovered | ||
* CastingPlayers | ||
*/ | ||
private static final CastingPlayerChangeListener castingPlayerChangeListener = | ||
new CastingPlayerChangeListener() { | ||
private final String TAG = CastingPlayerChangeListener.class.getSimpleName(); | ||
|
||
@Override | ||
public void onChanged(CastingPlayer castingPlayer) { | ||
Log.i(TAG, "Discovered changes to " + castingPlayer); | ||
// consume changes to the provided castingPlayers | ||
} | ||
|
||
@Override | ||
public void onAdded(CastingPlayer castingPlayer) { | ||
Log.i(TAG, "Discovered " + castingPlayer); | ||
// consume discovered castingPlayers | ||
} | ||
|
||
@Override | ||
public void onRemoved(CastingPlayer castingPlayer) { | ||
Log.i(TAG, "Removed " + castingPlayer); | ||
// consume castingPlayers removed or lost from the network | ||
} | ||
}; | ||
|
||
public static void demoDiscovery() { | ||
// Get the singleton instance of the PlayerDiscovery | ||
CastingPlayerDiscovery discoverer = CastingPlayerDiscovery.getInstance(); | ||
|
||
// Add our castingPlayerChangeListener to listen to changes in the discovered CastingPlayers | ||
discoverer.addCastingPlayerChangeListener(castingPlayerChangeListener); | ||
|
||
// Start discovery | ||
discoverer.startDiscovery(); | ||
|
||
// After some time, stop discovering and remove our castingPlayerChangeListener from the set of | ||
// listeners the CastingPlayerDiscoverer informs | ||
executorService.schedule( | ||
() -> { | ||
discoverer.stopDiscovery(); | ||
discoverer.removeCastingPlayerChangeListener(castingPlayerChangeListener); | ||
}, | ||
30, | ||
TimeUnit.SECONDS); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...es/tv-casting-app/android/App/app/src/main/jni/com/matter/casting/core/CastingPlayer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright (c) 2023 Project CHIP Authors | ||
* All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.matter.casting.core; | ||
|
||
public interface CastingPlayer { | ||
String getId(); | ||
|
||
String getName(); | ||
|
||
String getVendorId(); | ||
|
||
String getProductId(); | ||
|
||
String getType(); | ||
|
||
// TODO | ||
// List<Endpoint> getEndpoints(); | ||
// | ||
// ConnectionState getConnectionState(); | ||
// | ||
// CompletableFuture<Void> connect(long timeout); | ||
|
||
// static class ConnectionState extends Observable { | ||
// private boolean connected; | ||
// | ||
// void setConnected(boolean connected) { | ||
// this.connected = connected; | ||
// setChanged(); | ||
// notifyObservers(this.connected); | ||
// } | ||
// | ||
// boolean isConnected() { | ||
// return connected; | ||
// } | ||
// } | ||
} |
50 changes: 50 additions & 0 deletions
50
...ting-app/android/App/app/src/main/jni/com/matter/casting/core/CastingPlayerDiscovery.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright (c) 2023 Project CHIP Authors | ||
* All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.matter.casting.core; | ||
|
||
import java.util.List; | ||
|
||
public interface CastingPlayerDiscovery { | ||
static CastingPlayerDiscovery getInstance() { | ||
return null; | ||
} | ||
|
||
List<CastingPlayer> getDiscoveredCastingPlayers(); | ||
|
||
/** | ||
* | ||
*/ | ||
void startDiscovery(); | ||
|
||
void stopDiscovery(); | ||
|
||
/** | ||
* | ||
* @param listener | ||
*/ | ||
void addCastingPlayerChangeListener(CastingPlayerChangeListener listener); | ||
|
||
void removeCastingPlayerChangeListener(CastingPlayerChangeListener listener); | ||
|
||
interface CastingPlayerChangeListener { | ||
void onChanged(CastingPlayer castingPlayer); | ||
|
||
void onAdded(CastingPlayer castingPlayer); | ||
|
||
void onRemoved(CastingPlayer castingPlayer); | ||
} | ||
} |