For more information on the MessagePort features, see MessagePort Guide.
Since: 2.4
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 | |
MessagePortStringDataItem | |
MessagePortByteStreamDataItem | |
MessagePortCallback |
typedef (DOMString or DOMString[]) StringDataItemValue;
Since: 3.0
typedef (ByteStream or ByteStream[]) ByteStreamDataItemValue;
Since: 3.0
typedef (MessagePortStringDataItem or MessagePortByteStreamDataItem) MessagePortDataItem;
Since: 3.0
[NoInterfaceObject] interface MessagePortManagerObject {
readonly attribute MessagePortManager messageport;
};
Tizen implements MessagePortManagerObject;
Since: 2.4
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);
};
Since: 2.4
requestLocalMessagePort
LocalMessagePort requestLocalMessagePort(DOMString localMessagePortName);
Since: 2.4
Parameters:
Return value:
LocalMessagePort LocalMessagePort instanceExceptions:
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);
Since: 2.4
Trusted local message port can communicate with applications that are signed with same certificate.
Parameters:
Return value:
LocalMessagePort Trusted LocalMessagePort instanceExceptions:
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');
requestRemoteMessagePort
RemoteMessagePort requestRemoteMessagePort(ApplicationId appId, DOMString remoteMessagePortName);
Since: 2.4
If the message port name and application ID are the same, the platform returns the same RemoteMessagePort instance.
Parameters:
Return value:
RemoteMessagePort RemoteMessagePort instanceExceptions:
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
RemoteMessagePort requestTrustedRemoteMessagePort(ApplicationId appId, DOMString remoteMessagePortName);
Since: 2.4
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:
Return value:
RemoteMessagePort Trusted RemoteMessagePort instanceExceptions:
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');
[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.4
Since: 2.4
Since: 2.4
addMessagePortListener
long addMessagePortListener(MessagePortCallback listener);
Since: 2.4
Parameters:
Return value:
long ID of the listener that is later used to remove the listenerExceptions:
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
void removeMessagePortListener(long watchId);
Since: 2.4
Parameters:
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 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);
[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.4
Since: 2.4
Since: 2.4
Since: 2.4
sendMessage
void sendMessage(MessagePortDataItem[] data, optional LocalMessagePort? localMessagePort);
Since: 2.4
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:
Exceptions:
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 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;
};
Since: 3.0
dictionary MessagePortByteStreamDataItem {
DOMString key;
ByteStreamDataItemValue value;
};
Since: 3.0
[Callback=FunctionOnly, NoInterfaceObject] interface MessagePortCallback {
void onreceived(MessagePortDataItem[] data, RemoteMessagePort? remoteMessagePort);
};
Since: 2.4
onreceived
void onreceived(MessagePortDataItem[] data, RemoteMessagePort? remoteMessagePort);
Since: 2.4
Parameters:
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);
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);
};
};