WebMessagePort class

The representation of the HTML5 message ports.

A Message port represents one endpoint of a Message Channel. In Android webview, there is no separate Message Channel object. When a message channel is created, both ports are tangled to each other and started. See InAppWebViewController.createWebMessageChannel for creating a message channel.

When a message port is first created or received via transfer, it does not have a WebMessageCallback to receive web messages. On Android, the messages are queued until a WebMessageCallback is set.

A message port should be closed when it is not used by the embedder application anymore. A closed port cannot be transferred or cannot be reopened to send messages. Close can be called multiple times.

When a port is transferred to JavaScript, it cannot be used to send or receive messages at the Dart side anymore. Different from HTML5 Spec, a port cannot be transferred if one of these has ever happened: i. a message callback was set, ii. a message was posted on it. A transferred port cannot be closed by the application, since the ownership is also transferred.

It is possible to transfer both ports of a channel to JavaScript, for example for communication between subframes.

Implemented types

Constructors

WebMessagePort({required int index})
The representation of the HTML5 message ports.
WebMessagePort.fromPlatform({required PlatformWebMessagePort platform})
Constructs a WebMessagePort from a specific platform implementation.
WebMessagePort.fromPlatformCreationParams({required PlatformWebMessagePortCreationParams params})
Constructs a WebMessagePort.

Properties

hashCode int
The hash code for this object.
no setterinherited
platform PlatformWebMessagePort
Implementation of PlatformWebMessagePort for the current platform.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

close() Future<void>
Close the message port and free any resources associated with it.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
postMessage(WebMessage message) Future<void>
Post a WebMessage to the entangled port.
override
setWebMessageCallback(WebMessageCallback? onMessage) Future<void>
Sets a callback to receive message events on the main thread.
override
toJson() Map<String, dynamic>
override
toMap() Map<String, dynamic>
override
toString() String
A string representation of this object.
override

Operators

operator ==(Object other) bool
The equality operator.
inherited