From: Piotr Czaja Date: Wed, 3 Feb 2016 09:49:45 +0000 (+0100) Subject: [Messageport] Update dev guide and tutorial X-Git-Tag: tizen_3.0/TD_SYNC/20161201~172^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c98acfdb5dd708f83ff7d8e202bcb108bfa2b51d;p=sdk%2Fonline-doc.git [Messageport] Update dev guide and tutorial Change-Id: I7267fbbe181bd85f0dbbb076679595a8c115f398 Signed-off-by: Piotr Czaja --- diff --git a/org.tizen.guides/html/web/tizen/application/message_port_w.htm b/org.tizen.guides/html/web/tizen/application/message_port_w.htm index d3ca912..13fa416 100644 --- a/org.tizen.guides/html/web/tizen/application/message_port_w.htm +++ b/org.tizen.guides/html/web/tizen/application/message_port_w.htm @@ -32,7 +32,7 @@

Message Port

-

Tizen Web applications can communicate with other Web or native applications. The message data type for the communication is map data, which consists of a string key and value pair.

+

Tizen Web applications can communicate with other Web or native applications. The message data type for the communication is map data, which consists of a string key and value that can be string, string array, byte stream or byte stream array.

The Message Port API is mandatory for both Tizen mobile and wearable profiles, which means that it is supported in all mobile and wearable devices. All mandatory APIs are supported on the Tizen Emulators.

@@ -79,4 +79,4 @@ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga - \ No newline at end of file + diff --git a/org.tizen.tutorials/html/web/tizen/application/message_port_tutorial_w.htm b/org.tizen.tutorials/html/web/tizen/application/message_port_tutorial_w.htm index 2622c29..0a0225a 100644 --- a/org.tizen.tutorials/html/web/tizen/application/message_port_tutorial_w.htm +++ b/org.tizen.tutorials/html/web/tizen/application/message_port_tutorial_w.htm @@ -67,7 +67,34 @@ var localPortWatchId = localPort.addMessagePortListener(function(data, replyPort {    for (var i = 0; i < data.length; i++)    { -      console.log("key:" + data[i].key + " / value:" + data[i].value); +      var key = data[i].key; +      switch(key) +         case "command": +            console.log("key:" + key + " / value:" + data[i].value); +            break; +         case "data": +         case "byteData": +            console.log("key:" + key + " / value:["); +            for (var j = 0; j < data[i].value.length; j++) +            { +               console.log(data[i].value[j] + ", ") +            } +            console.log("]"); +            break; +         case "bytesData": +            console.log("key:" + key + " / value:["); +            for (var j = 0; j < data[i].value.length; j++) +            { +               console.log("["); +               for (var k = 0; k < data[i].value.length; k++) +               { +                  console.log(data[i].value[j] + ", ") +               } +               console.log("]"); +            } +            console.log("]"); +            break; +      }    }    if (replyPort)    { @@ -79,7 +106,21 @@ var localPortWatchId = localPort.addMessagePortListener(function(data, replyPort var messageData = [    {key:"command", value:"begin"}, -   {key:"data", value:"dummy"} +      } +   } +   if (replyPort) +   { +      console.log("replyPort given: " + replyPort.messagePortName); +   } +}); + +
  • Use the sendMessage() method of the RemoteMessagePort interface to send a message:

    +var messageData =
    +[
    +   {key:"command", value:"begin"},
    +   {key:"data", value:{"dummy1", "dummy2"}},
    +   {key:"byteData", value:[12, 23, 34, 45, 56, 67, 78]},
    +   {key:"bytesData", value:[[1, 2, 3, 255], [8, 9, 3, 4, 5]]}
     ];
     remotePort.sendMessage(messageData);