From 6193544994c834551810539d81367f468d71f861 Mon Sep 17 00:00:00 2001 From: Miguel Medeiros <31278849+miguelcmedeiros@users.noreply.github.com> Date: Tue, 13 May 2025 14:31:33 +0200 Subject: [PATCH] Support pushing message with binary payload --- lib/src/channel.dart | 8 ++++---- lib/src/push.dart | 2 +- lib/src/socket.dart | 4 ++-- test/mocks.mocks.dart | 35 ++++++++++++++--------------------- 4 files changed, 21 insertions(+), 28 deletions(-) diff --git a/lib/src/channel.dart b/lib/src/channel.dart index f280d68..18f1bfb 100644 --- a/lib/src/channel.dart +++ b/lib/src/channel.dart @@ -43,7 +43,7 @@ class PhoenixChannel { PhoenixChannel.fromSocket( this.socket, { required this.topic, - Map? parameters, + dynamic parameters, Duration? timeout, }) : _controller = StreamController.broadcast(), _waiters = {}, @@ -57,7 +57,7 @@ class PhoenixChannel { } /// Parameters passed to the backend at join time. - final Map parameters; + final dynamic parameters; /// The [PhoenixSocket] through which this channel is established. final PhoenixSocket socket; @@ -247,7 +247,7 @@ class PhoenixChannel { /// The message payload. /// /// This needs to be a JSON encodable object. - Map payload, [ + dynamic payload, [ /// Manually set timeout value for this push. /// /// If not provided, the default timeout will be used. @@ -265,7 +265,7 @@ class PhoenixChannel { /// using [push] instead. Push pushEvent( PhoenixChannelEvent event, - Map payload, [ + dynamic payload, [ Duration? newTimeout, ]) { assert(_joinedOnce); diff --git a/lib/src/push.dart b/lib/src/push.dart index 8e03622..b348c21 100644 --- a/lib/src/push.dart +++ b/lib/src/push.dart @@ -69,7 +69,7 @@ class PushResponse { } /// Type of function that should return a push payload -typedef PayloadGetter = Map Function(); +typedef PayloadGetter = dynamic Function(); /// Object produced by [PhoenixChannel.push] to encapsulate /// the message sent and its lifecycle. diff --git a/lib/src/socket.dart b/lib/src/socket.dart index 3ce4468..a586736 100644 --- a/lib/src/socket.dart +++ b/lib/src/socket.dart @@ -342,7 +342,7 @@ class PhoenixSocket { return (_pendingMessages[message.ref!] = Completer()).future; } - void _addToSink(String data) { + void _addToSink(dynamic data) { if (_disposed) { return; } @@ -360,7 +360,7 @@ class PhoenixSocket { /// [parameters] are any options parameters you wish to send PhoenixChannel addChannel({ required String topic, - Map? parameters, + dynamic parameters, Duration? timeout, }) { PhoenixChannel? channel = channels[topic]; diff --git a/test/mocks.mocks.dart b/test/mocks.mocks.dart index 010aa7c..43dc92a 100644 --- a/test/mocks.mocks.dart +++ b/test/mocks.mocks.dart @@ -129,13 +129,6 @@ class _FakeMessageSerializer_8 extends _i1.SmartFake /// /// See the documentation for Mockito's code generation for more information. class MockPhoenixChannel extends _i1.Mock implements _i5.PhoenixChannel { - @override - Map get parameters => (super.noSuchMethod( - Invocation.getter(#parameters), - returnValue: {}, - returnValueForMissingStub: {}, - ) as Map); - @override _i2.PhoenixSocket get socket => (super.noSuchMethod( Invocation.getter(#socket), @@ -330,7 +323,7 @@ class MockPhoenixChannel extends _i1.Mock implements _i5.PhoenixChannel { @override _i4.Push push( String? eventName, - Map? payload, [ + dynamic payload, [ Duration? newTimeout, ]) => (super.noSuchMethod( @@ -369,7 +362,7 @@ class MockPhoenixChannel extends _i1.Mock implements _i5.PhoenixChannel { @override _i4.Push pushEvent( _i11.PhoenixChannelEvent? event, - Map? payload, [ + dynamic payload, [ Duration? newTimeout, ]) => (super.noSuchMethod( @@ -531,14 +524,14 @@ class MockPhoenixSocket extends _i1.Mock implements _i2.PhoenixSocket { ) as _i10.Stream<_i3.Message>); @override - _i10.Future<_i2.PhoenixSocket?> connect() => (super.noSuchMethod( + _i10.Future connect() => (super.noSuchMethod( Invocation.method( #connect, [], ), - returnValue: _i10.Future<_i2.PhoenixSocket?>.value(), - returnValueForMissingStub: _i10.Future<_i2.PhoenixSocket?>.value(), - ) as _i10.Future<_i2.PhoenixSocket?>); + returnValue: _i10.Future.value(), + returnValueForMissingStub: _i10.Future.value(), + ) as _i10.Future); @override void close([ @@ -618,7 +611,7 @@ class MockPhoenixSocket extends _i1.Mock implements _i2.PhoenixSocket { @override _i5.PhoenixChannel addChannel({ required String? topic, - Map? parameters, + dynamic parameters, Duration? timeout, }) => (super.noSuchMethod( @@ -678,13 +671,6 @@ class MockWebSocketChannel extends _i1.Mock implements _i6.WebSocketChannel { returnValueForMissingStub: _i10.Future.value(), ) as _i10.Future); - @override - _i10.Stream get stream => (super.noSuchMethod( - Invocation.getter(#stream), - returnValue: _i10.Stream.empty(), - returnValueForMissingStub: _i10.Stream.empty(), - ) as _i10.Stream); - @override _i6.WebSocketSink get sink => (super.noSuchMethod( Invocation.getter(#sink), @@ -698,6 +684,13 @@ class MockWebSocketChannel extends _i1.Mock implements _i6.WebSocketChannel { ), ) as _i6.WebSocketSink); + @override + _i10.Stream get stream => (super.noSuchMethod( + Invocation.getter(#stream), + returnValue: _i10.Stream.empty(), + returnValueForMissingStub: _i10.Stream.empty(), + ) as _i10.Stream); + @override void pipe(_i7.StreamChannel? other) => super.noSuchMethod( Invocation.method(