webscoket implemented

This commit is contained in:
2014-08-13 11:44:29 +04:00
parent a7e8d5c2d9
commit 0e8ddca38c
17 changed files with 615 additions and 23 deletions

View File

@@ -1,5 +1,9 @@
package ru.m.armageddon.client;
import flash.text.TextFieldType;
import flash.Lib;
import flash.text.TextField;
import haxework.log.JSLogger;
import ru.m.armageddon.client.data.GameData;
import haxework.frame.IFrameSwitcher;
import haxework.provider.Provider;
@@ -10,6 +14,7 @@ import haxework.gui.GuiBuilder;
import haxe.Json;
import openfl.Assets;
import ru.m.armageddon.core.connect.flash.FlashConnection;
import ru.m.armageddon.core.connect.js.JsConnection;
import ru.m.armageddon.core.connect.IConnection;
import haxework.log.TraceLogger;
@@ -19,6 +24,7 @@ class Client implements IConnectionHandler {
public static function main() {
L.push(new TraceLogger());
L.push(new JSLogger());
L.d(TAG, Meta.getVersion());
new Client();
}
@@ -34,9 +40,20 @@ class Client implements IConnectionHandler {
Provider.setFactory(GameData, GameData);
Provider.set(IFrameSwitcher, switcher);
Provider.set(IConnection, new FlashConnection("localhost", 5000, this));
//#if flash
//Provider.set(IConnection, new FlashConnection("localhost", 5001, this));
//#elseif html5
Provider.set(IConnection, new JsConnection("localhost", 5001, this));
//#end
switcher.change(AuthFrame.ID);
/*var tf = new TextField();
tf.type = TextFieldType.INPUT;
tf.text = "Azaza";
tf.border = true;
tf.borderColor = 0xff0000;
Lib.current.addChild(tf);*/
}
public function onConnected():Void {}

View File

@@ -47,6 +47,9 @@ class AuthFrame extends VGroupView implements IPacketHandler {
loginInput.text = so.data.login;
passwordInput.text = so.data.password;
onPress(null);
} else {
loginInput.text = "shmyga";
passwordInput.text = "xkbp8jh9z2";
}
}
@@ -56,6 +59,7 @@ class AuthFrame extends VGroupView implements IPacketHandler {
var connection:IConnection = Provider.get(IConnection);
connection.connect()
.success(function(_) {
L.d(TAG, "Connected");
connection.send(new LoginRequest().setLogin(login).setPassword(password));
})
.fail(function(error) {

View File

@@ -0,0 +1,26 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta charset="utf-8">
<script type="text/javascript" src="swf.js"></script>
<style type="text/css">
html, body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div id="swf" style="width: 100%; height: 100%;"></div>
<script type="text/javascript">
var swf = new Swf("swf", "flash/bin/armageddon.swf");
</script>
</body>
</html>

148
src/client/webapp/swf.js Normal file
View File

@@ -0,0 +1,148 @@
(function(window) {
if (!window.Swf) {
window.Swf = function(eid, src, listener, params) {
this.id = "adman" + window.Swf.i++;
this.listener = listener;
this.embed(eid, src, params);
window.SWF_CALLBACKS = window.SWF_CALLBACKS || {};
window.SWF_CALLBACKS[this.id] = this.onSwfEvent();
};
window.Swf.i = 0;
window.Swf.prototype = {
dispatch: function(type) {
if (this.listener && this.listener["on_" + type]) {
var args = [].slice.call(arguments, 1);
this.listener["on_" + type].apply(this.listener, args);
}
},
onSwfEvent: function() {
var self = this;
return function(type, arg1, arg2) {
self.dispatch(type, arg1, arg2);
};
},
insertAfter :function(elem, refElem) {
var parent = refElem.parentNode;
var next = refElem.nextSibling;
if (next) {
return parent.insertBefore(elem, next);
} else {
return parent.appendChild(elem);
}
},
embed:function(target, src, params) {
params = params || {};
params["callback"] = "SWF_CALLBACKS." + this.id;
var flashData = {
params: {
id: this.id,
quality: "high",
allowScriptAccess: "always",
allowFullScreen: true,
wMode: "opaque",
base: null,
swLiveConnect: true
},
properties: {
name: this.id,
width: "100%",
height: "100%"
},
vars: params
};
this.swf = this.buildFlashElement(src, flashData);
this.swf.style["position"] = "absolute";
this.swf.style["left"] = 0;
this.swf.style["top"] = 0;
//this.swf.style["visibility"] = "hidden";
if (target) {
target = document.getElementById(target);
this.insertAfter(this.swf, target);
} else {
document.body.appendChild(this.swf);
}
},
typeOf: function (item) {
if (item == null) return "null";
if (item.nodeName) {
if (item.nodeType == 1) return "element";
if (item.nodeType == 3) return (/\S/).test(item.nodeValue) ? "textnode" : "whitespace";
} else if (typeof item.length == "number") {
if (item.callee) return "arguments";
}
return typeof item;
},
toFlashVars: function (object, base) {
var queryString = [];
for (var key in object) {
var value = object[key];
if (base) key = base + ":" + key;
var result;
switch (this.typeOf(value)) {
case "object":
result = this.toFlashVars(value, key);
break;
case "array":
var qs = {};
value.each(function (val, i) {
qs[i] = val;
});
result = this.toFlashVars(qs, key);
break;
default:
result = key + "=" + encodeURIComponent(value);
}
if (value != null) queryString.push(result);
}
return queryString.join("&");
},
buildFlashElement: function (path, options) {
var params = options.params;
var vars = options.vars;
var properties = options.properties;
params.flashVars = this.toFlashVars(vars);
var isIE = /*@cc_on!@*/false;
if (isIE) {
properties.classid = "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000";
params.movie = path;
} else {
properties.type = "application/x-shockwave-flash";
}
properties.data = path;
var build = "<object id=\"" + params.id + "\"";
for (var property in properties) build += " " + property + "=\"" + properties[property] + "\"";
build += ">";
for (var param in params) {
if (params[param]) build += "<param name=\"" + param + "\" value=\"" + params[param] + "\" />";
}
build += "</object>";
var div = document.createElement("div");
div.innerHTML = build;
return div.firstChild;
},
dispose: function() {
if (this.swf) {
this.swf.dispose();
this.swf.parentNode.removeChild(this.swf);
}
}
};
}
})(window);