Create FABridge tester. Move wstest into tests subdir.
This commit is contained in:
parent
8acfc8cf52
commit
af180155a8
|
@ -0,0 +1,37 @@
|
||||||
|
package {
|
||||||
|
|
||||||
|
import flash.events.*;
|
||||||
|
import flash.external.*;
|
||||||
|
import flash.utils.*;
|
||||||
|
|
||||||
|
[Event(name="message", type="FABTestMessageEvent")]
|
||||||
|
public class FABTest extends EventDispatcher {
|
||||||
|
|
||||||
|
private var main:FABTestMain;
|
||||||
|
private var intervalID:int;
|
||||||
|
private var seqCnt:int;
|
||||||
|
|
||||||
|
public function FABTest(main:FABTestMain) {
|
||||||
|
this.main = main;
|
||||||
|
ExternalInterface.call("console.log", "[FABTest] FABTest()");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function start(eventDelay:int):void {
|
||||||
|
ExternalInterface.call("console.log", "[FABTest] start()");
|
||||||
|
seqCnt = 0;
|
||||||
|
intervalID = setInterval(sendEvent, eventDelay);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function stop():void {
|
||||||
|
ExternalInterface.call("console.log", "[FABTest] stop()");
|
||||||
|
clearInterval(intervalID);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function sendEvent():void {
|
||||||
|
//ExternalInterface.call("console.log", "[FABTest] sendEvent " + seqCnt);
|
||||||
|
dispatchEvent(new FABTestMessageEvent("message", encodeURIComponent(seqCnt.toString())));
|
||||||
|
seqCnt = seqCnt + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
package {
|
||||||
|
|
||||||
|
import flash.display.*;
|
||||||
|
import flash.events.*;
|
||||||
|
import bridge.FABridge;
|
||||||
|
|
||||||
|
public class FABTestMain extends Sprite {
|
||||||
|
|
||||||
|
public function FABTestMain() {
|
||||||
|
|
||||||
|
// This is to avoid "You are trying to call recursively into the Flash Player ..."
|
||||||
|
// error which (I heard) happens when you pass bunch of messages.
|
||||||
|
// This workaround was written here:
|
||||||
|
// http://www.themorphicgroup.com/blog/2009/02/14/fabridge-error-you-are-trying-to-call-recursively-into-the-flash-player-which-is-not-allowed/
|
||||||
|
FABridge.EventsToCallLater["flash.events::Event"] = "true";
|
||||||
|
FABridge.EventsToCallLater["FABTestMessageEvent"] = "true";
|
||||||
|
|
||||||
|
var fab:FABridge = new FABridge();
|
||||||
|
fab.rootObject = this;
|
||||||
|
//log("Flash initialized");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create():FABTest {
|
||||||
|
return new FABTest(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Binary file not shown.
|
@ -0,0 +1,14 @@
|
||||||
|
package {
|
||||||
|
|
||||||
|
import flash.events.*;
|
||||||
|
|
||||||
|
public class FABTestMessageEvent extends Event {
|
||||||
|
public var data:String;
|
||||||
|
|
||||||
|
public function FABTestMessageEvent(type:String, data:String) {
|
||||||
|
super(type);
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
../../web-socket-js/flash-src/bridge/FABridge.as
|
|
@ -0,0 +1,136 @@
|
||||||
|
// Copyright: Hiroshi Ichikawa <http://gimite.net/en/>
|
||||||
|
// Lincense: New BSD Lincense
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
|
||||||
|
var console = window.console;
|
||||||
|
if (!console) console = {log: function(){ }, error: function(){ }};
|
||||||
|
|
||||||
|
function hasFlash() {
|
||||||
|
if ('navigator' in window && 'plugins' in navigator && navigator.plugins['Shockwave Flash']) {
|
||||||
|
return !!navigator.plugins['Shockwave Flash'].description;
|
||||||
|
}
|
||||||
|
if ('ActiveXObject' in window) {
|
||||||
|
try {
|
||||||
|
return !!new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version');
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!hasFlash()) {
|
||||||
|
console.error("Flash Player is not installed.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
FABTest = function() {
|
||||||
|
var self = this;
|
||||||
|
FABTest.__addTask(function() {
|
||||||
|
self.__flash =
|
||||||
|
FABTest.__flash.create();
|
||||||
|
|
||||||
|
self.__flash.addEventListener("message", function(fe) {
|
||||||
|
var data = decodeURIComponent(fe.getData());
|
||||||
|
try {
|
||||||
|
if (self.onmessage) {
|
||||||
|
var e;
|
||||||
|
if (window.MessageEvent) {
|
||||||
|
e = document.createEvent("MessageEvent");
|
||||||
|
e.initMessageEvent("message", false, false, data, null, null, window);
|
||||||
|
} else { // IE
|
||||||
|
e = {data: data};
|
||||||
|
}
|
||||||
|
self.onmessage(e);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e.toString());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//console.log("[FABTest] Flash object is ready");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
FABTest.prototype.start = function(eventDelay) {
|
||||||
|
if (!this.__flash) {
|
||||||
|
throw "INVALID_STATE_ERR: FABTest connection has not been established";
|
||||||
|
}
|
||||||
|
var result = this.__flash.start(eventDelay);
|
||||||
|
if (result < 0) { // success
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
FABTest.prototype.stop = function() {
|
||||||
|
if (!this.__flash) return;
|
||||||
|
this.__flash.stop();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
FABTest.__tasks = [];
|
||||||
|
|
||||||
|
FABTest.__initialize = function() {
|
||||||
|
if (!FABTest.__swfLocation) {
|
||||||
|
console.error("[FABTest] set FABTest.__swfLocation to location of FABTestMain.swf");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var container = document.createElement("div");
|
||||||
|
container.id = "fabTestContainer";
|
||||||
|
// Puts the Flash out of the window. Note that we cannot use display: none or visibility: hidden
|
||||||
|
// here because it prevents Flash from loading at least in IE.
|
||||||
|
container.style.position = "absolute";
|
||||||
|
container.style.left = "-100px";
|
||||||
|
container.style.top = "-100px";
|
||||||
|
var holder = document.createElement("div");
|
||||||
|
holder.id = "fabTestFlash";
|
||||||
|
container.appendChild(holder);
|
||||||
|
document.body.appendChild(container);
|
||||||
|
swfobject.embedSWF(
|
||||||
|
FABTest.__swfLocation, "fabTestFlash", "8", "8", "9.0.0",
|
||||||
|
null, {bridgeName: "fabTest"}, null, null,
|
||||||
|
function(e) {
|
||||||
|
if (!e.success) console.error("[FABTest] swfobject.embedSWF failed");
|
||||||
|
}
|
||||||
|
);
|
||||||
|
FABridge.addInitializationCallback("fabTest", function() {
|
||||||
|
try {
|
||||||
|
console.log("[FABTest] FABridge initializad");
|
||||||
|
FABTest.__flash = FABridge.fabTest.root();
|
||||||
|
for (var i = 0; i < FABTest.__tasks.length; ++i) {
|
||||||
|
FABTest.__tasks[i]();
|
||||||
|
}
|
||||||
|
FABTest.__tasks = [];
|
||||||
|
} catch (e) {
|
||||||
|
console.error("[FABTest] " + e.toString());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
FABTest.__addTask = function(task) {
|
||||||
|
if (FABTest.__flash) {
|
||||||
|
task();
|
||||||
|
} else {
|
||||||
|
FABTest.__tasks.push(task);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// called from Flash
|
||||||
|
function fabTestLog(message) {
|
||||||
|
console.log(decodeURIComponent(message));
|
||||||
|
}
|
||||||
|
|
||||||
|
// called from Flash
|
||||||
|
function fabTestError(message) {
|
||||||
|
console.error(decodeURIComponent(message));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (window.addEventListener) {
|
||||||
|
window.addEventListener("load", FABTest.__initialize, false);
|
||||||
|
} else {
|
||||||
|
window.attachEvent("onload", FABTest.__initialize);
|
||||||
|
}
|
||||||
|
|
||||||
|
})();
|
|
@ -0,0 +1,114 @@
|
||||||
|
<html>
|
||||||
|
|
||||||
|
<head><title>FABridge Event Test</title></head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
|
||||||
|
Event Delay (ms): <input id='eventDelay' style='width:50' value="100">
|
||||||
|
<input id='startButton' type='button' value='Start' style='width:100px'
|
||||||
|
onclick="start();">
|
||||||
|
|
||||||
|
<br><br>
|
||||||
|
<table border=1>
|
||||||
|
<tr>
|
||||||
|
<th align="right">Good Events Received:</th>
|
||||||
|
<td align="right"><div id='received'>0</div></td>
|
||||||
|
</tr><tr>
|
||||||
|
<th align="right">Errors (Bad Events Received:)</th>
|
||||||
|
<td align="right"><div id='errors'>0</div></td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<br>
|
||||||
|
Errors:<br>
|
||||||
|
<textarea id="error" style="font-size: 9;" cols=80 rows=25></textarea>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- Uncomment to activate firebug lite -->
|
||||||
|
<!--
|
||||||
|
<script type='text/javascript'
|
||||||
|
src='http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js'></script>
|
||||||
|
-->
|
||||||
|
|
||||||
|
<script src="../include/mootools.js"></script>
|
||||||
|
<script src="../include/util.js"></script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
|
||||||
|
function error(str) {
|
||||||
|
console.error(str);
|
||||||
|
cell = $('error');
|
||||||
|
cell.innerHTML += errors + ": " + str + "\n";
|
||||||
|
cell.scrollTop = cell.scrollHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
var eventDelay = 0;
|
||||||
|
var fab = null;
|
||||||
|
var recv_seq = 0, received = 0, errors = 0;
|
||||||
|
|
||||||
|
function check_event(data) {
|
||||||
|
//console.log(">> check_event");
|
||||||
|
var got_seq = parseInt(data, 10);
|
||||||
|
if (got_seq !== recv_seq) {
|
||||||
|
error("got event " + got_seq + ", expecting " + recv_seq);
|
||||||
|
errors = errors + 1;
|
||||||
|
} else {
|
||||||
|
received = received + 1;
|
||||||
|
}
|
||||||
|
recv_seq = got_seq + 1;
|
||||||
|
//console.log("<< check_event");
|
||||||
|
}
|
||||||
|
|
||||||
|
function update_stats() {
|
||||||
|
$('received').innerHTML = received;
|
||||||
|
$('errors').innerHTML = errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
function start() {
|
||||||
|
console.log(">> start");
|
||||||
|
eventDelay = parseInt($('eventDelay').value, 10);
|
||||||
|
recv_seq = 0;
|
||||||
|
|
||||||
|
fab.onmessage = function(e) {
|
||||||
|
//console.log(">> FABTest.onmessage");
|
||||||
|
check_event(e.data);
|
||||||
|
//console.log("<< FABTest.onmessage");
|
||||||
|
};
|
||||||
|
fab.start(eventDelay);
|
||||||
|
update_ref = update_stats.periodical(1);
|
||||||
|
|
||||||
|
$('startButton').value = "Stop";
|
||||||
|
$('startButton').onclick = stop;
|
||||||
|
console.log("<< start");
|
||||||
|
}
|
||||||
|
|
||||||
|
function stop() {
|
||||||
|
console.log(">> stop");
|
||||||
|
fab.stop();
|
||||||
|
$clear(update_ref);
|
||||||
|
update_stats(); // Final numbers
|
||||||
|
recv_seq = 0;
|
||||||
|
|
||||||
|
$('startButton').value = "Start";
|
||||||
|
$('startButton').onclick = start;
|
||||||
|
console.log("<< stop");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* If no builtin websockets then load web_socket.js */
|
||||||
|
console.log("Loading FABridge event test object");
|
||||||
|
var extra = "<script src='../include/web-socket-js/swfobject.js'><\/script>";
|
||||||
|
extra += "<script src='../include/web-socket-js/FABridge.js'><\/script>";
|
||||||
|
extra += "<script src='../include/fab-test/fab-test.js'><\/script>";
|
||||||
|
document.write(extra);
|
||||||
|
|
||||||
|
window.onload = function() {
|
||||||
|
console.log("onload");
|
||||||
|
FABTest.__swfLocation = "../include/fab-test/FABTestMain.swf";
|
||||||
|
console.log("creating FABridge event test object");
|
||||||
|
fab = new FABTest(eventDelay);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</html>
|
|
@ -37,9 +37,9 @@
|
||||||
src='http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js'></script>
|
src='http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js'></script>
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<script src="include/mootools.js"></script>
|
<script src="../include/mootools.js"></script>
|
||||||
<script src="include/base64.js"></script>
|
<script src="../include/base64.js"></script>
|
||||||
<script src="include/util.js"></script>
|
<script src="../include/util.js"></script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
|
@ -6,10 +6,12 @@ that has a random payload (length and content) that is checksummed and
|
||||||
given a sequence number. Any errors are reported and counted.
|
given a sequence number. Any errors are reported and counted.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import sys, socket, ssl, time, traceback
|
import sys, os, socket, ssl, time, traceback
|
||||||
import random, time
|
import random, time
|
||||||
from base64 import b64encode, b64decode
|
from base64 import b64encode, b64decode
|
||||||
from select import select
|
from select import select
|
||||||
|
|
||||||
|
sys.path.insert(0,os.path.dirname(__file__) + "/../")
|
||||||
from websocket import *
|
from websocket import *
|
||||||
|
|
||||||
buffer_size = 65536
|
buffer_size = 65536
|
Loading…
Reference in New Issue