© 2014 Samsung Electronics Co., Ltd. All rights reserved.
This API provides the functionality for communicating with other applications.
Interface | Method |
---|---|
MessagePortManagerObject | |
MessagePortManager | LocalMessagePort requestLocalMessagePort(DOMString localMessagePortName) LocalMessagePort requestTrustedLocalMessagePort(DOMString localMessagePortName) RemoteMessagePort requestRemoteMessagePort(ApplicationId appId, DOMString remoteMessagePortName) RemoteMessagePort requestTrustedRemoteMessagePort(ApplicationId appId, DOMString remoteMessagePortName) |
LocalMessagePort | long addMessagePortListener(MessagePortCallback listener) void removeMessagePortListener(long watchId) |
RemoteMessagePort | void sendMessage(MessagePortDataItem[] data, LocalMessagePort? localMessagePort) |
MessagePortDataItem | |
MessagePortCallback | void onreceived(MessagePortDataItem[] data, RemoteMessagePort? remoteMessagePort) |
The MessagePortManagerObject interface defines what is instantiated by the WebAPIs object.
[NoInterfaceObject] interface MessagePortManagerObject { readonly attribute MessagePortManager messageport; };
WebAPIs implements MessagePortManagerObject;
There is a webapis.messageport object that allows access to the functionality of the Message Port API.
The MessagePortManager interface provides methods to request message port to communicate.
[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); };
requestLocalMessagePort
Requests a LocalMessage Port instance to start receiving message from another application.
LocalMessagePort requestLocalMessagePort(DOMString localMessagePortName);
with error type UnknownError, if any other error occurs.
with error type InvalidValuesError, if the input parameter contains an invalid value.
with error type TypeMismatchError, if the input parameter is not compatible with the expected type.
// Requests the LocalMessagePort instance with the specified message port name var localMsgPort = webapis.messageport.requestLocalMessagePort('MessagePortA');
requestTrustedLocalMessagePort
Requests a trusted LocalMessagePort instance to receive message from another application.
LocalMessagePort requestTrustedLocalMessagePort(DOMString localMessagePortName);
Trusted local message port can communicate with applications that are signed with same certificate.
with error type UnknownError, if any other error occurs.
with error type InvalidValuesError, if the input parameter contains an invalid value.
with error type TypeMismatchError, if the input parameter is not compatible with the expected type.
// Requests the LocalMessagePort instance with the specified message port name var localMsgPort = webapis.messageport.requestTrustedLocalMessagePort('MessagePortB');
requestRemoteMessagePort
Requests a RemoteMessagePort instance to send message to another application.
RemoteMessagePort requestRemoteMessagePort(ApplicationId appId, DOMString remoteMessagePortName);
If the message port name and application ID is the same, the platform returns the same RemoteMessagePort instance.
with error type UnknownError, if any other error occurs.
with error type NotFoundError, if the port of the target application is not found.
with error type InvalidValuesError, if an input parameter contains an invalid value.
with error type TypeMismatchError, if the input parameter is not compatible with the expected type.
// Requests the RemoteMessagePort instance with the specified message port name var remoteMsgPort = webapis.messageport.requestRemoteMessagePort('6xaeuflskd.App1', 'MessagePortA');
requestTrustedRemoteMessagePort
Requests a trusted RemoteMessagePort instance to receive message from another application.
RemoteMessagePort requestTrustedRemoteMessagePort(ApplicationId appId, DOMString remoteMessagePortName);
If the message port name and application ID is the same, the platform returns the same RemoteMessagePort instance. Trusted remote message port can communicate with applications that are signed with same certificate.
with error type UnknownError, if any other error occurs
with error type InvalidAccessError, if the target application is not signed with the same certification.
with error type NotFoundError, if the port of the target application is not found.
with error type InvalidValuesError, if an input parameter contains an invalid value.
with error type TypeMismatchError, if the input parameter is not compatible with the expected type.
// Requests the RemoteMessagePort instance with the specified message port name. var remoteMsgPort = webapis.messageport.requestTrustedRemoteMessagePort('6xauflskd.App1', 'MessagePortB');
The LocalMessagePort interface provides methods to receive data.
[NoInterfaceObject] interface LocalMessagePort { readonly attribute DOMString messagePortName; readonly attribute boolean isTrusted; long addMessagePortListener(MessagePortCallback listener) raises(WebAPIException); void removeMessagePortListener(long watchId) raises(WebAPIException); };
readonly
DOMString messagePortName
An attribute that stores the name of the message port name.
readonly
boolean isTrusted
An attribute that determines whether the message port is trusted or not.
addMessagePortListener
Adds a message port listener to receive messages from other applications.
long addMessagePortListener(MessagePortCallback listener);
with error type UnknownError, if any other error occurs.
with error type InvalidValuesError, if the input parameter contains an invalid value.
with error type TypeMismatchError, if the input parameter is not compatible with the expected type.
function onreceived(data, remoteMsgPort) { console.log('Received data to \'' + remoteMsgPort.messagePortName + '\''); } var localMsgPort = webapis.messageport.requestLocalMessagePort('MessagePortA'); var watchId = localMsgPort.addMessagePortListener(onreceived);
removeMessagePortListener
Removes the message port listener.
void removeMessagePortListener(long watchId);
with error type UnknownError, if any other error occurs.
with error type NotFoundError, if the watch ID has not been found.
with error type InvalidValuesError, if the input parameter contains an invalid value.
with error type TypeMismatchError, if the input parameter is not compatible with the expected type.
var localMsgPort = webapis.messageport.requestLocalMessagePort('MessagePortA'); var watchId = localMsgPort.addMessagePortListener(onreceived); // Communication routines of your app... localMsgPort.removeMessagePortListener(watchId);
The RemoteMessagePort interface provides methods to send messages.
[NoInterfaceObject] interface RemoteMessagePort { readonly attribute DOMString messagePortName; readonly attribute ApplicationId appId; readonly attribute boolean isTrusted; void sendMessage(MessagePortDataItem[] data, optional LocalMessagePort? localMessagePort) raises(WebAPIException); };
readonly
DOMString messagePortName
An attribute to store the message port name.
readonly
ApplicationId appId
An attribute that store the application ID to connect with.
readonly
boolean isTrusted
An attribute that determines whether the message port is trusted or not.
sendMessage
Sends messages to the specified application.
void sendMessage(MessagePortDataItem[] data, optional LocalMessagePort? localMessagePort);
The sent messages will be ignored without any notice, unless the target application added one or more listeners to the target local message port.
with error type UnknownError, if any other error occurs.
with error type QuotaExceededError, if the size of message has exceeded the maximum limit.
with error type InvalidValuesError, if an input parameter contains an invalid value.
with error type TypeMismatchError, if the input parameter is not compatible with the expected type.
// Sends message var localMsgPort = webapis.messageport.requestLocalMessagePort('MessagePortA'); var remoteMsgPort = webapis.messageport.requestRemoteMessagePort('6xaeuflskd.App1', 'MessagePortB'); localMsgPort.addMessagePortListener(function(items, remoteport) { // ... if(remoteport !== null) { remoteport.sendMessage([{key:'RESULT', value:'OK'}]); } }); remoteMsgPort.sendMessage( [ { key:'CMD', value:'openWindow' }, { key:'OPTION', value:'bx' } ] , localMsgPort);
A dictionary for specifying the data item that is transferred.
dictionary MessagePortDataItem { DOMString key; DOMString value; };
This interface defines notification callbacks for receiving data from other applications.
[Callback=FunctionOnly, NoInterfaceObject] interface MessagePortCallback { void onreceived(MessagePortDataItem[] data, RemoteMessagePort? remoteMessagePort); };
onreceived
Called when data is received from other applications via the specified message port name.
void onreceived(MessagePortDataItem[] data, RemoteMessagePort? remoteMessagePort);
module MessagePort { [NoInterfaceObject] interface MessagePortManagerObject { readonly attribute MessagePortManager messageport; }; WebAPIs implements MessagePortManagerObject; [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); }; dictionary MessagePortDataItem { DOMString key; DOMString value; }; [Callback=FunctionOnly, NoInterfaceObject] interface MessagePortCallback { void onreceived(MessagePortDataItem[] data, RemoteMessagePort? remoteMessagePort); }; };