For more information on the MessagePort features, see MessagePort Guide.
Since: 2.1
typedef octet[] ByteStream;
Since: 3.0
typedef (DOMString or DOMString[]) StringDataItemValue;
typedef (ByteStream or ByteStream[]) ByteStreamDataItemValue;
typedef (MessagePortStringDataItem or MessagePortByteStreamDataItem) MessagePortDataItem;
[NoInterfaceObject] interface MessagePortManagerObject { readonly attribute MessagePortManager messageport; };
Tizen implements MessagePortManagerObject;
The tizen.messageport object allows access to the functionality of the Message Port API.
[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
LocalMessagePort requestLocalMessagePort(DOMString localMessagePortName);
Parameters:
Return value:
Exceptions:
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');
requestTrustedLocalMessagePort
LocalMessagePort requestTrustedLocalMessagePort(DOMString localMessagePortName);
Trusted local message port can communicate with applications that are signed with same certificate.
// Requests the LocalMessagePort instance with the specified message port name var localMsgPort = tizen.messageport.requestTrustedLocalMessagePort('MessagePortB');
requestRemoteMessagePort
RemoteMessagePort requestRemoteMessagePort(ApplicationId appId, DOMString remoteMessagePortName);
If the message port name and application ID are the same, the platform returns the same RemoteMessagePort instance.
with error type NotFoundError, if the port of the target application is not found.
// Requests the RemoteMessagePort instance with the specified message port name var remoteMsgPort = tizen.messageport.requestRemoteMessagePort('6xaeuflskd.App1', 'MessagePortA');
requestTrustedRemoteMessagePort
RemoteMessagePort requestTrustedRemoteMessagePort(ApplicationId appId, DOMString remoteMessagePortName);
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.
with error type InvalidAccessError, if the target application is not signed with the same certification.
with error type UnknownError, if any other error occurs
// Requests the RemoteMessagePort instance with the specified message port name. var remoteMsgPort = tizen.messageport.requestTrustedRemoteMessagePort('6xauflskd.App1', 'MessagePortB');
[NoInterfaceObject] interface LocalMessagePort { readonly attribute DOMString messagePortName; readonly attribute boolean isTrusted; long addMessagePortListener(MessagePortCallback listener) raises(WebAPIException); void removeMessagePortListener(long watchId) raises(WebAPIException); };
addMessagePortListener
long addMessagePortListener(MessagePortCallback listener);
function onreceived(data, remoteMsgPort) { console.log('Received data to \'' + remoteMsgPort.messagePortName + '\''); } var localMsgPort = tizen.messageport.requestLocalMessagePort('MessagePortA'); var watchId = localMsgPort.addMessagePortListener(onreceived);
removeMessagePortListener
void removeMessagePortListener(long watchId);
with error type NotFoundError, if the watch ID has not been found.
var localMsgPort = tizen.messageport.requestLocalMessagePort('MessagePortA'); var watchId = localMsgPort.addMessagePortListener(onreceived); // Communication routines of your app... localMsgPort.removeMessagePortListener(watchId);
[NoInterfaceObject] interface RemoteMessagePort { readonly attribute DOMString messagePortName; readonly attribute ApplicationId appId; readonly attribute boolean isTrusted; void sendMessage(MessagePortDataItem[] data, optional LocalMessagePort? localMessagePort) raises(WebAPIException); };
sendMessage
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 InvalidValuesError, if an input parameter contains an invalid value.
with error type QuotaExceededError, if the size of message has exceeded the maximum limit.
// Sends string message var localMsgPort = tizen.messageport.requestLocalMessagePort('MessagePortA'); var remoteMsgPort = tizen.messageport.requestRemoteMessagePort('6xaeuflskd.App1', 'MessagePortB'); localMsgPort.addMessagePortListener(function(items, remoteport) { // ... if(remoteport !== null) { remoteport.sendMessage([{key:'RESULT', value:'OK'}]); } }); // stream - FileStream object var bytePockets = [], byteCount = 0, i = 0; while(byteCount stream.bytesAvailable - 256) { bytePockets[i] = stream.readBytes(256); byteCount+=256; i++; } bytePockets[i] = stream.readBytes(stream.bytesAvailable - byteCount); var messagePortPockets = [{key: "key1", value: "val1"}, {key: "key2", value: ["val2", "val3", "val4"]}, {key: "key3", value: bytePockets[0]}, {key: "key4", value: bytePockets}]; remoteMsgPort.sendMessage(messagePortPockets, localMsgPort);
dictionary MessagePortStringDataItem { DOMString key; StringDataItemValue value; };
dictionary MessagePortByteStreamDataItem { DOMString key; ByteStreamDataItemValue value; };
[Callback=FunctionOnly, NoInterfaceObject] interface MessagePortCallback { void onreceived(MessagePortDataItem[] data, RemoteMessagePort? remoteMessagePort); };
onreceived
void onreceived(MessagePortDataItem[] data, RemoteMessagePort? remoteMessagePort);
// MessagePortCallback instance function onreceived(data, remoteMsgPort) { console.log('Received data to \'' + remoteMsgPort.messagePortName + '\''); } var localMsgPort = tizen.messageport.requestLocalMessagePort('MessagePortA'); var watchId = localMsgPort.addMessagePortListener(onreceived);
module MessagePort { typedef octet[] ByteStream; typedef (DOMString or DOMString[]) StringDataItemValue; typedef (ByteStream or ByteStream[]) ByteStreamDataItemValue; typedef (MessagePortStringDataItem or MessagePortByteStreamDataItem) MessagePortDataItem; [NoInterfaceObject] interface MessagePortManagerObject { readonly attribute MessagePortManager messageport; }; Tizen 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 MessagePortStringDataItem { DOMString key; StringDataItemValue value; }; dictionary MessagePortByteStreamDataItem { DOMString key; ByteStreamDataItemValue value; }; [Callback=FunctionOnly, NoInterfaceObject] interface MessagePortCallback { void onreceived(MessagePortDataItem[] data, RemoteMessagePort? remoteMessagePort); }; };