1 APE.PipeProxy = new Class({
5 initialize: function(core, options){
6 this.core = core || window.Ape;
9 this.initRequestMethod();
17 init: function(options){
18 this.pipe = options.pipe;
20 this.core.addPipe(this.getPubid(), this);
22 this.onRaw('proxy_event', this.rawProxyEvent);
23 this.ape.fireEvent('proxyPipeCreate', [this, options]);
34 open: function(hostname, port){
35 if (this.core.status == 0) this.core.start(null, false);
36 //Adding a callback to request response to create a new pipe if this.pipe haven't been init
37 this.request.stack.add('PROXY_CONNECT', {'host':hostname, 'port':port}, this.pipe ? {} : {'callback':this.callback.bind(this)});
38 this.request.stack.send();
42 this.request.send('SEND', {'msg':B64.encode(data)});
45 rawProxyEvent: function(resp){
46 switch (resp.data.event) {
48 var data = B64.decode(resp.data.data);
49 this.fireGlobalEvent('proxyRead', data)
50 if (this.onread) this.onread(data);
53 this.fireGlobalEvent('proxyConnect');
54 if (this.onopen) this.onopen();
57 this.fireGlobalEvent('proxyClose');
58 if (this.onclose) this.onclose();
63 callback: function(raw){
65 this.rawProxyEvent(raw);
69 APE.Core = new Class({
74 * This allow ape to be compatible with TCPSocket
76 TCPSocket: APE.PipeProxy