Skip to content

Commit 3047f4a

Browse files
Support pushing message with binary payload (#13)
1 parent e01492c commit 3047f4a

4 files changed

Lines changed: 21 additions & 28 deletions

File tree

lib/src/channel.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class PhoenixChannel {
4343
PhoenixChannel.fromSocket(
4444
this.socket, {
4545
required this.topic,
46-
Map<String, dynamic>? parameters,
46+
dynamic parameters,
4747
Duration? timeout,
4848
}) : _controller = StreamController.broadcast(),
4949
_waiters = {},
@@ -57,7 +57,7 @@ class PhoenixChannel {
5757
}
5858

5959
/// Parameters passed to the backend at join time.
60-
final Map<String, dynamic> parameters;
60+
final dynamic parameters;
6161

6262
/// The [PhoenixSocket] through which this channel is established.
6363
final PhoenixSocket socket;
@@ -247,7 +247,7 @@ class PhoenixChannel {
247247
/// The message payload.
248248
///
249249
/// This needs to be a JSON encodable object.
250-
Map<String, dynamic> payload, [
250+
dynamic payload, [
251251
/// Manually set timeout value for this push.
252252
///
253253
/// If not provided, the default timeout will be used.
@@ -265,7 +265,7 @@ class PhoenixChannel {
265265
/// using [push] instead.
266266
Push pushEvent(
267267
PhoenixChannelEvent event,
268-
Map<String, dynamic> payload, [
268+
dynamic payload, [
269269
Duration? newTimeout,
270270
]) {
271271
assert(_joinedOnce);

lib/src/push.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class PushResponse {
6969
}
7070

7171
/// Type of function that should return a push payload
72-
typedef PayloadGetter = Map<String, dynamic> Function();
72+
typedef PayloadGetter = dynamic Function();
7373

7474
/// Object produced by [PhoenixChannel.push] to encapsulate
7575
/// the message sent and its lifecycle.

lib/src/socket.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ class PhoenixSocket {
342342
return (_pendingMessages[message.ref!] = Completer<Message>()).future;
343343
}
344344

345-
void _addToSink(String data) {
345+
void _addToSink(dynamic data) {
346346
if (_disposed) {
347347
return;
348348
}
@@ -360,7 +360,7 @@ class PhoenixSocket {
360360
/// [parameters] are any options parameters you wish to send
361361
PhoenixChannel addChannel({
362362
required String topic,
363-
Map<String, dynamic>? parameters,
363+
dynamic parameters,
364364
Duration? timeout,
365365
}) {
366366
PhoenixChannel? channel = channels[topic];

test/mocks.mocks.dart

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,6 @@ class _FakeMessageSerializer_8 extends _i1.SmartFake
129129
///
130130
/// See the documentation for Mockito's code generation for more information.
131131
class MockPhoenixChannel extends _i1.Mock implements _i5.PhoenixChannel {
132-
@override
133-
Map<String, dynamic> get parameters => (super.noSuchMethod(
134-
Invocation.getter(#parameters),
135-
returnValue: <String, dynamic>{},
136-
returnValueForMissingStub: <String, dynamic>{},
137-
) as Map<String, dynamic>);
138-
139132
@override
140133
_i2.PhoenixSocket get socket => (super.noSuchMethod(
141134
Invocation.getter(#socket),
@@ -330,7 +323,7 @@ class MockPhoenixChannel extends _i1.Mock implements _i5.PhoenixChannel {
330323
@override
331324
_i4.Push push(
332325
String? eventName,
333-
Map<String, dynamic>? payload, [
326+
dynamic payload, [
334327
Duration? newTimeout,
335328
]) =>
336329
(super.noSuchMethod(
@@ -369,7 +362,7 @@ class MockPhoenixChannel extends _i1.Mock implements _i5.PhoenixChannel {
369362
@override
370363
_i4.Push pushEvent(
371364
_i11.PhoenixChannelEvent? event,
372-
Map<String, dynamic>? payload, [
365+
dynamic payload, [
373366
Duration? newTimeout,
374367
]) =>
375368
(super.noSuchMethod(
@@ -531,14 +524,14 @@ class MockPhoenixSocket extends _i1.Mock implements _i2.PhoenixSocket {
531524
) as _i10.Stream<_i3.Message>);
532525

533526
@override
534-
_i10.Future<_i2.PhoenixSocket?> connect() => (super.noSuchMethod(
527+
_i10.Future<void> connect() => (super.noSuchMethod(
535528
Invocation.method(
536529
#connect,
537530
[],
538531
),
539-
returnValue: _i10.Future<_i2.PhoenixSocket?>.value(),
540-
returnValueForMissingStub: _i10.Future<_i2.PhoenixSocket?>.value(),
541-
) as _i10.Future<_i2.PhoenixSocket?>);
532+
returnValue: _i10.Future<void>.value(),
533+
returnValueForMissingStub: _i10.Future<void>.value(),
534+
) as _i10.Future<void>);
542535

543536
@override
544537
void close([
@@ -618,7 +611,7 @@ class MockPhoenixSocket extends _i1.Mock implements _i2.PhoenixSocket {
618611
@override
619612
_i5.PhoenixChannel addChannel({
620613
required String? topic,
621-
Map<String, dynamic>? parameters,
614+
dynamic parameters,
622615
Duration? timeout,
623616
}) =>
624617
(super.noSuchMethod(
@@ -678,13 +671,6 @@ class MockWebSocketChannel extends _i1.Mock implements _i6.WebSocketChannel {
678671
returnValueForMissingStub: _i10.Future<void>.value(),
679672
) as _i10.Future<void>);
680673

681-
@override
682-
_i10.Stream<dynamic> get stream => (super.noSuchMethod(
683-
Invocation.getter(#stream),
684-
returnValue: _i10.Stream<dynamic>.empty(),
685-
returnValueForMissingStub: _i10.Stream<dynamic>.empty(),
686-
) as _i10.Stream<dynamic>);
687-
688674
@override
689675
_i6.WebSocketSink get sink => (super.noSuchMethod(
690676
Invocation.getter(#sink),
@@ -698,6 +684,13 @@ class MockWebSocketChannel extends _i1.Mock implements _i6.WebSocketChannel {
698684
),
699685
) as _i6.WebSocketSink);
700686

687+
@override
688+
_i10.Stream<dynamic> get stream => (super.noSuchMethod(
689+
Invocation.getter(#stream),
690+
returnValue: _i10.Stream<dynamic>.empty(),
691+
returnValueForMissingStub: _i10.Stream<dynamic>.empty(),
692+
) as _i10.Stream<dynamic>);
693+
701694
@override
702695
void pipe(_i7.StreamChannel<dynamic>? other) => super.noSuchMethod(
703696
Invocation.method(

0 commit comments

Comments
 (0)