-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Add binaryMessenger constructor argument to platform channels #30406
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add binaryMessenger constructor argument to platform channels #30406
Conversation
By abstracting out the calls to [BinaryMessages] the same code can be used for platform channels on the platform side as on the framework side.
|
Curious what do you think about the alternative of using the same mechanism |
|
After several discussions, I think we plan to support 2 approaches for plugins:
|
ClassyRemade
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My name was not my intention. It's out there now!
|
Ping! |
|
@amirh @collinjackson @bparrishMines Can somebody review this? |
|
@Hixie FYI this PR incorporates the changes we talked about in our meeting a few weeks ago. |
|
This ends up being a bit convoluted, with BinaryMessages, BinaryMessenger, MethodChannel, BaseMethodChannel, BasicMessageChannel, and BaseMessageChannel. I'm not sure I'd be able to draw an accurate diagram of which class inherited from which, and which instantiated which, and which was static vs which was instantiatable, without referencing the code. Could we instead just make BinaryMessages non-static? i.e. refactor it so that you call through to an singleton instance of that class, much as we do with things like the ImageCache? Then for the framework side the binding could set it up, and on the plugin side the plugin could set it up. |
|
That might not work for the web case. On the web we compile all of the code (platform side and client side) into one executable, so we wouldn't be able to have the two different compilations set up the What do you think about changing this CL so that instead of introducing a super-class, we just add an optional |
|
@hterkelsen @Hixie what's the path forward here? Are there more changes needed to this, or is it ready to land? |
|
Sorry, haven't been checking my bugmail much recently. The new PR is much closer to something reasonable, I think. Can we go further and just have BinaryMessages be an instance instead of static? Then we don't need both BinaryMessenger and BinaryMessages, we can just have the interface (public), and the default implementation (also public, but instance methods instead of static methods, and used as the default value to the arguments added in the current PR). |
|
@hterkelsen - do you plan to continue with this? @Hixie - are these concerns meant to block landing this? At this point the PR has been open for over a month - if we don't think we can keep making progress forward with this approach perhaps we should close it. |
yes |
|
I like the approach in this patch. Please follow the breaking change policy (https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes). |
|
I'll defer to @amirh, @dnfield, or @goderbauer for final review. |
- Make the message handler typedef public. - Fix typos in comments. - Make clear that defaultBinaryMessenger has replaced BinaryMessages
|
I tried to send an email to I tried to send the following: As part of a change to generalize Platform Channels so they may be used in Web Plugins, I intend to deprecate BinaryMessages. Justification The platform channels use BinaryMessages to send messages from the application to the platform side. The proposed change Part of this change is to replace the collection of static methods in BinaryMessages with an interface for sending messages, Links to Issue and PR Migration Steps defaultBinaryMessenger is a drop-in replacement for BinaryMessages. Simply find and replace every instance of BinaryMessages with defaultBinaryMessages. Before: BinaryMessages.setMessageHandler('my-channel', myHandler); After: defaultBinaryMessenger.setMessageHandler('my-channel', myHandler); Conclusion Please comment on the issue or contact me directly if this change will cause you any issues. Thanks! |
|
cc @kf6gpe for help with flutter-announce. |
|
@hterkelsen Thanks for the pending contribution! I can give you posting rights to flutter-announce --- reach out to me at the email on my github page and we'll get you set up. Thanks! |
| /// Neither [name] nor [codec] may be null. | ||
| const BasicMessageChannel(this.name, this.codec); | ||
| /// None of [name], [codec], or [binaryMessenger] may be null. | ||
| const BasicMessageChannel(this.name, this.codec, [ this.binaryMessenger = defaultBinaryMessenger ]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make this a named parameter rather than an optional one? e.g. { this.binaryMessenger = defaultBinaryMessenger }? This ends up getting ugly/confusing if we have to add more parameters later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I did it this way because MethodChannel has an optional argument for this.codec so I could only add binaryMessenger as another optional argument.
|
I believe it should be api.flutter.dev.
…On Wed, May 22, 2019 at 9:45 AM Dan Field ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In packages/flutter/lib/src/services/platform_channel.dart
<#30406 (comment)>:
> @@ -287,12 +301,12 @@ class MethodChannel {
/// [StandardMethodCodec].
/// * [JSONMessageCodec] which defines the payload values supported by
/// [JSONMethodCodec].
- /// * <https://docs.flutter.io/javadoc/io/flutter/plugin/common/MethodCall.html>
+ /// * <https://docs.flutter.dev/javadoc/io/flutter/plugin/common/MethodCall.html>
Is this ready? Last I heard the docs wasn't ready for .dev links.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#30406?email_source=notifications&email_token=AAEGSHG3QWETXIVLNUMA4MDPWV2CBA5CNFSM4HDE3AP2YY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOBZMZQJA#pullrequestreview-240752676>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAEGSHBGO7V5PZP6X7APU7TPWV2CBANCNFSM4HDE3APQ>
.
--
Ian Hickson
|
|
We're ready for links to api.flutter.dev at this point, yes. Thanks!
On Wed, May 22, 2019 at 10:22 AM Ian Hickson <notifications@github.com>
wrote:
… I believe it should be api.flutter.dev.
On Wed, May 22, 2019 at 9:45 AM Dan Field ***@***.***>
wrote:
> ***@***.**** commented on this pull request.
> ------------------------------
>
> In packages/flutter/lib/src/services/platform_channel.dart
> <#30406 (comment)>:
>
> > @@ -287,12 +301,12 @@ class MethodChannel {
> /// [StandardMethodCodec].
> /// * [JSONMessageCodec] which defines the payload values supported by
> /// [JSONMethodCodec].
> - /// * <
https://docs.flutter.io/javadoc/io/flutter/plugin/common/MethodCall.html>
> + /// * <
https://docs.flutter.dev/javadoc/io/flutter/plugin/common/MethodCall.html>
>
> Is this ready? Last I heard the docs wasn't ready for .dev links.
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <
#30406?email_source=notifications&email_token=AAEGSHG3QWETXIVLNUMA4MDPWV2CBA5CNFSM4HDE3AP2YY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOBZMZQJA#pullrequestreview-240752676
>,
> or mute the thread
> <
https://github.com/notifications/unsubscribe-auth/AAEGSHBGO7V5PZP6X7APU7TPWV2CBANCNFSM4HDE3APQ
>
> .
>
--
Ian Hickson
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#30406?email_source=notifications&email_token=AAK6QRDYFM4OQTHVGPE42JTPWV6M3A5CNFSM4HDE3AP2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODV7XI4Q#issuecomment-494892146>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAK6QRAYQFZXSXL3PPDPGKLPWV6M3ANCNFSM4HDE3APQ>
.
|
- make binaryMessenger a named argument in BasicMessageChannel
|
Thanks, @dnfield. PTAL |
dnfield
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
Thanks! I'll land this tomorrow once the build is fixed and my breaking change announcement has been posted for 24 hours. |
flutter/flutter#30406 deprecated the usage of static BinaryMessages methods. As we cannot use the new defaultBinaryMessages mechanism before it makes it to stable, for now, we suppress the warnings.
…r#30406) * Deprecates `BinaryMessages` in favor of a default instance of `BinaryMessenger`, called `defaultBinaryMessenger` * Platform channels use the `defaultBinaryMessenger` for their binaryMessenger default argument.
flutter/flutter#30406 deprecated the usage of static BinaryMessages methods. As we cannot use the new defaultBinaryMessages mechanism before it makes it to stable, for now, we suppress the warnings.
flutter/flutter#30406 deprecated the usage of static BinaryMessages methods. As we cannot use the new defaultBinaryMessages mechanism before it makes it to stable, for now, we suppress the warnings.
flutter/flutter#30406 deprecated the usage of static BinaryMessages methods. As we cannot use the new defaultBinaryMessages mechanism before it makes it to stable, for now, we suppress the warnings.
By abstracting out the calls to [BinaryMessages] the same code
can be used for platform channels on the platform side as on the
framework side.
Description
This PR adds base classes to MethodChannel and BasicMessageChannel, which abstracts out a 'BinaryMessenger' which is responsible for actually moving the bytes across the platform divide. The existing Channel implementations use BinaryMessages to implement their BinaryMessenger. The "dual" channel, which sends messages from the platform side to the framework side, would use a different BinaryMessenger.
Related Issues
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]). This will ensure a smooth and quick review process.///).flutter analyze --flutter-repo) does not report any problems on my PR.Breaking Change
Does your PR require Flutter developers to manually update their apps to accommodate your change?