templates/as3/org/rubyforge/dango/DangoClientFramework.as in dango_generator-0.2.6 vs templates/as3/org/rubyforge/dango/DangoClientFramework.as in dango_generator-0.3.0
- old
+ new
@@ -25,10 +25,12 @@
public class DangoClientFramework implements IEventDispatcher {
private var socket:Socket; //ソケット
private var dispatcher:EventDispatcher; // Event送出用
+ private var default_encode_type:uint = 0; // 送信データのエンコードタイプはJSON
+
private var is_debug:Boolean; // Debugモードかどうかのフラグ
private var is_connect:Boolean = false; // 接続完了しているかどうか
private var frame_rate:uint = 24; // デフォルトのフレームレート(想定値)
@@ -83,16 +85,21 @@
var policy_file_protocol:String = config.policy_file_protocol;
// var policy_file_port:uint = config.policy_file_port;
var policy_file_path:String = config.policy_file_path;
+ if(is_debug){ trace("flash player: " + Capabilities.version); }
+ if(is_debug){ trace("isDebugger: " + Capabilities.isDebugger); }
+ if(is_debug){ trace("language: " + Capabilities.language); }
+ if(is_debug){ trace("os: " + Capabilities.os); }
+ if(is_debug){ trace("frame_rate: " + frame_rate); }
// Event送出用
dispatcher = new EventDispatcher(this);
// Security.sandboxType
- trace("Security.sandboxType:" + Security.sandboxType);
+ if(is_debug){ trace("Security.sandboxType:" + Security.sandboxType); }
// policy_file
// if(!policy_file_protocol){ policy_file_protocol = "http" };
if(!policy_file_path) { policy_file_path = "/crossdomain.xml" };
@@ -116,21 +123,21 @@
if(policy_file_protocol){
var url_load_policy_file:String;
// url_load_policy_file = "xmlsocket://" + server_host + ":" + server_port;
// url_load_policy_file = "http://aiarebaba.hi-fi-net.com/crossdomain.xml";
url_load_policy_file = "http://" + server_host + policy_file_path;
- trace("url_load_policy_file=" + url_load_policy_file);
+ if(is_debug){ trace("url_load_policy_file=" + url_load_policy_file); }
Security.loadPolicyFile(url_load_policy_file);
}
// 接続
try{
- trace("connectiong... host=" + server_host + " port=" + server_port);
+ if(is_debug){ trace("connectiong... host=" + server_host + " port=" + server_port); }
socket.connect(server_host, server_port);
- trace("connected host=" + server_host + " port=" + server_port);
+ if(is_debug){ trace("connected host=" + server_host + " port=" + server_port); }
} catch(err:Error){
- trace("connect error err=" + err + " name=" + err.name + " message=" + err.message);
+ if(is_debug){ trace("connect error err=" + err + " name=" + err.name + " message=" + err.message); }
return(void);
}
// polling用タイマーの設定
var polling_timer:Timer = new Timer(polling_timer_msec, 0); // タイマーの追加
@@ -281,11 +288,11 @@
public function recv_do_callback(evt:TimerEvent):void {
// if(is_debug){ trace("DangoClientFramework:recv_do_callback:" + DangoUtil.now2str()); }
// 前回から時間がかかりすぎている(処理落ちしかけている場合は)スキップ
var start_date:Date = new Date();
- if(recv_do_last_date.time > start_date.time - (Number(recv_do_timer_msec) * 1.3)){
+ if(recv_do_last_date.time > start_date.time - (Number(recv_do_timer_msec) * 1.4)){
if(recv_wait_do_cache.length > 0){
var recv_arr:Array = recv_wait_do_cache.shift();
var notice_name:String = recv_arr[0];
var recv_data:Object = recv_arr[1];
server_time = recv_arr[2];
@@ -297,10 +304,11 @@
} else { // 通常のデータならイベント発生
if(is_debug){ trace("DangoClientFramework:dispatchEvent:dango_" + notice_name + " server_time=" + server_time); }
this.dispatchEvent(new DangoReceiveEvent("dango__before_filter", recv_data, count_no));
this.dispatchEvent(new DangoReceiveEvent("dango_" + notice_name, recv_data, count_no));
+ this.dispatchEvent(new DangoReceiveEvent("dango__after_filter", recv_data, count_no));
}
}
}
recv_do_last_date = new Date(); // 前回の実行の終了時間の保持
@@ -401,11 +409,11 @@
* @return void
*/
public function send_data_to_server( send_obj:Array ):void {
// if(is_debug){ trace("DangoClientFramework:send_data_to_server:send_obj=" + ObjectUtil.toString(send_obj)); }
- var type:int = 0;
+ var encode_type:uint = default_encode_type;
// データが空ならJSONencodeしない
var send_obj_str:String;
if(send_obj == null){
send_obj_str = "\n";
@@ -413,15 +421,15 @@
send_obj_str = JSON.encode(send_obj) + "\n";
}
var send_obj_size:int = DangoUtil.string_byte_length(send_obj_str);
-// if(is_debug){ trace("DangoClientFramework:send:" + type + ":" + send_obj_size + ":" + send_obj_str); }
+// if(is_debug){ trace("DangoClientFramework:send:" + encode_type + ":" + send_obj_size + ":" + send_obj_str); }
// 長さ送信
var byte_array:ByteArray = new ByteArray;
- byte_array.writeByte(type);
+ byte_array.writeByte(encode_type);
byte_array.writeUnsignedInt(send_obj_size);
socket.writeBytes(byte_array, 0, 5);
socket.writeUTFBytes("\n");
socket.flush();
@@ -467,10 +475,10 @@
} catch(err:Error){
this.dispatchEvent(new DangoErrorEvent("DangoError", DangoErrorCode.IOError, "failed to byte_array.readBytes."));
return([]);
}
- var type:int = byte_array_size.readByte();
+ var encode_type:int = byte_array_size.readByte();
recv_not_yet_size = byte_array_size.readUnsignedInt();
var crlf:String = byte_array.readUTFBytes(1);
byte_read_size -= 6;
// if(is_debug){ trace("DangoClientFramework:recv_not_yet_size=" + recv_not_yet_size); }
}