diff options
author | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2013-06-10 22:47:14 (GMT) |
---|---|---|
committer | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2013-06-10 22:47:14 (GMT) |
commit | 6f56474450b7c54f2c95b5dea6a7a42623141649 (patch) | |
tree | 420c52085d8cf778360c09baf9722b21d01259da /test/samples | |
parent | a154682fc1b25581742d38dd5fe9aa06ede167b7 (diff) | |
download | uscxml-6f56474450b7c54f2c95b5dea6a7a42623141649.zip uscxml-6f56474450b7c54f2c95b5dea6a7a42623141649.tar.gz uscxml-6f56474450b7c54f2c95b5dea6a7a42623141649.tar.bz2 |
W3C MMI Architecture framework
Diffstat (limited to 'test/samples')
-rw-r--r-- | test/samples/uscxml/templates/mc-html.html | 161 | ||||
-rw-r--r-- | test/samples/uscxml/test-mmi-events.scxml | 88 | ||||
-rw-r--r-- | test/samples/uscxml/test-mmi-im.scxml | 69 | ||||
-rw-r--r-- | test/samples/uscxml/test-mmi-mc.scxml | 83 |
4 files changed, 401 insertions, 0 deletions
diff --git a/test/samples/uscxml/templates/mc-html.html b/test/samples/uscxml/templates/mc-html.html new file mode 100644 index 0000000..78bb34e --- /dev/null +++ b/test/samples/uscxml/templates/mc-html.html @@ -0,0 +1,161 @@ +<html xmlns="http://www.w3.org/1999/xhtml"> + <head> + <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> + <script src="http://ajax.googleapis.com/ajax/libs/dojo/1.8.3/dojo/dojo.js"></script> + + <script type="text/javascript"> + function createUUID() { + // http://www.ietf.org/rfc/rfc4122.txt + var s = []; + var hexDigits = "0123456789abcdef"; + for (var i = 0; i < 36; i++) { + s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1); + } + s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010 + s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01 + s[8] = s[13] = s[18] = s[23] = "-"; + var uuid = s.join(""); + return uuid; + } + </script> + + <script type="text/javascript"> + require(["dojo/on", "dojo/mouse", "dojo/domReady!", "dojo", "dojox/json/ref"], function(on, mouse, dom, dojo, ref) { + + var element = dojo.byId("foo"); + + var mmiNS = "http://www.w3.org/2008/04/mmi-arch"; + var token = createUUID(); + var contextId; + var timeout="30000"; + var imURL = "${im.url}"; + + var xhr = dojo.require("dojo/_base/xhr"); + // initial new context request + xhr.post({ + url: imURL + "?token=" + token, + postData: + '<mmi:mmi xmlns:mmi="' + mmiNS + '" version="1.0">' + + '<mmi:NewContextRequest ' + + 'mmi:Source="HTML" ' + + 'mmi:Target="' + imURL + '" '+ + 'mmi:RequestID="' + token + '" />' + + '</mmi:mmi>', + handleAs:"xml", + headers:{ + "X-Requested-With": null, + "Content-Type": "application/xml", + }, + load: function(result) { + // scxml IM replied with 204 - longpoll via get + longpoll(); + } + }); + + var longpoll = function() { + xhr.get({ + // The URL to request + url: imURL + "?token=" + token, + handleAs:"xml", + headers:{ + "X-Requested-With": null, + "Content-Type": "application/xml", + }, + load: function(result) { + // IM had some event to send to us + element.innerHTML += (new XMLSerializer()).serializeToString(result).replace(/</gi, "<") + "<br />"; + var mmiEvent = result.documentElement.firstChild; + switch (mmiEvent.localName) { + case "NewContextResponse": + newContextResponse(mmiEvent); + break; + case "StartRequest": + startRequest(mmiEvent); + break; + } + longpoll(); + } + }); + } + + var eventToJSON = function(event) { + var seen = []; + return JSON.stringify(event, function(key, val) { + if (isNode(val)) { + return; + } + if (isWindow(val)) { + return; + } + if (typeof val == "object") { + if (seen.indexOf(val) >= 0) + return; + seen.push(val) + } + return val + }); + } + + var isNode = function(o){ + return ( + typeof Node === "object" ? o instanceof Node : + o && typeof o === "object" && typeof o.nodeType === "number" && typeof o.nodeName==="string" + ); + } + + var isWindow = function(o){ + return ( + typeof Window === "object" ? o instanceof Window : + o && typeof o === "object" && typeof o.menubar === "object" + ); + } + + var newContextResponse = function(event) { + contextId = event.getAttribute("Context"); + } + var startRequest = function(event) { + var content = event.firstChild; + console.log(content); + var fromStartRequest = document.importNode(content.firstChild,true); + element.appendChild(fromStartRequest); + } + + var sendExtensionNotification = function(event) { + console.log(event); + var data = eventToJSON(event); + console.log(data); + xhr.post({ + url: imURL + "?token=" + token, + postData: + '<mmi:mmi xmlns:mmi="' + mmiNS + '" version="1.0">' + + '<mmi:ExtensionNotification ' + + 'mmi:Source="HTML" ' + + 'mmi:Target="' + imURL + '" ' + + 'mmi:Context="' + contextId + '" ' + + 'mmi:RequestID="' + token + '">' + + '<mmi:Data>' + data + '</mmi:Data>' + + '</mmi:ExtensionNotification>' + + '</mmi:mmi>', + handleAs:"xml", + headers:{ + "X-Requested-With": null, + "Content-Type": "application/xml", + }, + load: function(result) { + // scxml IM replied with 204 + } + }); + + } + + on(element, "click", sendExtensionNotification); + on(element, mouse.enter, sendExtensionNotification); + on(element, mouse.leave, sendExtensionNotification); + + }); + </script> + </head> + <body class="tundra"> + <div id="foo"></div> + </body> +</html> diff --git a/test/samples/uscxml/test-mmi-events.scxml b/test/samples/uscxml/test-mmi-events.scxml new file mode 100644 index 0000000..9460a6e --- /dev/null +++ b/test/samples/uscxml/test-mmi-events.scxml @@ -0,0 +1,88 @@ +<scxml datamodel="ecmascript" + xmlns:mmi="http://www.w3.org/2008/04/mmi-arch" + xmlns="http://www.w3.org/2005/07/scxml"> + <!-- + This is a sample implementation for a modality component in the W3C MMI Architecture using SCXML + --> + <state id="idle"> + <onentry> + <log expr="'Entering idle state'" /> + <send targetexpr="_ioprocessors['mmihttp'].location"> + <mmi:PrepareRequest + <mmi:content> + <scxml datamodel="ecmascript"> + <state> + <onentry> + <log expr="" /> + </onentry> + </state> + </scxml> + </mmi:content> + </mmi:PrepareRequest> + </send> + </onentry> + + <transition event="mmi.prepare.request" target="idle"> + <log expr="'Received PrepareRequest'" /> + <mmi:mmi xmlns:mmi="http://www.w3.org/2008/04/mmi-arch" version="1.0"> + <mmi:PrepareResponse + mmi:SourceExpr="_ioprocessors['basichttp'].location" + mmi:TargetExpr="someOtherURI" + mmi:ContextExpr="someURI" + mmi:RequestIDExpr="_event.data.getElementsByTagName('PrepareRequest')[0].getAttribute('RequestID')" + mmi:Status="success"/> + </mmi:mmi> + </transition> + <transition event="mmi.start.request" target="running"> + <log expr="'Received StartRequest'" /> + </transition> + <transition event="mmi.clearcontext.request" target="terminate"> + <log expr="'Received ClearContextRequest'" /> + </transition> + </state> + + <state id="paused"> + <onentry> + <log expr="'Entering pause state'"> + </onentry> + <transition event="mmi.prepare.request" target="paused"> + <log expr="'Received PrepareRequest'" /> + </transition> + <transition event="mmi.start.request" target="running"> + <log expr="'Received StartRequest'" /> + </transition> + <transition event="mmi.resume.request" target="running"> + <log expr="'Received ResumeRequest'" /> + </transition> + <transition event="mmi.cancel.request" target="idle"> + <log expr="'Received CancelRequest'" /> + </transition> + <transition event="mmi.clearcontext.request" target="terminate"> + <log expr="'Received ClearContextRequest'" /> + </transition> + </state> + + <state id="running"> + <onentry> + <log expr="'Entering running state'"> + </onentry> + <transition event="mmi.prepare.request" target="running"> + <log expr="'Received PrepareRequest'" /> + </transition> + <transition event="mmi.pause.request" target="paused"> + <log expr="'Received PauseRequest'" /> + </transition> + <transition event="mmi.cancel.request" target="idle"> + <log expr="'Received CancelRequest'" /> + </transition> + <transition event="mmi.clearcontext.request" target="terminate"> + <log expr="'Received ClearContextRequest'" /> + </transition> + </state> + + <final id="terminate"> + <onentry> + <log expr="'Entering terminate state'"> + </onentry> + </final> +</scxml>
\ No newline at end of file diff --git a/test/samples/uscxml/test-mmi-im.scxml b/test/samples/uscxml/test-mmi-im.scxml new file mode 100644 index 0000000..4b130bd --- /dev/null +++ b/test/samples/uscxml/test-mmi-im.scxml @@ -0,0 +1,69 @@ +<scxml datamodel="ecmascript" name="mmi-test" + xmlns:mmi="http://www.w3.org/2008/04/mmi-arch" + xmlns:html="http://www.w3.org/1999/xhtml" + xmlns="http://www.w3.org/2005/07/scxml"> + + <script> +<![CDATA[ + + function dump(object, level) { + if (!level) level = 0; + + var padding = ""; + for (var j=0;j < level+1;j++) padding += " "; + + if (typeof(object) == 'object') { + for (var item in object) { + if (item === "lastChild") continue; + if (item === "firstChild") continue; + if (item === "ownerDocument") continue; + var value = object[item]; + + if(typeof(value) == 'object') { + print (padding + "'" + item + "' ...\n"); + dump (value, level+1); + } else { + print (padding + "'" + item + "' => \"" + value + "\"\n"); + } + } + } else { + print("===> " + object + " <===(" + typeof(object) + ")"); + } + } +]]> + </script> + + <state id="startmc"> + <!-- invoke type="vxml" id="mc.vxml" / --> + + <!-- Idle here and wait for events --> + <state id="idle"> + + <!-- setup session --> + <transition event="mmi.newcontextrequest" target="idle"> + + <send type="mmi.event"> + <content> + <mmi:NewContextResponse mmi:Status="success" /> + </content> + </send> + + <send type="mmi.event"> + <content> + <mmi:StartRequest> + <mmi:Content> + <html:button>Click Me</html:button> + </mmi:Content> + </mmi:StartRequest> + </content> + </send> + </transition> + + <transition event="mmi.extensionnotification" target="idle"> + <script>dump(_event)</script> + </transition> + + </state> + </state> + <final id="terminate" /> +</scxml>
\ No newline at end of file diff --git a/test/samples/uscxml/test-mmi-mc.scxml b/test/samples/uscxml/test-mmi-mc.scxml new file mode 100644 index 0000000..e2197ff --- /dev/null +++ b/test/samples/uscxml/test-mmi-mc.scxml @@ -0,0 +1,83 @@ +<scxml datamodel="ecmascript" name="sample-mc"> + <!-- + This is a sample implementation for a modality component in the W3C MMI Architecture using SCXML. + We enter an idle state and wait for StartRequests from an IM. + --> + <state id="idle"> + <onentry> + <log expr="'Entering idle state'" /> + </onentry> + <transition event="mmi.prepare.request" target="idle"> + <log expr="'Received PrepareRequest'" /> + <send type="mmihttp"> + <mmi:PrepareResponse + mmi:SourceExpr="_ioprocessors['mmihttp'].location" + mmi:TargetExpr="_event.data.getElementsByTagName('PrepareRequest')[0].getAttribute('Source')" + mmi:ContextExpr="_event.data.getElementsByTagName('PrepareRequest')[0].getAttribute('Context')" + mmi:RequestIDExpr="_event.data.getElementsByTagName('PrepareRequest')[0].getAttribute('RequestID')" + mmi:Status="success"/> + </transition> + + <transition event="mmi.start.request" target="running"> + <log expr="'Received StartRequest'" /> + </transition> + + <transition event="mmi.clearcontext.request" target="terminate"> + <log expr="'Received ClearContextRequest'" /> + </transition> + </state> + + <state id="paused"> + <onentry> + <log expr="'Entering pause state'"> + </onentry> + + <transition event="mmi.prepare.request" target="paused"> + <log expr="'Received PrepareRequest'" /> + </transition> + + <transition event="mmi.start.request" target="running"> + <log expr="'Received StartRequest'" /> + </transition> + + <transition event="mmi.resume.request" target="running"> + <log expr="'Received ResumeRequest'" /> + </transition> + + <transition event="mmi.cancel.request" target="idle"> + <log expr="'Received CancelRequest'" /> + </transition> + + <transition event="mmi.clearcontext.request" target="terminate"> + <log expr="'Received ClearContextRequest'" /> + </transition> + </state> + + <state id="running"> + <onentry> + <log expr="'Entering running state'"> + </onentry> + + <transition event="mmi.prepare.request" target="running"> + <log expr="'Received PrepareRequest'" /> + </transition> + + <transition event="mmi.pause.request" target="paused"> + <log expr="'Received PauseRequest'" /> + </transition> + + <transition event="mmi.cancel.request" target="idle"> + <log expr="'Received CancelRequest'" /> + </transition> + + <transition event="mmi.clearcontext.request" target="terminate"> + <log expr="'Received ClearContextRequest'" /> + </transition> + </state> + + <final id="terminate"> + <onentry> + <log expr="'Entering terminate state'"> + </onentry> + </final> +</scxml>
\ No newline at end of file |