dango_generator 0.0.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +16 -0
- data/README.txt +41 -0
- data/dango_generator.rb +99 -0
- data/templates/as3/as3corelib-license.txt +33 -0
- data/templates/as3/as3corelib-readme.txt +5 -0
- data/templates/as3/com/adobe/crypto/MD5.as +256 -0
- data/templates/as3/com/adobe/crypto/SHA1.as +268 -0
- data/templates/as3/com/adobe/crypto/SHA224.as +255 -0
- data/templates/as3/com/adobe/crypto/SHA256.as +260 -0
- data/templates/as3/com/adobe/crypto/WSSEUsernameToken.as +117 -0
- data/templates/as3/com/adobe/errors/IllegalStateError.as +66 -0
- data/templates/as3/com/adobe/images/BitString.as +42 -0
- data/templates/as3/com/adobe/images/JPGEncoder.as +651 -0
- data/templates/as3/com/adobe/images/PNGEncoder.as +144 -0
- data/templates/as3/com/adobe/net/DynamicURLLoader.as +58 -0
- data/templates/as3/com/adobe/net/IURIResolver.as +79 -0
- data/templates/as3/com/adobe/net/URI.as +2469 -0
- data/templates/as3/com/adobe/net/URIEncodingBitmap.as +142 -0
- data/templates/as3/com/adobe/net/proxies/RFC2817Socket.as +204 -0
- data/templates/as3/com/adobe/serialization/json/JSON.as +88 -0
- data/templates/as3/com/adobe/serialization/json/JSONDecoder.as +218 -0
- data/templates/as3/com/adobe/serialization/json/JSONEncoder.as +302 -0
- data/templates/as3/com/adobe/serialization/json/JSONParseError.as +90 -0
- data/templates/as3/com/adobe/serialization/json/JSONToken.as +107 -0
- data/templates/as3/com/adobe/serialization/json/JSONTokenType.as +70 -0
- data/templates/as3/com/adobe/serialization/json/JSONTokenizer.as +550 -0
- data/templates/as3/com/adobe/utils/ArrayUtil.as +190 -0
- data/templates/as3/com/adobe/utils/DateUtil.as +666 -0
- data/templates/as3/com/adobe/utils/DictionaryUtil.as +90 -0
- data/templates/as3/com/adobe/utils/IntUtil.as +69 -0
- data/templates/as3/com/adobe/utils/NumberFormatter.as +77 -0
- data/templates/as3/com/adobe/utils/StringUtil.as +257 -0
- data/templates/as3/com/adobe/utils/XMLUtil.as +171 -0
- data/templates/as3/com/adobe/webapis/ServiceBase.as +51 -0
- data/templates/as3/com/adobe/webapis/URLLoaderBase.as +111 -0
- data/templates/as3/com/adobe/webapis/events/ServiceEvent.as +78 -0
- data/templates/as3/org/rubyforge/dango/DangoClientFramework.as +426 -0
- data/templates/as3/org/rubyforge/dango/DangoError.as +11 -0
- data/templates/as3/org/rubyforge/dango/DangoErrorCode.as +7 -0
- data/templates/as3/org/rubyforge/dango/DangoErrorEvent.as +23 -0
- data/templates/as3/org/rubyforge/dango/DangoReceiveEvent.as +21 -0
- data/templates/as3/org/rubyforge/dango/DangoURLLoader.as +127 -0
- data/templates/as3/org/rubyforge/dango/DangoURLLoaderEvent.as +29 -0
- data/templates/as3/org/rubyforge/dango/DangoUtil.as +84 -0
- data/templates/dango/config/development.yml +28 -0
- data/templates/dango/config/production.yml +3 -0
- data/templates/dango/config/system_message.yml +5 -0
- data/templates/dango/config/test.yml +3 -0
- data/templates/dango/server/99_dango_server.rb +22 -0
- data/templates/lib/dango_monitor_client.rb +1 -0
- data/templates/lib/dango_tester_client.rb +1 -0
- data/templates/script/dango_server +36 -0
- data/templates/tasks/dango.rake +2 -0
- metadata +108 -0
@@ -0,0 +1,51 @@
|
|
1
|
+
/*
|
2
|
+
Adobe Systems Incorporated(r) Source Code License Agreement
|
3
|
+
Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved.
|
4
|
+
|
5
|
+
Please read this Source Code License Agreement carefully before using
|
6
|
+
the source code.
|
7
|
+
|
8
|
+
Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive,
|
9
|
+
no-charge, royalty-free, irrevocable copyright license, to reproduce,
|
10
|
+
prepare derivative works of, publicly display, publicly perform, and
|
11
|
+
distribute this source code and such derivative works in source or
|
12
|
+
object code form without any attribution requirements.
|
13
|
+
|
14
|
+
The name "Adobe Systems Incorporated" must not be used to endorse or promote products
|
15
|
+
derived from the source code without prior written permission.
|
16
|
+
|
17
|
+
You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and
|
18
|
+
against any loss, damage, claims or lawsuits, including attorney's
|
19
|
+
fees that arise or result from your use or distribution of the source
|
20
|
+
code.
|
21
|
+
|
22
|
+
THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT
|
23
|
+
ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
|
24
|
+
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
25
|
+
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF
|
26
|
+
NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA
|
27
|
+
OR ITS SUPPLIERS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
28
|
+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
29
|
+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
30
|
+
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
31
|
+
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
32
|
+
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOURCE CODE, EVEN IF
|
33
|
+
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
34
|
+
*/
|
35
|
+
|
36
|
+
|
37
|
+
package com.adobe.webapis
|
38
|
+
{
|
39
|
+
import flash.events.EventDispatcher;
|
40
|
+
|
41
|
+
/**
|
42
|
+
* Base class for remote service classes.
|
43
|
+
*/
|
44
|
+
public class ServiceBase extends EventDispatcher
|
45
|
+
{
|
46
|
+
public function ServiceBase()
|
47
|
+
{
|
48
|
+
}
|
49
|
+
|
50
|
+
}
|
51
|
+
}
|
@@ -0,0 +1,111 @@
|
|
1
|
+
/*
|
2
|
+
Adobe Systems Incorporated(r) Source Code License Agreement
|
3
|
+
Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved.
|
4
|
+
|
5
|
+
Please read this Source Code License Agreement carefully before using
|
6
|
+
the source code.
|
7
|
+
|
8
|
+
Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive,
|
9
|
+
no-charge, royalty-free, irrevocable copyright license, to reproduce,
|
10
|
+
prepare derivative works of, publicly display, publicly perform, and
|
11
|
+
distribute this source code and such derivative works in source or
|
12
|
+
object code form without any attribution requirements.
|
13
|
+
|
14
|
+
The name "Adobe Systems Incorporated" must not be used to endorse or promote products
|
15
|
+
derived from the source code without prior written permission.
|
16
|
+
|
17
|
+
You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and
|
18
|
+
against any loss, damage, claims or lawsuits, including attorney's
|
19
|
+
fees that arise or result from your use or distribution of the source
|
20
|
+
code.
|
21
|
+
|
22
|
+
THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT
|
23
|
+
ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
|
24
|
+
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
25
|
+
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF
|
26
|
+
NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA
|
27
|
+
OR ITS SUPPLIERS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
28
|
+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
29
|
+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
30
|
+
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
31
|
+
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
32
|
+
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOURCE CODE, EVEN IF
|
33
|
+
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
34
|
+
*/
|
35
|
+
|
36
|
+
package com.adobe.webapis
|
37
|
+
{
|
38
|
+
import flash.events.IOErrorEvent;
|
39
|
+
import flash.events.SecurityErrorEvent;
|
40
|
+
import flash.events.ProgressEvent;
|
41
|
+
|
42
|
+
import com.adobe.net.DynamicURLLoader;
|
43
|
+
|
44
|
+
/**
|
45
|
+
* Dispatched when data is
|
46
|
+
* received as the download operation progresses.
|
47
|
+
*
|
48
|
+
* @eventType flash.events.ProgressEvent.PROGRESS
|
49
|
+
*
|
50
|
+
* @langversion ActionScript 3.0
|
51
|
+
* @playerversion Flash 9.0
|
52
|
+
*/
|
53
|
+
[Event(name="progress", type="flash.events.ProgressEvent")]
|
54
|
+
|
55
|
+
/**
|
56
|
+
* Dispatched if a call to the server results in a fatal
|
57
|
+
* error that terminates the download.
|
58
|
+
*
|
59
|
+
* @eventType flash.events.IOErrorEvent.IO_ERROR
|
60
|
+
*
|
61
|
+
* @langversion ActionScript 3.0
|
62
|
+
* @playerversion Flash 9.0
|
63
|
+
*/
|
64
|
+
[Event(name="ioError", type="flash.events.IOErrorEvent")]
|
65
|
+
|
66
|
+
/**
|
67
|
+
* A securityError event occurs if a call attempts to
|
68
|
+
* load data from a server outside the security sandbox.
|
69
|
+
*
|
70
|
+
* @eventType flash.events.SecurityErrorEvent.SECURITY_ERROR
|
71
|
+
*
|
72
|
+
* @langversion ActionScript 3.0
|
73
|
+
* @playerversion Flash 9.0
|
74
|
+
*/
|
75
|
+
[Event(name="securityError", type="flash.events.SecurityErrorEvent")]
|
76
|
+
|
77
|
+
/**
|
78
|
+
* Base class for services that utilize URLLoader
|
79
|
+
* to communicate with remote APIs / Services.
|
80
|
+
*
|
81
|
+
* @langversion ActionScript 3.0
|
82
|
+
* @playerversion Flash 9.0
|
83
|
+
*/
|
84
|
+
public class URLLoaderBase extends ServiceBase
|
85
|
+
{
|
86
|
+
protected function getURLLoader():DynamicURLLoader
|
87
|
+
{
|
88
|
+
var loader:DynamicURLLoader = new DynamicURLLoader();
|
89
|
+
loader.addEventListener("progress", onProgress);
|
90
|
+
loader.addEventListener("ioError", onIOError);
|
91
|
+
loader.addEventListener("securityError", onSecurityError);
|
92
|
+
|
93
|
+
return loader;
|
94
|
+
}
|
95
|
+
|
96
|
+
private function onIOError(event:IOErrorEvent):void
|
97
|
+
{
|
98
|
+
dispatchEvent(event);
|
99
|
+
}
|
100
|
+
|
101
|
+
private function onSecurityError(event:SecurityErrorEvent):void
|
102
|
+
{
|
103
|
+
dispatchEvent(event);
|
104
|
+
}
|
105
|
+
|
106
|
+
private function onProgress(event:ProgressEvent):void
|
107
|
+
{
|
108
|
+
dispatchEvent(event);
|
109
|
+
}
|
110
|
+
}
|
111
|
+
}
|
@@ -0,0 +1,78 @@
|
|
1
|
+
/*
|
2
|
+
Adobe Systems Incorporated(r) Source Code License Agreement
|
3
|
+
Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved.
|
4
|
+
|
5
|
+
Please read this Source Code License Agreement carefully before using
|
6
|
+
the source code.
|
7
|
+
|
8
|
+
Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive,
|
9
|
+
no-charge, royalty-free, irrevocable copyright license, to reproduce,
|
10
|
+
prepare derivative works of, publicly display, publicly perform, and
|
11
|
+
distribute this source code and such derivative works in source or
|
12
|
+
object code form without any attribution requirements.
|
13
|
+
|
14
|
+
The name "Adobe Systems Incorporated" must not be used to endorse or promote products
|
15
|
+
derived from the source code without prior written permission.
|
16
|
+
|
17
|
+
You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and
|
18
|
+
against any loss, damage, claims or lawsuits, including attorney's
|
19
|
+
fees that arise or result from your use or distribution of the source
|
20
|
+
code.
|
21
|
+
|
22
|
+
THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT
|
23
|
+
ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
|
24
|
+
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
25
|
+
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF
|
26
|
+
NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA
|
27
|
+
OR ITS SUPPLIERS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
28
|
+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
29
|
+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
30
|
+
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
31
|
+
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
32
|
+
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOURCE CODE, EVEN IF
|
33
|
+
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
34
|
+
*/
|
35
|
+
|
36
|
+
|
37
|
+
package com.adobe.webapis.events
|
38
|
+
{
|
39
|
+
|
40
|
+
import flash.events.Event;
|
41
|
+
|
42
|
+
/**
|
43
|
+
* Event class that contains data loaded from remote services.
|
44
|
+
*
|
45
|
+
* @author Mike Chambers
|
46
|
+
*/
|
47
|
+
public class ServiceEvent extends Event
|
48
|
+
{
|
49
|
+
private var _data:Object = new Object();;
|
50
|
+
|
51
|
+
/**
|
52
|
+
* Constructor for ServiceEvent class.
|
53
|
+
*
|
54
|
+
* @param type The type of event that the instance represents.
|
55
|
+
*/
|
56
|
+
public function ServiceEvent(type:String, bubbles:Boolean = false,
|
57
|
+
cancelable:Boolean=false)
|
58
|
+
{
|
59
|
+
super(type, bubbles, cancelable);
|
60
|
+
}
|
61
|
+
|
62
|
+
/**
|
63
|
+
* This object contains data loaded in response
|
64
|
+
* to remote service calls, and properties associated with that call.
|
65
|
+
*/
|
66
|
+
public function get data():Object
|
67
|
+
{
|
68
|
+
return _data;
|
69
|
+
}
|
70
|
+
|
71
|
+
public function set data(d:Object):void
|
72
|
+
{
|
73
|
+
_data = d;
|
74
|
+
}
|
75
|
+
|
76
|
+
|
77
|
+
}
|
78
|
+
}
|
@@ -0,0 +1,426 @@
|
|
1
|
+
|
2
|
+
package org.rubyforge.dango {
|
3
|
+
/**
|
4
|
+
* Dangoのクライアントフレームワーク本体のクラス
|
5
|
+
*
|
6
|
+
*/
|
7
|
+
|
8
|
+
import flash.net.*;
|
9
|
+
import flash.events.*;
|
10
|
+
import flash.text.*;
|
11
|
+
import flash.utils.*;
|
12
|
+
import flash.system.*;
|
13
|
+
import mx.utils.ObjectUtil;
|
14
|
+
|
15
|
+
import com.adobe.serialization.json.JSON;
|
16
|
+
|
17
|
+
import flash.events.IEventDispatcher;
|
18
|
+
import flash.events.EventDispatcher;
|
19
|
+
import flash.events.Event;
|
20
|
+
|
21
|
+
import org.rubyforge.dango.DangoUtil;
|
22
|
+
import org.rubyforge.dango.DangoErrorCode;
|
23
|
+
|
24
|
+
public class DangoClientFramework implements IEventDispatcher {
|
25
|
+
|
26
|
+
private var socket:Socket; //ソケット
|
27
|
+
private var dispatcher:EventDispatcher; // Event送出用
|
28
|
+
|
29
|
+
private var is_debug:Boolean; // Debugモードかどうかのフラグ
|
30
|
+
private var is_connect:Boolean = false; // 接続完了しているかどうか
|
31
|
+
|
32
|
+
private var receve_count:uint = 0; // データ受信回数
|
33
|
+
|
34
|
+
private var recv_not_yet_size:uint = 0; // データ受信時のキャッシュ
|
35
|
+
private var recv_not_yet_str:String = ""; // データ受信時のキャッシュ
|
36
|
+
|
37
|
+
private var polling_timer:Timer; // ポーリング(ハートビート)用タイマーの設定
|
38
|
+
private var polling_timer_msec:uint = 5000; // ポーリング(ハートビート)用タイマーのミリ秒
|
39
|
+
|
40
|
+
private var delay_send_timer:Timer; // 遅延送信用のタイマーの設定
|
41
|
+
private var delay_send_timer_msec:uint = 1500; // 遅延送信用のタイマーのミリ秒
|
42
|
+
private var delay_send_cache:Array = []; // 遅延送信用のキャッシュ
|
43
|
+
|
44
|
+
// private var server_host:String = "172.31.1.74";
|
45
|
+
// private var server_host:String = "localhost";
|
46
|
+
// private var server_port:int = 15000;
|
47
|
+
private var server_host:String;
|
48
|
+
private var server_port:int;
|
49
|
+
|
50
|
+
public var sid:int;
|
51
|
+
|
52
|
+
/**
|
53
|
+
* コンストラクタ
|
54
|
+
*
|
55
|
+
*/
|
56
|
+
public function DangoClientFramework(config:*, d:Boolean = false){
|
57
|
+
is_debug = d; // Debugモードかどうかのフラグ
|
58
|
+
|
59
|
+
// 設定ファイルの読み込み
|
60
|
+
server_host = config.server_host;
|
61
|
+
server_port = config.server_port;
|
62
|
+
// is_debug = config.debug;
|
63
|
+
is_debug = true;
|
64
|
+
|
65
|
+
var policy_file_protocol:String = config.policy_file_protocol;
|
66
|
+
var policy_file_port:uint = config.policy_file_port;
|
67
|
+
var policy_file_path:String = config.policy_file_path;
|
68
|
+
|
69
|
+
|
70
|
+
// Event送出用
|
71
|
+
dispatcher = new EventDispatcher(this);
|
72
|
+
|
73
|
+
// Security.sandboxType
|
74
|
+
trace("Security.sandboxType:" + Security.sandboxType);
|
75
|
+
|
76
|
+
// policy_file
|
77
|
+
// if(!policy_file_protocol){ policy_file_protocol = "http" };
|
78
|
+
if(!policy_file_path) { policy_file_path = "/crossdomain.xml" };
|
79
|
+
|
80
|
+
// ソケットの生成
|
81
|
+
socket = new Socket();
|
82
|
+
|
83
|
+
// ソケットのイベントリスナーの追加
|
84
|
+
socket.addEventListener(Event.CONNECT, connectHandler, false);
|
85
|
+
socket.addEventListener(Event.CONNECT, connectHandler, true);
|
86
|
+
socket.addEventListener(Event.CLOSE, closeHandler, false);
|
87
|
+
socket.addEventListener(Event.CLOSE, closeHandler, true);
|
88
|
+
socket.addEventListener(ProgressEvent.SOCKET_DATA, socketDataHandler, false);
|
89
|
+
socket.addEventListener(ProgressEvent.SOCKET_DATA, socketDataHandler, true);
|
90
|
+
socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler, false);
|
91
|
+
socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler, true);
|
92
|
+
socket.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler, false);
|
93
|
+
socket.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler, true);
|
94
|
+
trace("registered event handling.");
|
95
|
+
|
96
|
+
// ポリシーファイルの読み込み
|
97
|
+
var url_load_policy_file:String;
|
98
|
+
// url_load_policy_file = "xmlsocket://" + server_host + ":" + server_port;
|
99
|
+
// url_load_policy_file = "http://aiarebaba.hi-fi-net.com/crossdomain.xml";
|
100
|
+
url_load_policy_file = "http://" + server_host + policy_file_path;
|
101
|
+
trace("url_load_policy_file=" + url_load_policy_file);
|
102
|
+
Security.loadPolicyFile(url_load_policy_file);
|
103
|
+
|
104
|
+
// 接続
|
105
|
+
try{
|
106
|
+
trace("connectiong... host=" + server_host + " port=" + server_port);
|
107
|
+
socket.connect(server_host, server_port);
|
108
|
+
trace("connected host=" + server_host + " port=" + server_port);
|
109
|
+
} catch(err:Error){
|
110
|
+
trace("connect error err=" + err + " name=" + err.name + " message=" + err.message);
|
111
|
+
return(void);
|
112
|
+
}
|
113
|
+
|
114
|
+
// polling用タイマーの設定
|
115
|
+
var polling_timer:Timer = new Timer(polling_timer_msec, 0); // タイマーの追加
|
116
|
+
polling_timer.addEventListener(TimerEvent.TIMER, polling_callback); // イベントリスナーの発行
|
117
|
+
polling_timer.start(); // タイマーの作動開始
|
118
|
+
|
119
|
+
// 遅延送信用タイマーの設定
|
120
|
+
var delay_send_timer:Timer = new Timer(delay_send_timer_msec, 0); // タイマーの追加
|
121
|
+
delay_send_timer.addEventListener(TimerEvent.TIMER, delay_send_callback); // イベントリスナーの発行
|
122
|
+
delay_send_timer.start(); // タイマーの作動開始
|
123
|
+
}
|
124
|
+
|
125
|
+
//接続イベントの処理
|
126
|
+
private function connectHandler(evt:Event):void {
|
127
|
+
is_connect = true;
|
128
|
+
var msg:String = "DangoClientFramework:connectHandler";
|
129
|
+
if(is_debug){ trace(msg); }
|
130
|
+
}
|
131
|
+
|
132
|
+
//切断イベントの処理
|
133
|
+
private function closeHandler(evt:Event):void {
|
134
|
+
// タイマーが動いていれば止める
|
135
|
+
if(polling_timer != null && polling_timer.running){ polling_timer.stop(); }
|
136
|
+
|
137
|
+
is_connect = false;
|
138
|
+
var msg:String = "DangoClientFramework:closeHandler";
|
139
|
+
if(is_debug){ trace(msg); }
|
140
|
+
this.dispatchEvent(new DangoErrorEvent("DangoError", DangoErrorCode.CloseError, msg));
|
141
|
+
}
|
142
|
+
|
143
|
+
//セキュリティエラーイベントの処理
|
144
|
+
private function securityErrorHandler(evt:SecurityErrorEvent):void {
|
145
|
+
// タイマーが動いていれば止める
|
146
|
+
if(polling_timer != null && polling_timer.running){ polling_timer.stop(); }
|
147
|
+
|
148
|
+
is_connect = false;
|
149
|
+
var msg:String = "DangoClientFramework:securityErrorHandler:text=" + evt.text ;
|
150
|
+
|
151
|
+
if(is_debug){ trace(msg); }
|
152
|
+
this.dispatchEvent(new DangoErrorEvent("DangoError", DangoErrorCode.SecurityError, msg));
|
153
|
+
}
|
154
|
+
|
155
|
+
//IOエラーイベントの処理
|
156
|
+
private function ioErrorHandler(evt:IOErrorEvent):void {
|
157
|
+
// タイマーが動いていれば止める
|
158
|
+
if(polling_timer != null && polling_timer.running){ polling_timer.stop(); }
|
159
|
+
|
160
|
+
is_connect = false;
|
161
|
+
var msg:String = "DangoClientFramework:ioErrorHandler";
|
162
|
+
if(is_debug){ trace(msg); }
|
163
|
+
this.dispatchEvent(new DangoErrorEvent("DangoError", DangoErrorCode.IOError, msg));
|
164
|
+
}
|
165
|
+
|
166
|
+
//プログレスイベントの処理(呼び出し用イベントのディスパッチ)
|
167
|
+
private function socketDataHandler(evt:ProgressEvent):void {
|
168
|
+
receve_count ++;
|
169
|
+
if(is_debug){ trace("DangoClientFramework:socketDataHandler:" + receve_count); }
|
170
|
+
var receive_data:Object = this.receive_notice();
|
171
|
+
|
172
|
+
if(recv_not_yet_size == 0){ // 未受信データが無ければ
|
173
|
+
if(receive_data != {}){ // データが空なら無視する
|
174
|
+
var notice_name:String = receive_data["notice"];
|
175
|
+
|
176
|
+
if(notice_name == "_notice_sid"){ // 接続直後のsid通知なら
|
177
|
+
this.sid = receive_data["_sid"];
|
178
|
+
// if(is_debug){ trace("DangoClientFramework:this.sid=" + this.sid + ":" + DangoUtil.now2str()); }
|
179
|
+
if(is_debug){ trace("DangoClientFramework:this.sid=" + this.sid + ":" + receve_count); }
|
180
|
+
|
181
|
+
} else if(notice_name == "_heart_beat"){ // heart beat通知なら
|
182
|
+
if(is_debug){ trace("DangoClientFramework:_heart_beat:" + receve_count); }
|
183
|
+
|
184
|
+
} else { // 通常のデータならイベント発生
|
185
|
+
if(is_debug){ trace("DangoClientFramework:dispatchEvent:dango_" + notice_name + ":" + receve_count); }
|
186
|
+
this.dispatchEvent(new DangoReceiveEvent("dango_" + notice_name, receive_data));
|
187
|
+
}
|
188
|
+
} else { // データが空なら
|
189
|
+
// if(is_debug){ trace("DangoClientFramework:receive_data is empty." + DangoUtil.now2str()); }
|
190
|
+
if(is_debug){ trace("DangoClientFramework:receive_data is empty."); }
|
191
|
+
}
|
192
|
+
}
|
193
|
+
}
|
194
|
+
|
195
|
+
// Event送出用
|
196
|
+
public function addEventListener(type:String, listener:Function,
|
197
|
+
useCapture:Boolean = false,
|
198
|
+
priority:int = 0,
|
199
|
+
useWeakReference:Boolean = false):void{
|
200
|
+
dispatcher.addEventListener(type, listener, useCapture, priority);
|
201
|
+
}
|
202
|
+
public function dispatchEvent(evt:Event):Boolean{
|
203
|
+
return dispatcher.dispatchEvent(evt);
|
204
|
+
}
|
205
|
+
public function hasEventListener(type:String):Boolean{
|
206
|
+
return dispatcher.hasEventListener(type);
|
207
|
+
}
|
208
|
+
public function removeEventListener(type:String, listener:Function,
|
209
|
+
useCapture:Boolean = false):void{
|
210
|
+
dispatcher.removeEventListener(type, listener, useCapture);
|
211
|
+
}
|
212
|
+
public function willTrigger(type:String):Boolean {
|
213
|
+
return dispatcher.willTrigger(type);
|
214
|
+
}
|
215
|
+
|
216
|
+
|
217
|
+
/**
|
218
|
+
* polling_callback
|
219
|
+
* ハートビートを送る
|
220
|
+
*
|
221
|
+
* @param evt:TimerEvent
|
222
|
+
* @return void
|
223
|
+
*/
|
224
|
+
public function polling_callback(evt:TimerEvent):void {
|
225
|
+
if(is_debug){ trace("DangoClientFramework:polling_callback:" + DangoUtil.now2str() ); }
|
226
|
+
if(socket.connected){
|
227
|
+
// var send_obj:Object = null;
|
228
|
+
// this.send_data_to_server(send_obj);
|
229
|
+
|
230
|
+
var hb_id:String = String((new Date()).time) + String(this.sid);
|
231
|
+
if(is_debug){ trace("DangoClientFramework:send _notice_heart_beat:" + hb_id + ":" + DangoUtil.now2str()); }
|
232
|
+
this.send_action("_notice_heart_beat", { "_hb_id": hb_id}); // ハートビート送信
|
233
|
+
}
|
234
|
+
}
|
235
|
+
|
236
|
+
/**
|
237
|
+
* delay_send_callback
|
238
|
+
* 遅延送信用タイマーコールバック
|
239
|
+
*
|
240
|
+
* @param socket:Socket
|
241
|
+
* @param send_obj:Object
|
242
|
+
* @return void
|
243
|
+
*/
|
244
|
+
public function delay_send_callback(evt:TimerEvent):void {
|
245
|
+
// if(is_debug){ trace("DangoClientFramework:delay_send_callback:evt:" + evt); }
|
246
|
+
if(!is_connect){ return(void); }
|
247
|
+
if(socket.connected){
|
248
|
+
var send_obj_dup:Object;
|
249
|
+
var i:uint;
|
250
|
+
|
251
|
+
for (i = 0; i < 5; i++) {
|
252
|
+
if(delay_send_cache.length == 0) { break; }
|
253
|
+
send_obj_dup = delay_send_cache.pop();
|
254
|
+
// データをすぐ送信
|
255
|
+
this.send_data_to_server(send_obj_dup);
|
256
|
+
if(is_debug){ trace("DangoClientFramework:delay_send_callback:sent:" + DangoUtil.now2str()); }
|
257
|
+
}
|
258
|
+
}
|
259
|
+
}
|
260
|
+
|
261
|
+
/**
|
262
|
+
* send data to server.
|
263
|
+
* クライアント側から使うサーバーへのデータ送信メソッド
|
264
|
+
*
|
265
|
+
* @param socket:Socket
|
266
|
+
* @param send_obj:Object
|
267
|
+
* @return void
|
268
|
+
*/
|
269
|
+
public function send_action(action_name:String, send_obj:Object, delay:Boolean=false):void {
|
270
|
+
if(is_debug){ trace("DangoClientFramework:send_action:start:" + action_name + ":" + DangoUtil.now2str()); }
|
271
|
+
|
272
|
+
// if(!is_connect){ throw new DangoError("error:not connect" , 29); } // 接続されていない場合はエラー
|
273
|
+
|
274
|
+
// 送信データの作成
|
275
|
+
var send_obj_dup:Object = ObjectUtil.copy(send_obj);
|
276
|
+
send_obj_dup["action"] = action_name;
|
277
|
+
|
278
|
+
// delayフラグがあったり、接続がまだなら、遅延送信用のキャッシュにデータを入れる
|
279
|
+
if(delay || !is_connect){
|
280
|
+
delay_send_cache.push(send_obj_dup);
|
281
|
+
|
282
|
+
if(is_debug){ trace("DangoClientFramework:send_action:delay_pull:" + action_name + ":" + DangoUtil.now2str()); }
|
283
|
+
return(void);
|
284
|
+
}
|
285
|
+
|
286
|
+
// データをすぐ送信
|
287
|
+
this.send_data_to_server(send_obj_dup);
|
288
|
+
if(is_debug){ trace("DangoClientFramework:send_action:end:" + action_name + ":" + DangoUtil.now2str()); }
|
289
|
+
}
|
290
|
+
|
291
|
+
/**
|
292
|
+
* send data to server.
|
293
|
+
* フレームワーク側のデータ送信の一般処理
|
294
|
+
*
|
295
|
+
* @param socket:Socket
|
296
|
+
* @param send_obj:Object
|
297
|
+
* @return void
|
298
|
+
*/
|
299
|
+
public function send_data_to_server( send_obj:Object ):void {
|
300
|
+
// if(is_debug){ trace("DangoClientFramework:send_data_to_server:send_obj=" + ObjectUtil.toString(send_obj)); }
|
301
|
+
|
302
|
+
var type:int = 0;
|
303
|
+
|
304
|
+
// データが空ならJSONencodeしない
|
305
|
+
var send_obj_str:String;
|
306
|
+
if(send_obj == null){
|
307
|
+
send_obj_str = "\n";
|
308
|
+
} else {
|
309
|
+
send_obj_str = JSON.encode(send_obj) + "\n";
|
310
|
+
}
|
311
|
+
|
312
|
+
var send_obj_size:int = DangoUtil.string_byte_length(send_obj_str);
|
313
|
+
|
314
|
+
// if(is_debug){ trace("DangoClientFramework:send:" + type + ":" + send_obj_size + ":" + send_obj_str); }
|
315
|
+
|
316
|
+
// 長さ送信
|
317
|
+
var byte_array:ByteArray = new ByteArray;
|
318
|
+
byte_array.writeByte(type);
|
319
|
+
byte_array.writeUnsignedInt(send_obj_size);
|
320
|
+
|
321
|
+
socket.writeBytes(byte_array, 0, 5);
|
322
|
+
socket.writeUTFBytes("\n");
|
323
|
+
socket.flush();
|
324
|
+
|
325
|
+
// データ送信
|
326
|
+
socket.writeUTFBytes(send_obj_str);
|
327
|
+
socket.flush();
|
328
|
+
|
329
|
+
// if(is_debug){ trace("DangoClientFramework:send_obj_str:" + send_obj_str + ":" + DangoUtil.now2str()); }
|
330
|
+
}
|
331
|
+
|
332
|
+
/**
|
333
|
+
* receive data from server.
|
334
|
+
* フレームワーク側のデータ受信の一般処理
|
335
|
+
*
|
336
|
+
* @return Object
|
337
|
+
*/
|
338
|
+
public function receive_notice():Object {
|
339
|
+
if(is_debug){ trace("DangoClientFramework:receive_notice:" + receve_count + ":" + DangoUtil.now2str()); }
|
340
|
+
|
341
|
+
// 変数定義
|
342
|
+
var recv_data_orig:String = "";
|
343
|
+
var bytes_available:uint;
|
344
|
+
|
345
|
+
// まず読めるデータをすべてByteArrayに入れる
|
346
|
+
var byte_array:ByteArray = new ByteArray;
|
347
|
+
socket.readBytes(byte_array, 0, socket.bytesAvailable);
|
348
|
+
var byte_read_size:uint = byte_array.length;
|
349
|
+
|
350
|
+
if(recv_not_yet_size == 0){ // 未受信データが無ければ
|
351
|
+
// if(is_debug){ trace("DangoClientFramework:recv_not_yet_size==0"); }
|
352
|
+
|
353
|
+
if(byte_read_size < 6){ // きちんとデータが届いていなければ
|
354
|
+
this.dispatchEvent(new DangoErrorEvent("DangoError", DangoErrorCode.IOError, "byte_read_size is too short."));
|
355
|
+
return({});
|
356
|
+
}
|
357
|
+
|
358
|
+
// 長さを取得
|
359
|
+
var byte_array_size:ByteArray = new ByteArray;
|
360
|
+
try{
|
361
|
+
byte_array.readBytes(byte_array_size, 0, 5);
|
362
|
+
} catch(err:Error){
|
363
|
+
this.dispatchEvent(new DangoErrorEvent("DangoError", DangoErrorCode.IOError, "failed to byte_array.readBytes."));
|
364
|
+
return({});
|
365
|
+
}
|
366
|
+
|
367
|
+
var type:int = byte_array_size.readByte();
|
368
|
+
recv_not_yet_size = byte_array_size.readUnsignedInt();
|
369
|
+
var crlf:String = byte_array.readUTFBytes(1);
|
370
|
+
byte_read_size -= 6;
|
371
|
+
// if(is_debug){ trace("DangoClientFramework:recv_not_yet_size=" + recv_not_yet_size); }
|
372
|
+
}
|
373
|
+
|
374
|
+
// 読めているだけ読んで、その分recv_not_yet_sizeを減らす
|
375
|
+
if(recv_not_yet_size > byte_read_size){
|
376
|
+
// if(is_debug){ trace("DangoClientFramework:byte_read_size=" + byte_read_size); }
|
377
|
+
recv_data_orig = byte_array.readUTFBytes(byte_read_size);
|
378
|
+
recv_not_yet_size -= byte_read_size;
|
379
|
+
}else{
|
380
|
+
// if(is_debug){ trace("DangoClientFramework:recv_not_yet_size=" + recv_not_yet_size); }
|
381
|
+
recv_data_orig = byte_array.readUTFBytes(recv_not_yet_size);
|
382
|
+
recv_not_yet_size = 0;
|
383
|
+
}
|
384
|
+
|
385
|
+
// if(is_debug){ trace("DangoClientFramework:recv_data_orig:" + recv_data_orig); }
|
386
|
+
|
387
|
+
// 全データを受信したかどうかを確認
|
388
|
+
if(recv_not_yet_size == 0){ // 受信完了ならJSONパース
|
389
|
+
var recv_data:String = recv_not_yet_str + recv_data_orig;
|
390
|
+
recv_not_yet_str = "";
|
391
|
+
|
392
|
+
// if(is_debug){ trace("DangoClientFramework:recieve:data=" + ObjectUtil.toString(recv_data)); }
|
393
|
+
|
394
|
+
var ret_obj_data:Object;
|
395
|
+
if(recv_data && recv_data != "" && recv_data != "\n"){ // データが空じゃないならdecode
|
396
|
+
ret_obj_data = JSON.decode(recv_data) as Object;
|
397
|
+
|
398
|
+
} else { // データが空なら空データを作ってreturn
|
399
|
+
ret_obj_data = {};
|
400
|
+
return(ret_obj_data);
|
401
|
+
}
|
402
|
+
|
403
|
+
// ret_obj_dataがObjectでnoticeが存在しているかのチェック
|
404
|
+
if(!(ret_obj_data is Object) || !(ret_obj_data["notice"] is String)){
|
405
|
+
if(!is_connect){ throw new DangoError("error:recieve data is invalid." , 29); }
|
406
|
+
}
|
407
|
+
|
408
|
+
if(ret_obj_data["notice"] == "_notice_sid"){
|
409
|
+
if(is_debug){ trace("DangoClientFramework:recieve:_notice_sid:no response:" + receve_count + ":" + DangoUtil.now2str()); }
|
410
|
+
}else{
|
411
|
+
var response_notice_name:String;
|
412
|
+
response_notice_name = "_response";
|
413
|
+
if(is_debug){ trace("DangoClientFramework:sending:response:notice_name=" + ret_obj_data["notice"] + ":" + ret_obj_data["_id"] + ":" + receve_count + ":" + DangoUtil.now2str()); }
|
414
|
+
|
415
|
+
this.send_action(response_notice_name, {"_id":ret_obj_data["_id"]}); // 受信完了確認の為に空データを送る
|
416
|
+
}
|
417
|
+
return(ret_obj_data);
|
418
|
+
|
419
|
+
} else { // まだデータが残っているなら空を返す
|
420
|
+
recv_not_yet_str += recv_data_orig;
|
421
|
+
return({});
|
422
|
+
}
|
423
|
+
}
|
424
|
+
|
425
|
+
}
|
426
|
+
}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
//参考:http://livedocs.adobe.com/flex/2_jp/docs/wwhelp/wwhimpl/js/html/wwhelp.htm?href=Part5_ProgAS.html
|
2
|
+
|
3
|
+
package org.rubyforge.dango {
|
4
|
+
import flash.events.*;
|
5
|
+
|
6
|
+
public class DangoError extends Error {
|
7
|
+
public function DangoError(message:String, errorID:int) {
|
8
|
+
super(message, errorID);
|
9
|
+
}
|
10
|
+
}
|
11
|
+
}
|