MessagePort API
For more information on the Message Port features, see Message Port Guide.
Since: 2.1
Table of Contents
- 1. Interfaces
- 1.1. MessagePortManagerObject
- 1.2. MessagePortManager
- 1.3. LocalMessagePort
- 1.4. RemoteMessagePort
- 1.5. MessagePortDataItem
- 1.6. MessagePortCallback
- 2. Full WebIDL
Summary of Interfaces and Methods
Interface | Method |
---|---|
MessagePortManagerObject | |
MessagePortManager |
LocalMessagePort requestLocalMessagePort (DOMString localMessagePortName)
LocalMessagePort requestTrustedLocalMessagePort (DOMString localMessagePortName)
RemoteMessagePort requestTrustedRemoteMessagePort (ApplicationId appId, DOMString remoteMessagePortName)
|
LocalMessagePort |
long addMessagePortListener (MessagePortCallback listener)
void removeMessagePortListener (long watchId)
|
RemoteMessagePort | |
MessagePortDataItem | |
MessagePortCallback |
1. Interfaces
1.1. MessagePortManagerObject
[NoInterfaceObject] interface MessagePortManagerObject { readonly attribute MessagePortManager messageport; };
Tizen implements MessagePortManagerObject;
Since: 2.1
The tizen.messageport object allows access to the functionality of the Message Port API.
Attributes
-
readonly
MessagePortManager messageportObject representing a exif manager.
Since: 2.1
1.2. MessagePortManager
[NoInterfaceObject] interface MessagePortManager { LocalMessagePort requestLocalMessagePort(DOMString localMessagePortName) raises(WebAPIException); LocalMessagePort requestTrustedLocalMessagePort(DOMString localMessagePortName) raises(WebAPIException); RemoteMessagePort requestRemoteMessagePort(ApplicationId appId, DOMString remoteMessagePortName) raises(WebAPIException); RemoteMessagePort requestTrustedRemoteMessagePort(ApplicationId appId, DOMString remoteMessagePortName) raises(WebAPIException); };
Since: 2.1
Methods
-
requestLocalMessagePort
-
Requests a LocalMessagePort instance to start receiving message from another application.
LocalMessagePort requestLocalMessagePort(DOMString localMessagePortName);
Since: 2.1
Parameters:
-
localMessagePortName:
Name of the local message port to retrieve
The LocalMessagePort instances are identical for the same message port name.
Return value:
-
LocalMessagePort:
LocalMessagePort instance.
Exceptions:
- WebAPIException
with error type TypeMismatchError, if the input parameter is not compatible with the expected type.
with error type InvalidValuesError, if the input parameter contains an invalid value.
with error type UnknownError, if any other error occurs.
Code example:
/* Requests the LocalMessagePort instance with the specified message port name. */ var localMsgPort = tizen.messageport.requestLocalMessagePort("MessagePortA");
-
localMessagePortName:
Name of the local message port to retrieve
-
requestTrustedLocalMessagePort
-
Requests a trusted LocalMessagePort instance to receive message from another application.
LocalMessagePort requestTrustedLocalMessagePort(DOMString localMessagePortName);
Since: 2.1
Trusted local message port can communicate with applications that are signed with same certificate.
Parameters:
-
localMessagePortName:
Name of local message port
The LocalMessagePort instances are identical for the same message port name.
Return value:
-
LocalMessagePort:
Trusted LocalMessagePort instance.
Exceptions:
- WebAPIException
with error type TypeMismatchError, if the input parameter is not compatible with the expected type.
with error type InvalidValuesError, if the input parameter contains an invalid value.
with error type UnknownError, if any other error occurs.
Code example:
/* Requests the LocalMessagePort instance with the specified message port name. */ var localMsgPort = tizen.messageport.requestTrustedLocalMessagePort("MessagePortB");
-
localMessagePortName:
Name of local message port
-
requestRemoteMessagePort
-
Requests a RemoteMessagePort instance to send message to another application.
RemoteMessagePort requestRemoteMessagePort(ApplicationId appId, DOMString remoteMessagePortName);
Since: 2.1
If the message port name and application ID are the same, the platform returns the same RemoteMessagePort instance.
Parameters:
- appId: ID of the application to send messages.
- remoteMessagePortName: Name of remote message port.
Return value:
-
RemoteMessagePort:
RemoteMessagePort instance.
Exceptions:
- WebAPIException
with error type NotFoundError, if the port of the target application is not found.
with error type UnknownError, if any other error occurs.
Code example:
/* Requests the RemoteMessagePort instance with the specified message port name. */ var remoteMsgPort = tizen.messageport.requestRemoteMessagePort("6xaeuflskd.App1", "MessagePortA");
-
requestTrustedRemoteMessagePort
-
Requests a trusted RemoteMessagePort instance to receive message from another application.
RemoteMessagePort requestTrustedRemoteMessagePort(ApplicationId appId, DOMString remoteMessagePortName);
Since: 2.1
If the message port name and application ID are the same, the platform returns the same RemoteMessagePort instance. Trusted remote message port can communicate with applications that are signed with same certificate.
Parameters:
- appId: ID of the application to send messages.
- remoteMessagePortName: Name of remote message port.
Return value:
-
RemoteMessagePort:
Trusted RemoteMessagePort instance.
Exceptions:
- WebAPIException
with error type NotFoundError, if the port of the target application is not found.
with error type InvalidAccessError, if the target application is not signed with the same certification.
with error type UnknownError, if any other error occurs
Code example:
/* Requests the RemoteMessagePort instance with the specified message port name. */ var remoteMsgPort = tizen.messageport.requestTrustedRemoteMessagePort("6xauflskd.App1", "MessagePortB");
1.3. LocalMessagePort
[NoInterfaceObject] interface LocalMessagePort { readonly attribute DOMString messagePortName; readonly attribute boolean isTrusted; long addMessagePortListener(MessagePortCallback listener) raises(WebAPIException); void removeMessagePortListener(long watchId) raises(WebAPIException); };
Since: 2.1
Attributes
-
readonly
DOMString messagePortNameThe name of the message port name.
Since: 2.1
-
readonly
boolean isTrustedThe flag indicating whether the message port is trusted.
Since: 2.1
Methods
-
addMessagePortListener
-
Adds a message port listener to receive messages from other applications.
long addMessagePortListener(MessagePortCallback listener);
Since: 2.1
Parameters:
- listener: Callback function that is called when a message is received.
Return value:
-
long:
ID of the listener that is later used to remove the listener.
Exceptions:
- WebAPIException
with error type TypeMismatchError, if the input parameter is not compatible with the expected type.
with error type InvalidValuesError, if the input parameter contains an invalid value.
with error type UnknownError, if any other error occurs.
Code example:
function onreceived(data, remoteMsgPort) { console.log("Received data to '" + remoteMsgPort.messagePortName + "'"); } var localMsgPort = tizen.messageport.requestLocalMessagePort("MessagePortA"); var watchId = localMsgPort.addMessagePortListener(onreceived);
-
removeMessagePortListener
-
Removes the message port listener.
void removeMessagePortListener(long watchId);
Since: 2.1
Parameters:
- watchId: ID to identify the listener.
Exceptions:
- WebAPIException
with error type TypeMismatchError, if the input parameter is not compatible with the expected type.
with error type InvalidValuesError, if the input parameter contains an invalid value.
with error type NotFoundError, if the watch ID has not been found.
with error type UnknownError, if any other error occurs.
Code example:
var localMsgPort = tizen.messageport.requestLocalMessagePort("MessagePortA"); var watchId = localMsgPort.addMessagePortListener(onreceived); /* Communication routines of your app. */ localMsgPort.removeMessagePortListener(watchId);
1.4. RemoteMessagePort
[NoInterfaceObject] interface RemoteMessagePort { readonly attribute DOMString messagePortName; readonly attribute ApplicationId appId; readonly attribute boolean isTrusted; void sendMessage(MessagePortDataItem[] data, optional LocalMessagePort? localMessagePort) raises(WebAPIException); };
Since: 2.1
Attributes
-
readonly
DOMString messagePortNameThe message port name.
Since: 2.1
-
readonly
ApplicationId appIdThe application ID to connect with.
Since: 2.1
-
readonly
boolean isTrustedThe flag indicating whether the message port is trusted.
Since: 2.1
Methods
-
sendMessage
-
Sends messages to the specified application.
void sendMessage(MessagePortDataItem[] data, optional LocalMessagePort? localMessagePort);
Since: 2.1
The sent messages will be ignored without any notice, unless the target application added one or more listeners to the target local message port.
Parameters:
- data: Array of data to send.
-
localMessagePort [optional] [nullable]:
LocalMessagePort object that gives local message port of the current application
It can be used to receive reply messages from the other end of the message port.
The order of items in this array is not guaranteed to be preserved during data transfer, and values of key within this array must not be duplicated or empty.
Exceptions:
- WebAPIException
with error type TypeMismatchError, if the input parameter is not compatible with the expected type.
with error type InvalidValuesError, if an input parameter contains an invalid value.
with error type QuotaExceededError, if the size of message has exceeded the maximum limit.
with error type UnknownError, if any other error occurs.
Code example:
/* Sends message. */ var localMsgPort = tizen.messageport.requestLocalMessagePort("MessagePortA"); /* Assuming the message port of application with id: "6xaeuflskd.App1" is registered. */ var remoteMsgPort = tizen.messageport.requestRemoteMessagePort("6xaeuflskd.App1", "MessagePortB"); localMsgPort.addMessagePortListener(function(items, remoteport) { /* Do something. */ if (remoteport !== null) { remoteport.sendMessage([{key: "RESULT", value: "OK"}]); } }); remoteMsgPort.sendMessage( [{key: "CMD", value: "openWindow"}, {key: "OPTION", value: "bx"}], localMsgPort);
1.5. MessagePortDataItem
dictionary MessagePortDataItem { DOMString key; DOMString value; };
Since: 2.1
1.6. MessagePortCallback
[Callback=FunctionOnly, NoInterfaceObject] interface MessagePortCallback { void onreceived(MessagePortDataItem[] data, RemoteMessagePort? remoteMessagePort); };
Since: 2.1
Methods
-
onreceived
-
Called when data is received from other applications via the specified message port name.
void onreceived(MessagePortDataItem[] data, RemoteMessagePort? remoteMessagePort);
Since: 2.1
Parameters:
- data: Array of data received from another application.
- remoteMessagePort [nullable]: RemoteMessagePort port that can be used to reply for the received message.
Code example:
/* MessagePortCallback instance. */ function onreceived(data, remoteMsgPort) { console.log("Received data to '" + remoteMsgPort.messagePortName + "'"); } var localMsgPort = tizen.messageport.requestLocalMessagePort("MessagePortA"); var watchId = localMsgPort.addMessagePortListener(onreceived);
2. Full WebIDL
module MessagePort { dictionary MessagePortDataItem { DOMString key; DOMString value; }; Tizen implements MessagePortManagerObject; [NoInterfaceObject] interface MessagePortManagerObject { readonly attribute MessagePortManager messageport; }; [NoInterfaceObject] interface MessagePortManager { LocalMessagePort requestLocalMessagePort(DOMString localMessagePortName) raises(WebAPIException); LocalMessagePort requestTrustedLocalMessagePort(DOMString localMessagePortName) raises(WebAPIException); RemoteMessagePort requestRemoteMessagePort(ApplicationId appId, DOMString remoteMessagePortName) raises(WebAPIException); RemoteMessagePort requestTrustedRemoteMessagePort(ApplicationId appId, DOMString remoteMessagePortName) raises(WebAPIException); }; [NoInterfaceObject] interface LocalMessagePort { readonly attribute DOMString messagePortName; readonly attribute boolean isTrusted; long addMessagePortListener(MessagePortCallback listener) raises(WebAPIException); void removeMessagePortListener(long watchId) raises(WebAPIException); }; [NoInterfaceObject] interface RemoteMessagePort { readonly attribute DOMString messagePortName; readonly attribute ApplicationId appId; readonly attribute boolean isTrusted; void sendMessage(MessagePortDataItem[] data, optional LocalMessagePort? localMessagePort) raises(WebAPIException); }; [Callback=FunctionOnly, NoInterfaceObject] interface MessagePortCallback { void onreceived(MessagePortDataItem[] data, RemoteMessagePort? remoteMessagePort); }; };