mirror of
https://github.com/block/buzz.git
synced 2026-10-31 06:21:34 +00:00
fix(mobile/ios): configure push gateway URL
Co-authored-by: Tom Brow <tomb@block.xyz> Signed-off-by: Tom Brow <tomb@block.xyz>
This commit is contained in:
parent
aea7821412
commit
52fa0d20ef
@@ -1,4 +1,5 @@
|
||||
{
|
||||
"BUZZ_RELAY_URL": "http://localhost:3000",
|
||||
"BUZZ_PUSH_GATEWAY_URL": "http://localhost:8080",
|
||||
"BUZZ_DEV_PUBKEY": "<your-hex-pubkey-here>"
|
||||
}
|
||||
|
||||
@@ -252,12 +252,13 @@ import UserNotifications
|
||||
guard let arguments = call.arguments as? [String: Any],
|
||||
let relayText = arguments["relayUrl"] as? String,
|
||||
let relayURL = URL(string: relayText),
|
||||
let gatewayURL = URL(string: "http://localhost:8080")
|
||||
let gatewayText = arguments["gatewayUrl"] as? String,
|
||||
let gatewayURL = URL(string: gatewayText)
|
||||
else {
|
||||
result(
|
||||
FlutterError(
|
||||
code: "invalid_arguments",
|
||||
message: "Development push enrollment requires relayUrl.",
|
||||
message: "Development push enrollment requires relayUrl and gatewayUrl.",
|
||||
details: nil
|
||||
)
|
||||
)
|
||||
|
||||
@@ -57,7 +57,7 @@ class DebugPushLeaseBootstrap extends HookConsumerWidget {
|
||||
SignedEventRelay relay,
|
||||
) async {
|
||||
final descriptor = await fetchBuzzPushLeaseDescriptor(config.baseUrl);
|
||||
final grant = await enrollBuzzDevPush(config.wsUrl);
|
||||
final grant = await enrollBuzzDevPush(config.wsUrl, Env.pushGatewayUrl);
|
||||
if (grant.relayOrigin != descriptor.origin) {
|
||||
throw StateError(
|
||||
'Endpoint grant origin ${grant.relayOrigin} does not match descriptor origin ${descriptor.origin}',
|
||||
|
||||
@@ -83,7 +83,10 @@ Future<List<BuzzPushEndpointGrant>> readBuzzPushEndpointGrants() async {
|
||||
}
|
||||
}
|
||||
|
||||
Future<BuzzPushEndpointGrant> enrollBuzzDevPush(String relayUrl) async {
|
||||
Future<BuzzPushEndpointGrant> enrollBuzzDevPush(
|
||||
String relayUrl,
|
||||
String gatewayUrl,
|
||||
) async {
|
||||
if (!kDebugMode) {
|
||||
throw UnsupportedError(
|
||||
'Development push enrollment is unavailable outside debug builds.',
|
||||
@@ -91,7 +94,7 @@ Future<BuzzPushEndpointGrant> enrollBuzzDevPush(String relayUrl) async {
|
||||
}
|
||||
final raw = await _channel.invokeMapMethod<dynamic, dynamic>(
|
||||
'devEnrollPush',
|
||||
{'relayUrl': relayUrl},
|
||||
{'relayUrl': relayUrl, 'gatewayUrl': gatewayUrl},
|
||||
);
|
||||
if (raw == null) {
|
||||
throw StateError('Native development push enrollment returned no grant.');
|
||||
|
||||
@@ -62,7 +62,8 @@ class RelayConfig {
|
||||
/// Compile-time environment config via --dart-define.
|
||||
///
|
||||
/// Run with:
|
||||
/// flutter run --dart-define=BUZZ_RELAY_URL=http://localhost:3000
|
||||
/// flutter run --dart-define=BUZZ_RELAY_URL=http://localhost:3000 \
|
||||
/// --dart-define=BUZZ_PUSH_GATEWAY_URL=http://localhost:8080
|
||||
///
|
||||
/// Or create a `.env.json` and use --dart-define-from-file=.env.json
|
||||
class Env {
|
||||
@@ -70,6 +71,10 @@ class Env {
|
||||
'BUZZ_RELAY_URL',
|
||||
defaultValue: 'http://localhost:3000',
|
||||
);
|
||||
static const pushGatewayUrl = String.fromEnvironment(
|
||||
'BUZZ_PUSH_GATEWAY_URL',
|
||||
defaultValue: 'http://localhost:8080',
|
||||
);
|
||||
}
|
||||
|
||||
class RelayConfigNotifier extends Notifier<RelayConfig> {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:buzz/shared/push/push_bridge.dart';
|
||||
import 'package:buzz/shared/relay/relay_provider.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
@@ -63,16 +64,17 @@ void main() {
|
||||
});
|
||||
|
||||
test(
|
||||
'debug enrollment invokes native driver then refreshes grants',
|
||||
'debug enrollment carries the configured relay and gateway URLs',
|
||||
() async {
|
||||
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
|
||||
final methods = <String>[];
|
||||
final enrollmentArguments = <Object?>[];
|
||||
final messenger =
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger;
|
||||
messenger.setMockMethodCallHandler(_channel, (call) async {
|
||||
methods.add(call.method);
|
||||
if (call.method == 'devEnrollPush') {
|
||||
expect(call.arguments, {'relayUrl': 'wss://relay.example/'});
|
||||
enrollmentArguments.add(call.arguments);
|
||||
return _grantMap('new-grant');
|
||||
}
|
||||
if (call.method == 'endpointGrants') {
|
||||
@@ -81,14 +83,41 @@ void main() {
|
||||
fail('Unexpected method ${call.method}');
|
||||
});
|
||||
|
||||
final grant = await enrollBuzzDevPush('wss://relay.example/');
|
||||
final firstGrant = await enrollBuzzDevPush(
|
||||
'wss://relay.example/',
|
||||
'https://gateway-one.example/',
|
||||
);
|
||||
final secondGrant = await enrollBuzzDevPush(
|
||||
'wss://relay.example/',
|
||||
'https://gateway-two.example/',
|
||||
);
|
||||
|
||||
expect(grant.endpointGrant, 'new-grant');
|
||||
expect(methods, ['devEnrollPush', 'endpointGrants']);
|
||||
expect(firstGrant.endpointGrant, 'new-grant');
|
||||
expect(secondGrant.endpointGrant, 'new-grant');
|
||||
expect(enrollmentArguments, [
|
||||
{
|
||||
'relayUrl': 'wss://relay.example/',
|
||||
'gatewayUrl': 'https://gateway-one.example/',
|
||||
},
|
||||
{
|
||||
'relayUrl': 'wss://relay.example/',
|
||||
'gatewayUrl': 'https://gateway-two.example/',
|
||||
},
|
||||
]);
|
||||
expect(methods, [
|
||||
'devEnrollPush',
|
||||
'endpointGrants',
|
||||
'devEnrollPush',
|
||||
'endpointGrants',
|
||||
]);
|
||||
expect(pushEndpointGrants.value.single.endpointGrant, 'new-grant');
|
||||
},
|
||||
);
|
||||
|
||||
test('development push gateway uses the localhost compiled default', () {
|
||||
expect(Env.pushGatewayUrl, 'http://localhost:8080');
|
||||
});
|
||||
|
||||
test('persists the acknowledged push lease generation', () async {
|
||||
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
|
||||
final methods = <String>[];
|
||||
|
||||
Reference in New Issue
Block a user