I'd like to contribute reactive network status change support to nativephp/mobile-network.
Currently, Network::status() provides a snapshot of the current network state. The proposed addition would allow applications to react when that state changes, using the native platform APIs:
Android: ConnectivityManager.NetworkCallback
iOS: a persistent NWPathMonitor
The proposed API would be a single NetworkStatusChanged event containing the same status information currently exposed by Network::status():
connected
type
isExpensive
isConstrained
The first native observation would establish the baseline without emitting an event. Subsequent meaningful changes, including connection/disconnection, Wi-Fi ↔ cellular, or metered/constrained changes would emit NetworkStatusChanged, with duplicate states suppressed.
I was thinking of making the event package-owned, following the newer plugin pattern:
NativePHP\Network\Events\NetworkStatusChanged
Ideally, the event would implement BroadcastsGlobally, allowing application-wide usage such as:
Event::listen(NetworkStatusChanged::class, function (NetworkStatusChanged $event) { // React to connectivity changes... });
One compatibility issue i noticed while investigating the implementation is that mobile-network currently supports nativephp/mobile ^3.0 || ^4.0, while BroadcastsGlobally is a v4 API.
Would you prefer this feature to target NativePHP v4 and update the package constraint accordingly, or should mobile-network retain v3 compatibility and keep the event component-scoped?
I'm happy to implement this and submit the PR once the preferred direction is clear.
I'd like to contribute reactive network status change support to
nativephp/mobile-network.Currently,
Network::status()provides a snapshot of the current network state. The proposed addition would allow applications to react when that state changes, using the native platform APIs:Android:
ConnectivityManager.NetworkCallbackiOS: a persistent
NWPathMonitorThe proposed API would be a single
NetworkStatusChangedevent containing the same status information currently exposed byNetwork::status():connectedtypeisExpensiveisConstrainedThe first native observation would establish the baseline without emitting an event. Subsequent meaningful changes, including connection/disconnection, Wi-Fi ↔ cellular, or metered/constrained changes would emit NetworkStatusChanged, with duplicate states suppressed.
I was thinking of making the event package-owned, following the newer plugin pattern:
NativePHP\Network\Events\NetworkStatusChangedIdeally, the event would implement BroadcastsGlobally, allowing application-wide usage such as:
Event::listen(NetworkStatusChanged::class, function (NetworkStatusChanged $event) { // React to connectivity changes... });One compatibility issue i noticed while investigating the implementation is that
mobile-networkcurrently supportsnativephp/mobile ^3.0 || ^4.0, whileBroadcastsGloballyis a v4 API.Would you prefer this feature to target NativePHP v4 and update the package constraint accordingly, or should
mobile-networkretain v3 compatibility and keep the event component-scoped?I'm happy to implement this and submit the PR once the preferred direction is clear.