Browse Source

[std] remove haxe.remoting

Simon Krajewski 7 years ago
parent
commit
0431983229

+ 0 - 90
std/haxe/remoting/AMFConnection.hx

@@ -1,90 +0,0 @@
-/*
- * Copyright (C)2005-2018 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package haxe.remoting;
-
-/**
-	Allows a connection to an AMF Remoting server such as Flash Media Server or AMFPHP.
-*/
-class AMFConnection implements AsyncConnection implements Dynamic<AsyncConnection> {
-
-	var __data : {
-		error : Dynamic -> Void,
-		#if flash
-		cnx : flash.net.NetConnection,
-		#else
-		cnx : Dynamic,
-		#end
-	};
-	var __path : Array<String>;
-
-	function new( data, path ) {
-		__data = data;
-		__path = path;
-	}
-
-	public function resolve( name ) : AsyncConnection {
-		var s = new AMFConnection(__data,__path.copy());
-		s.__path.push(name);
-		return s;
-	}
-
-	public function setErrorHandler(h) {
-		__data.error = h;
-	}
-
-	public function close() {
-		__data.cnx.close();
-	}
-
-	public function call( params : Array<Dynamic>, ?onResult : Dynamic -> Void ) : Void {
-		if( onResult == null ) onResult = function(e) {};
-		var p = params.copy();
-		#if flash
-		p.unshift(new flash.net.Responder(onResult,__data.error));
-		#else
-		p.unshift({ onStatus : __data.error, onResult : onResult });
-		#end
-		p.unshift(__path.join("."));
-		untyped __data.cnx.call.apply(__data,p);
-	}
-
-	#if flash
-	public static function urlConnect( gatewayUrl : String ) {
-		var c = new flash.net.NetConnection();
-		var cnx = new AMFConnection({ cnx : c, error : function(e) throw e },[]);
-		c.addEventListener(flash.events.NetStatusEvent.NET_STATUS,function(e:flash.events.NetStatusEvent) {
-			cnx.__data.error(e);
-		});
-		c.connect(gatewayUrl);
-		return cnx;
-	}
-
-	public static function connect( nc ) {
-		return new AMFConnection({ cnx : nc, error : function(e) throw e },[]);
-	}
-
-	public static function registerClassAlias( s : String, cl : Class<Dynamic> ) {
-		untyped __global__[ "flash.net.registerClassAlias" ]( s, cl );
-	}
-	#end
-
-}

+ 0 - 60
std/haxe/remoting/AsyncAdapter.hx

@@ -1,60 +0,0 @@
-/*
- * Copyright (C)2005-2018 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package haxe.remoting;
-
-/**
-	Build an AsyncConnection from a synchronized Connection.
-**/
-class AsyncAdapter implements AsyncConnection {
-
-	var __cnx : Connection;
-	var __error : { ref : Dynamic -> Void };
-
-	function new(cnx,error) {
-		__cnx = cnx;
-		__error = error;
-	}
-
-	public function resolve( name ) : AsyncConnection {
-		return new AsyncAdapter(__cnx.resolve(name),__error);
-	}
-
-	public function setErrorHandler(h) {
-		__error.ref = h;
-	}
-
-	public function call( params : Array<Dynamic>, ?onResult : Dynamic -> Void ) {
-		var ret;
-		try {
-			ret = __cnx.call(params);
-		} catch( e : Dynamic ) {
-			__error.ref(e);
-			return;
-		}
-		if( onResult != null ) onResult(ret);
-	}
-
-	public static function create( cnx : Connection ) : AsyncConnection {
-		return new AsyncAdapter(cnx,{ ref : function(e) throw e });
-	}
-
-}

+ 0 - 33
std/haxe/remoting/AsyncConnection.hx

@@ -1,33 +0,0 @@
-/*
- * Copyright (C)2005-2018 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package haxe.remoting;
-
-/**
-	For asynchronous connections, where the results are events that will be resolved later in the execution process.
-*/
-interface AsyncConnection implements Dynamic<AsyncConnection> {
-
-	function resolve( name : String ) : AsyncConnection;
-	function call( params : Array<Dynamic>, ?result : Dynamic -> Void ) : Void;
-	function setErrorHandler( error : Dynamic -> Void ) : Void;
-
-}

+ 0 - 88
std/haxe/remoting/AsyncDebugConnection.hx

@@ -1,88 +0,0 @@
-/*
- * Copyright (C)2005-2018 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package haxe.remoting;
-
-class AsyncDebugConnection implements AsyncConnection implements Dynamic<AsyncDebugConnection> {
-
-	var __path : Array<String>;
-	var __cnx : AsyncConnection;
-	var __data : {
-		error : Dynamic -> Void,
-		oncall : Array<String> -> Array<Dynamic> -> Void,
-		onerror : Array<String> -> Array<Dynamic> -> Dynamic -> Void,
-		onresult : Array<String> -> Array<Dynamic> -> Dynamic -> Void,
-	};
-
-	function new(path,cnx,data) {
-		__path = path;
-		__cnx = cnx;
-		__data = data;
-	}
-
-	public function resolve( name ) : AsyncConnection {
-		var cnx = new AsyncDebugConnection(__path.copy(),__cnx.resolve(name),__data);
-		cnx.__path.push(name);
-		return cnx;
-	}
-
-	public function setErrorHandler(h) {
-		__data.error = h;
-	}
-
-	public function setErrorDebug(h) {
-		__data.onerror = h;
-	}
-
-	public function setResultDebug(h) {
-		__data.onresult = h;
-	}
-
-	public function setCallDebug(h) {
-		__data.oncall = h;
-	}
-
-	public function call( params : Array<Dynamic>, ?onResult : Dynamic -> Void ) {
-		var me = this;
-		__data.oncall(__path,params);
-		__cnx.setErrorHandler(function(e) {
-			me.__data.onerror(me.__path,params,e);
-			me.__data.error(e);
-		});
-		__cnx.call(params,function(r) {
-			me.__data.onresult(me.__path,params,r);
-			if( onResult != null ) onResult(r);
-		});
-	}
-
-	public static function create( cnx : AsyncConnection ) {
-		var cnx = new AsyncDebugConnection([],cnx,{
-			error : function(e) throw e,
-			oncall : function(path,params) {},
-			onerror : null,
-			onresult : null,
-		});
-		cnx.setErrorDebug(function(path,params,e) trace(path.join(".")+"("+params.join(",")+") = ERROR "+Std.string(e)));
-		cnx.setResultDebug(function(path,params,e) trace(path.join(".")+"("+params.join(",")+") = "+Std.string(e)));
-		return cnx;
-	}
-
-}

+ 0 - 37
std/haxe/remoting/AsyncProxy.hx

@@ -1,37 +0,0 @@
-/*
- * Copyright (C)2005-2018 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package haxe.remoting;
-
-/**
-	This class is magic. When you extend it with a class C, it will automaticaly
-	create a stub class with all public methods forwarding remoting messages over
-	the connection.
-**/
-class AsyncProxy<T> {
-
-	var __cnx : AsyncConnection;
-
-	function new( c ) {
-		__cnx = c;
-	}
-
-}

+ 0 - 29
std/haxe/remoting/Connection.hx

@@ -1,29 +0,0 @@
-/*
- * Copyright (C)2005-2018 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package haxe.remoting;
-
-interface Connection implements Dynamic<Connection> {
-
-	function resolve( name : String ) : Connection;
-	function call( params : Array<Dynamic> ) : Dynamic;
-
-}

+ 0 - 64
std/haxe/remoting/Context.hx

@@ -1,64 +0,0 @@
-/*
- * Copyright (C)2005-2018 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package haxe.remoting;
-
-/**
-    Allows communication between platforms. This is a shared API that can be called on the connection at the client code.
-*/
-class Context {
-
-	var objects : haxe.ds.StringMap<{ obj : Dynamic, rec : Bool }>;
-
-	public function new() {
-		objects = new haxe.ds.StringMap();
-	}
-
-	public function addObject( name : String, obj : {}, ?recursive ) {
-		objects.set(name,{ obj : obj, rec : recursive });
-	}
-
-	public function call( path : Array<String>, params : Array<Dynamic> ) : Dynamic {
-		if( path.length < 2 ) throw "Invalid path '"+path.join(".")+"'";
-		var inf = objects.get(path[0]);
-		if( inf == null )
-			throw "No such object "+path[0];
-		var o = inf.obj;
-		var m = Reflect.field(o,path[1]);
-		if( path.length > 2 ) {
-			if( !inf.rec ) throw "Can't access "+path.join(".");
-			for( i in 2...path.length ) {
-				o = m;
-				m = Reflect.field(o,path[i]);
-			}
-		}
-		if( !Reflect.isFunction(m) )
-			throw "No such method "+path.join(".");
-		return Reflect.callMethod(o,m,params);
-	}
-
-	public static function share( name : String, obj : {} ) : Context {
-		var ctx = new Context();
-		ctx.addObject(name,obj);
-		return ctx;
-	}
-
-}

+ 0 - 63
std/haxe/remoting/ContextAll.hx

@@ -1,63 +0,0 @@
-/*
- * Copyright (C)2005-2018 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package haxe.remoting;
-
-class ContextAll extends Context {
-
-	public override function call( path : Array<String>, params : Array<Dynamic> ) : Dynamic {
-		#if neko
-		var o : Dynamic = null;
-		var m : Dynamic = neko.Lib.getClasses();
-		for( p in path ) {
-			o = m;
-			m = Reflect.field(o,p);
-		}
-		#elseif js
-		var path2 = path.copy();
-		var f = path2.pop();
-		var o;
-		try {
-			o = js.Lib.eval(path2.join("."));
-		} catch( e : Dynamic ) {
-			o = null;
-		}
-		var m = Reflect.field(o,f);
-		#elseif flash
-		var path2 = path.copy();
-		var f = path2.pop();
-		var o = flash.Lib.eval(path2.join("."));
-		var m = Reflect.field(o,f);
-		#elseif php
-		var path2 = path.copy();
-		var f = path2.pop();
-		var o = Type.resolveClass(path2.join("."));
-		var m = Reflect.field(o,f);
-		#else
-		var o = null;
-		var m = null;
-		#end
-		if( m == null )
-			return super.call(path,params);
-		return Reflect.callMethod(o,m,params);
-	}
-
-}

+ 0 - 90
std/haxe/remoting/DelayedConnection.hx

@@ -1,90 +0,0 @@
-/*
- * Copyright (C)2005-2018 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package haxe.remoting;
-
-class DelayedConnection implements AsyncConnection implements Dynamic<AsyncConnection> {
-
-	public var connection(get,set) : AsyncConnection;
-
-	var __path : Array<String>;
-	var __data : {
-		cnx : AsyncConnection,
-		error : Dynamic -> Void,
-		cache : Array<{
-			path : Array<String>,
-			params : Array<Dynamic>,
-			onResult : Dynamic -> Void,
-			onError : Dynamic -> Void
-		}>,
-	};
-
-	function new(data,path) {
-		__data = data;
-		__path = path;
-	}
-
-	public function setErrorHandler(h) {
-		__data.error = h;
-	}
-
-	public function resolve( name ) : AsyncConnection {
-		var d = new DelayedConnection(__data,__path.copy());
-		d.__path.push(name);
-		return d;
-	}
-
-	function get_connection() {
-		return __data.cnx;
-	}
-
-	function set_connection(cnx) {
-		__data.cnx = cnx;
-		process(this);
-		return cnx;
-	}
-
-	public function call( params : Array<Dynamic>, ?onResult ) {
-		__data.cache.push({ path : __path, params : params, onResult : onResult, onError : __data.error });
-		process(this);
-	}
-
-	static function process( d : DelayedConnection ) {
-		var cnx = d.__data.cnx;
-		if( cnx == null )
-			return;
-		while( true ) {
-			var m = d.__data.cache.shift();
-			if( m == null )
-				break;
-			var c = cnx;
-			for( p in m.path )
-				c = c.resolve(p);
-			c.setErrorHandler(m.onError);
-			c.call(m.params,m.onResult);
-		}
-	}
-
-	public static function create() {
-		return new DelayedConnection({ cnx : null, error : function(e) throw e, cache : new Array() },[]);
-	}
-
-}

+ 0 - 142
std/haxe/remoting/ExternalConnection.hx

@@ -1,142 +0,0 @@
-/*
- * Copyright (C)2005-2018 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package haxe.remoting;
-
-/**
-	Synchronous communications between Flash and Javascript.
-**/
-@:expose
-class ExternalConnection implements Connection implements Dynamic<Connection> {
-
-	var __data : { name : String, ctx : Context, #if js flash : String #end };
-	var __path : Array<String>;
-
-	function new( data, path ) {
-		__data = data;
-		__path = path;
-	}
-
-	public function resolve(field) : Connection {
-		var e = new ExternalConnection(__data,__path.copy());
-		e.__path.push(field);
-		return e;
-	}
-
-	public function close() {
-		connections.remove(__data.name);
-	}
-
-	#if flash
-	static function escapeString( s : String ) {
-		return s.split("\\").join("\\\\");
-	}
-	#else
-	static inline function escapeString(s:String) {
-		return s;
-	}
-	#end
-
-	public function call( params : Array<Dynamic> ) : Dynamic {
-		var s = new haxe.Serializer();
-		s.serialize(params);
-		var params = escapeString(s.toString());
-		var data = null;
-		#if flash
-			#if js_unflatten
-				data = flash.external.ExternalInterface.call("haxe.remoting.ExternalConnection.doCall",__data.name,__path.join("."),params);
-			#else
-				data = flash.external.ExternalInterface.call("haxe_remoting_ExternalConnection.doCall",__data.name,__path.join("."),params);
-			#end
-		#elseif js
-			var fobj : Dynamic = (untyped js.Browser.document)[cast __data.flash]; // FIXME(bruno): Why is this necessary?
-			if( fobj == null ) fobj = js.Browser.document.getElementById(__data.flash);
-			if( fobj == null ) throw "Could not find flash object '"+__data.flash+"'";
-			try	data = fobj.externalRemotingCall(__data.name,__path.join("."),params) catch( e : Dynamic ) {};
-		#end
-		if( data == null ) {
-			#if js
-			var domain, pageDomain;
-			try {
-				// check that swf in on the same domain
-				domain = fobj.src.split("/")[2];
-				pageDomain = js.Browser.location.host;
-			} catch( e : Dynamic ) {
-				domain = null;
-				pageDomain = null;
-			}
-			if( domain != pageDomain )
-				throw "ExternalConnection call failure : SWF need allowDomain('"+pageDomain+"')";
-			#end
-			throw "Call failure : ExternalConnection is not " + #if flash "compiled in JS" #else "initialized in Flash" #end;
-		}
-		return new haxe.Unserializer(data).unserialize();
-	}
-
-	static var connections = new haxe.ds.StringMap<ExternalConnection>();
-
-	@:keep
-	static function doCall( name : String, path : String, params : String ) : String {
-		try {
-			var cnx = connections.get(name);
-			if( cnx == null ) throw "Unknown connection : "+name;
-			if( cnx.__data.ctx == null ) throw "No context shared for the connection "+name;
-			var params = new haxe.Unserializer(params).unserialize();
-			var ret = cnx.__data.ctx.call(path.split("."),params);
-			var s = new haxe.Serializer();
-			s.serialize(ret);
-			#if flash
-			return escapeString(s.toString());
-			#else
-			return s.toString()+"#";
-			#end
-		} catch( e : Dynamic ) {
-			var s = new haxe.Serializer();
-			s.serializeException(e);
-			return s.toString();
-		}
-		#if as3
-		return "";
-		#end
-	}
-
-	#if flash
-
-	public static function jsConnect( name : String, ?ctx : Context ) {
-		if( !flash.external.ExternalInterface.available )
-			throw "External Interface not available";
-		try flash.external.ExternalInterface.addCallback("externalRemotingCall",doCall) catch( e : Dynamic ) {};
-		var cnx = new ExternalConnection({ name : name, ctx : ctx },[]);
-		connections.set(name,cnx);
-		return cnx;
-	}
-
-	#elseif js
-
-	public static function flashConnect( name : String, flashObjectID : String, ?ctx : Context ) {
-		var cnx = new ExternalConnection({ ctx : ctx, name : name, flash : flashObjectID },[]);
-		connections.set(name,cnx);
-		return cnx;
-	}
-
-	#end
-
-}

+ 0 - 156
std/haxe/remoting/FlashJsConnection.hx

@@ -1,156 +0,0 @@
-/*
- * Copyright (C)2005-2018 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package haxe.remoting;
-
-class FlashJsConnection #if flash implements AsyncConnection implements Dynamic<AsyncConnection> #end {
-
-#if flash
-
-	var __path : Array<String>;
-	var __data : {
-		id : String,
-		name : String,
-		ctx : Context,
-		error : Dynamic -> Void,
-		timer : haxe.Timer,
-		queue : Array<Void -> Void>,
-	};
-
-	function new( data, path ) {
-		__data = data;
-		__path = path;
-	}
-
-	public function close() {
-		connections.remove(__data.name);
-	}
-
-	public function resolve( name ) : AsyncConnection {
-		var c = new FlashJsConnection(__data,__path.copy());
-		c.__path.push(name);
-		return c;
-	}
-
-	public function setErrorHandler(h) {
-		__data.error = h;
-	}
-
-	public function call( params : Array<Dynamic>, ?onResult : Dynamic -> Void ) {
-		var s = new haxe.Serializer();
-		s.serialize(params);
-		var params = escapeString(s.toString());
-		var error = __data.error;
-		__data.queue.push(function() {
-			var data = flash.external.ExternalInterface.call("haxe.remoting.FlashJsConnection.flashCall",__data.id,__data.name,__path.join("."),params);
-			var v : Dynamic;
-			try {
-				if( data == null )
-					throw "Call failure : FlashJsConnection is not compiled in JS";
-				v = new haxe.Unserializer(data).unserialize();
-			} catch( e : Dynamic ) {
-				error(e);
-				return;
-			}
-			if( onResult != null )
-				onResult(v);
-		});
-		if( __data.timer == null ) {
-			__data.timer = new haxe.Timer(1);
-			__data.timer.run = function() {
-				var q = __data.queue.shift();
-				if( q == null ) {
-					__data.timer.stop();
-					__data.timer = null;
-					return;
-				}
-				q();
-			};
-		}
-	}
-
-	static var connections = new haxe.ds.StringMap<FlashJsConnection>();
-
-	static function escapeString( s : String ) {
-		#if flash
-		return s.split("\\").join("\\\\");
-		#else
-		return s.split("\\").join("\\\\").split("&").join("&amp;");
-		#end
-	}
-
-	static function doCall( name : String, path : String, params : String ) : String {
-		try {
-			var cnx = connections.get(name);
-			if( cnx == null ) throw "Unknown connection : "+name;
-			if( cnx.__data.ctx == null ) throw "No context shared for the connection "+name;
-			var params = new haxe.Unserializer(params).unserialize();
-			var ret = cnx.__data.ctx.call(path.split("."),params);
-			var s = new haxe.Serializer();
-			s.serialize(ret);
-			return escapeString(s.toString());
-		} catch( e : Dynamic ) {
-			var s = new haxe.Serializer();
-			s.serializeException(e);
-			return s.toString();
-		}
-		#if as3
-		return "";
-		#end
-	}
-
-	public static function connect( name : String, objId : String, ?ctx : Context ) {
-		if( !flash.external.ExternalInterface.available )
-			throw "External Interface not available";
-		try flash.external.ExternalInterface.addCallback("flashJsRemotingCall",doCall) catch( e : Dynamic ) {};
-		var cnx = new FlashJsConnection({
-			id : objId,
-			name : name,
-			ctx : ctx,
-			error : function(e) throw e,
-			queue : [],
-			timer : null,
-		},[]);
-		connections.set(name,cnx);
-		return cnx;
-	}
-
-#elseif js
-
-	static function flashCall( flashObj : String, name : String, path : String, params : String ) : String {
-		try {
-			var fobj : Dynamic = untyped (untyped js.Browser.document)[__data.flash]; // FIXME(bruno): Why is this necessary?
-			if( fobj == null ) fobj = js.Browser.document.getElementById(flashObj);
-			if( fobj == null ) throw "Could not find flash object '"+flashObj+"'";
-			var data = null;
-			try data = fobj.flashJsRemotingCall(name,path,params) catch( e : Dynamic ) {};
-			if( data == null ) throw "Flash object "+flashObj+" does not have an active FlashJsConnection";
-			return data;
-		} catch( e : Dynamic ) {
-			var s = new haxe.Serializer();
-			s.serializeException(e);
-			return s.toString();
-		}
-	}
-
-#end
-
-}

+ 0 - 80
std/haxe/remoting/HttpAsyncConnection.hx

@@ -1,80 +0,0 @@
-/*
- * Copyright (C)2005-2018 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package haxe.remoting;
-
-/**
-    Allows an asynchronous connection to the given URL which should link to a Haxe server application.
-*/
-class HttpAsyncConnection implements AsyncConnection implements Dynamic<AsyncConnection> {
-
-	var __data : { url : String, error : Dynamic -> Void };
-	var __path : Array<String>;
-
-	function new(data,path) {
-		__data = data;
-		__path = path;
-	}
-
-	public function resolve( name ) : AsyncConnection {
-		var c = new HttpAsyncConnection(__data,__path.copy());
-		c.__path.push(name);
-		return c;
-	}
-
-	public function setErrorHandler(h) {
-		__data.error = h;
-	}
-
-	public function call( params : Array<Dynamic>, ?onResult : Dynamic -> Void ) {
-		var h = new haxe.Http(__data.url);
-		#if (neko && no_remoting_shutdown)
-			h.noShutdown = true;
-		#end
-		var s = new haxe.Serializer();
-		s.serialize(__path);
-		s.serialize(params);
-		h.setHeader("X-Haxe-Remoting","1");
-		h.setParameter("__x",s.toString());
-		var error = __data.error;
-		h.onData = function( response : String ) {
-			var ok = true;
-			var ret;
-			try {
-				if( response.substr(0,3) != "hxr" ) throw "Invalid response : '"+response+"'";
-				var s = new haxe.Unserializer(response.substr(3));
-				ret = s.unserialize();
-			} catch( err : Dynamic ) {
-				ret = null;
-				ok = false;
-				error(err);
-			}
-			if( ok && onResult != null ) onResult(ret);
-		};
-		h.onError = error;
-		h.request(true);
-	}
-
-	public static function urlConnect( url : String ) {
-		return new HttpAsyncConnection({ url : url, error : function(e) throw e },[]);
-	}
-
-}

+ 0 - 113
std/haxe/remoting/HttpConnection.hx

@@ -1,113 +0,0 @@
-/*
- * Copyright (C)2005-2018 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package haxe.remoting;
-
-/**
-    Allows a synchronous connection to the given URL which should link to a Haxe server application.
-*/
-class HttpConnection implements Connection implements Dynamic<Connection> {
-
-	public static var TIMEOUT = 10.;
-
-	var __url : String;
-	var __path : Array<String>;
-
-	function new(url,path) {
-		__url = url;
-		__path = path;
-	}
-
-	public function resolve( name ) : Connection {
-		var c = new HttpConnection(__url,__path.copy());
-		c.__path.push(name);
-		return c;
-	}
-
-	public function call( params : Array<Dynamic> ) : Dynamic {
-		var data = null;
-		var h = new haxe.Http(__url);
-		#if (js && !nodejs)
-			h.async = false;
-		#end
-		#if (neko && no_remoting_shutdown)
-			h.noShutdown = true;
-		#end
-		#if (neko || php || cpp)
-			h.cnxTimeout = TIMEOUT;
-		#end
-		var s = new haxe.Serializer();
-		s.serialize(__path);
-		s.serialize(params);
-		h.setHeader("X-Haxe-Remoting","1");
-		h.setParameter("__x",s.toString());
-		h.onData = function(d) { data = d; };
-		h.onError = function(e) { throw e; };
-		h.request(true);
-		if( data.substr(0,3) != "hxr" )
-			throw "Invalid response : '"+data+"'";
-		data = data.substr(3);
-		return new haxe.Unserializer(data).unserialize();
-	}
-
-	#if !flash
-
-	public static function urlConnect( url : String ) {
-		return new HttpConnection(url,[]);
-	}
-
-	#end
-
-	#if neko
-	public static function handleRequest( ctx : Context ) {
-		var v = neko.Web.getParams().get("__x");
-		if( neko.Web.getClientHeader("X-Haxe-Remoting") == null || v == null )
-			return false;
-		neko.Lib.print(processRequest(v,ctx));
-		return true;
-	}
-	#elseif php
-	public static function handleRequest( ctx : Context ) {
-		var v = php.Web.getParams().get("__x");
-		if( php.Web.getClientHeader("X-Haxe-Remoting") == null || v == null )
-			return false;
-		php.Lib.print(processRequest(v,ctx));
-		return true;
-	}
-	#end
-
-	public static function processRequest( requestData : String, ctx : Context ) : String {
-		try {
-			var u = new haxe.Unserializer(requestData);
-			var path = u.unserialize();
-			var args = u.unserialize();
-			var data = ctx.call(path,args);
-			var s = new haxe.Serializer();
-			s.serialize(data);
-			return "hxr" + s.toString();
-		} catch( e : Dynamic ) {
-			var s = new haxe.Serializer();
-			s.serializeException(e);
-			return "hxr" + s.toString();
-		}
-	}
-
-}

+ 0 - 141
std/haxe/remoting/LocalConnection.hx

@@ -1,141 +0,0 @@
-/*
- * Copyright (C)2005-2018 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package haxe.remoting;
-
-/**
-    Allows communications to a different application that runs on the same client device
-*/
-class LocalConnection implements AsyncConnection implements Dynamic<AsyncConnection> {
-
-	static var ID = 0;
-
-	var __path : Array<String>;
-	var __data : {
-		ctx : Context,
-		results : haxe.ds.IntMap<{ error : Dynamic -> Void, result : Dynamic -> Void }>,
-		error : Dynamic -> Void,
-		target : String,
-		#if flash
-		cnx : flash.net.LocalConnection,
-		#else
-		cnx : Dynamic,
-		#end
-	};
-
-	function new(data,path) {
-		this.__path = path;
-		this.__data = data;
-	}
-
-	public function resolve( name ) : AsyncConnection {
-		var s = new LocalConnection(__data,__path.copy());
-		s.__path.push(name);
-		return s;
-	}
-
-	public function setErrorHandler(h) {
-		__data.error = h;
-	}
-
-	public function call( params : Array<Dynamic>, ?onResult : Dynamic -> Void ) : Void {
-		try {
-			var id = ID++;
-			#if flash
-			__data.cnx.send(__data.target,"remotingCall",id,__path.join("."),haxe.Serializer.run(params));
-			#else
-			if( !__data.cnx.send(__data.target,"remotingCall",id,__path.join("."),haxe.Serializer.run(params)) )
-				throw "Remoting call failure";
-			#end
-			__data.results.set(id,{ error : __data.error, result : onResult });
-		} catch( e : Dynamic ) {
-			__data.error(e);
-		}
-	}
-
-	public function close() {
-		__data.cnx.close();
-	}
-
-	static function remotingCall( c : LocalConnection, id : Int, path : String, args : String ) {
-		var r;
-		try {
-			if( c.__data.ctx == null ) throw "No context shared for this connection";
-			var ret = c.__data.ctx.call(path.split("."),haxe.Unserializer.run(args));
-			r = haxe.Serializer.run(ret);
-		} catch( e : Dynamic ) {
-			var s = new haxe.Serializer();
-			s.serializeException(e);
-			r = s.toString();
-		}
-		// don't forward 'send' errors on connection since it's only the receiving side
-		c.__data.cnx.send(c.__data.target,"remotingResult",id,r);
-	}
-
-	static function remotingResult( c : LocalConnection, id : Int, result : String ) {
-		var f = c.__data.results.get(id);
-		if( f == null )
-			c.__data.error("Invalid result ID "+id);
-		c.__data.results.remove(id);
-		var val : Dynamic;
-		try {
-			val = new haxe.Unserializer(result).unserialize();
-		} catch( e : Dynamic ) {
-			f.error(e);
-			return;
-		}
-		if( f.result != null )
-			f.result(val);
-	}
-
-	#if flash
-	public static function connect( name : String, ?ctx : Context, ?allowDomains : Array<String> ) {
-		var l = new flash.net.LocalConnection();
-		var recv = name + "_recv";
-		var c = new LocalConnection({
-			ctx : ctx,
-			error : function(e) throw e,
-			results : new haxe.ds.IntMap(),
-			cnx : l,
-			target : recv,
-		},[]);
-		l.client = {
-			remotingCall : remotingCall.bind(c),
-			remotingResult : remotingResult.bind(c),
-		};
-		l.addEventListener(flash.events.StatusEvent.STATUS, function(s:flash.events.StatusEvent) {
-			if( s.level != "status" )
-				c.__data.error("Failed to send data on LocalConnection");
-		});
-		try
-			l.connect(name)
-		catch( e : Dynamic ) {
-			l.connect(recv);
-			c.__data.target = name;
-		}
-		if( allowDomains != null )
-			for( d in allowDomains )
-				l.allowDomain(d);
-		return c;
-	}
-	#end
-
-}

+ 0 - 37
std/haxe/remoting/Proxy.hx

@@ -1,37 +0,0 @@
-/*
- * Copyright (C)2005-2018 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package haxe.remoting;
-
-/**
-	When you extend it with a class C, it will automatically
-	create a stub class with all public methods forwarding remoting messages over
-	the connection.
-**/
-class Proxy<T> {
-
-	var __cnx : Connection;
-
-	function new( c ) {
-		__cnx = c;
-	}
-
-}

+ 0 - 178
std/haxe/remoting/SocketConnection.hx

@@ -1,178 +0,0 @@
-/*
- * Copyright (C)2005-2018 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package haxe.remoting;
-import haxe.remoting.SocketProtocol.Socket;
-
-/**
-	Allows remoting communications over a socket connection
-*/
-class SocketConnection implements AsyncConnection implements Dynamic<AsyncConnection> {
-
-	var __path : Array<String>;
-	var __data : {
-		protocol : SocketProtocol,
-		results : List<{ onResult : Dynamic -> Void, onError : Dynamic -> Void }>,
-		log : Array<String> -> Array<Dynamic> -> Dynamic -> Void,
-		error : Dynamic -> Void,
-		#if js
-		queue : Array<Void -> Void>,
-		timer : haxe.Timer,
-		#end
-	};
-
-	function new(data,path) {
-		__data = data;
-		__path = path;
-	}
-
-	public function resolve(name) : AsyncConnection {
-		var s = new SocketConnection(__data,__path.copy());
-		s.__path.push(name);
-		return s;
-	}
-
-	public function call( params : Array<Dynamic>, ?onResult : Dynamic -> Void ) {
-		try {
-			__data.protocol.sendRequest(__path,params);
-			__data.results.add({ onResult : onResult, onError : __data.error });
-		} catch( e : Dynamic ) {
-			__data.error(e);
-		}
-	}
-
-	public function setErrorHandler(h) {
-		__data.error = h;
-	}
-
-	public function setErrorLogger(h) {
-		__data.log = h;
-	}
-
-	public function setProtocol( p : SocketProtocol ) {
-		__data.protocol = p;
-	}
-
-	public function getProtocol() : SocketProtocol {
-		return __data.protocol;
-	}
-
-	public function close() {
-		try __data.protocol.socket.close() catch( e : Dynamic ) { };
-	}
-
-	public function processMessage( data : String ) {
-		var request;
-		var proto = __data.protocol;
-		data = proto.decodeData(data);
-		try {
-			request = proto.isRequest(data);
-		} catch( e : Dynamic ) {
-			var msg = Std.string(e) + " (in "+StringTools.urlEncode(data)+")";
-			__data.error(msg); // protocol error
-			return;
-		}
-		// request
-		if( request ) {
-			try proto.processRequest(data,__data.log) catch( e : Dynamic ) __data.error(e);
-			return;
-		}
-		// answer
-		var f = __data.results.pop();
-		if( f == null ) {
-			__data.error("No response excepted ("+data+")");
-			return;
-		}
-		var ret;
-		try {
-			ret = proto.processAnswer(data);
-		} catch( e : Dynamic ) {
-			f.onError(e);
-			return;
-		}
-		if( f.onResult != null ) f.onResult(ret);
-	}
-
-	function defaultLog(path,args,e:Dynamic) {
-		// exception inside the called method
-		var astr, estr;
-		try astr = args.join(",") catch( e : Dynamic ) astr = "???";
-		try estr = Std.string(e) catch( e : Dynamic ) estr = "???";
-		var header = "Error in call to "+path.join(".")+"("+astr+") : ";
-		__data.error(header + estr);
-	}
-
-	public static function create( s : Socket, ?ctx : Context ) {
-		var data = {
-			protocol : new SocketProtocol(s,ctx),
-			results : new List(),
-			error : function(e) throw e,
-			log : null,
-			#if js
-			queue : [],
-			timer : null,
-			#end
-		};
-		var sc = new SocketConnection(data,[]);
-		data.log = sc.defaultLog;
-		#if flash
-		s.addEventListener(flash.events.DataEvent.DATA, function(e : flash.events.DataEvent) {
-			var data = e.data;
-			var msgLen = sc.__data.protocol.messageLength(data.charCodeAt(0),data.charCodeAt(1));
-			if( msgLen == null || data.length != msgLen - 1 ) {
-				sc.__data.error("Invalid message header");
-				return;
-			}
-			sc.processMessage(e.data.substr(2,e.data.length-2));
-		});
-		#elseif js
-		// we can't deliver directly the message
-		// since it might trigger a blocking action on JS side
-		// and in that case this will trigger a Flash bug
-		// where a new onData is called is a parallel thread
-		// ...with the buffer of the previous onData (!)
-		s.onData = function( data : String ) {
-			sc.__data.queue.push(function() {
-				var msgLen = sc.__data.protocol.messageLength(data.charCodeAt(0),data.charCodeAt(1));
-				if( msgLen == null || data.length != msgLen - 1 ) {
-					sc.__data.error("Invalid message header");
-					return;
-				}
-				sc.processMessage(data.substr(2,data.length-2));
-			});
-			if( sc.__data.timer == null ) {
-				sc.__data.timer = new haxe.Timer(1);
-				sc.__data.timer.run = function() {
-					var q = sc.__data.queue.shift();
-					if( q == null ) {
-						sc.__data.timer.stop();
-						sc.__data.timer = null;
-						return;
-					}
-					q();
-				};
-			}
-		};
-		#end
-		return sc;
-	}
-
-}

+ 0 - 209
std/haxe/remoting/SocketProtocol.hx

@@ -1,209 +0,0 @@
-/*
- * Copyright (C)2005-2018 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package haxe.remoting;
-
-typedef Socket =
-	#if flash
-		flash.net.XMLSocket
-	#elseif js
-		js.XMLSocket
-	#elseif sys
-		sys.net.Socket
-	#else
-		Dynamic
-	#end
-
-/**
-	The Haxe Remoting Socket Protocol is composed of serialized string exchanges.
-	Each string is prefixed with a 2-chars header encoding the string size (up to 4KB)
-	and postfixed with the `\0` message delimiting char.
-
-	A request string is composed of the following serialized values :
-
-	 - the boolean true for a request
-	 - an array of strings representing the object+method path
-	 - an array of parameters
-
-	A response string is composed of the following serialized values :
-
-	 - the boolean false for a response
-	 - a serialized value representing the result
-
-	Exceptions are serialized with `serializeException` so they will be thrown immediately
-	when they are unserialized.
-**/
-class SocketProtocol {
-
-	public var socket : Socket;
-	public var context : Context;
-
-	public function new( sock, ctx ) {
-		this.socket = sock;
-		this.context = ctx;
-	}
-
-	function decodeChar(c) : Null<Int> {
-		// A...Z
-		if( c >= 65 && c <= 90 )
-			return c - 65;
-		// a...z
-		if( c >= 97 && c <= 122 )
-			return c - 97 + 26;
-		// 0...9
-		if( c >= 48 && c <= 57 )
-			return c - 48 + 52;
-		// +
-		if( c == 43 )
-			return 62;
-		// /
-		if( c == 47 )
-			return 63;
-		return null;
-	}
-
-	function encodeChar(c) : Null<Int> {
-		if( c < 0 )
-			return null;
-		// A...Z
-		if( c < 26 )
-			return c + 65;
-		// a...z
-		if( c < 52 )
-			return (c - 26) + 97;
-		// 0...9
-		if( c < 62 )
-			return (c - 52) + 48;
-		// +
-		if( c == 62 )
-			return 43;
-		// /
-		if( c == 63 )
-			return 47;
-		return null;
-	}
-
-	public function messageLength( c1 : Int, c2 : Int ) : Null<Int> {
-		var e1 = decodeChar(c1);
-		var e2 = decodeChar(c2);
-		if( e1 == null || e2 == null )
-			return null;
-		return (e1 << 6) | e2;
-	}
-
-	public function encodeMessageLength( len : Int ) {
-		var c1 = encodeChar(len>>6);
-		if( c1 == null )
-			throw "Message is too big";
-		var c2 = encodeChar(len&63);
-		return { c1 : c1, c2 : c2 };
-	}
-
-	public function sendRequest( path : Array<String>, params : Array<Dynamic> ) {
-		var s = new haxe.Serializer();
-		s.serialize(true);
-		s.serialize(path);
-		s.serialize(params);
-		sendMessage(s.toString());
-	}
-
-	public function sendAnswer( answer : Dynamic, ?isException : Bool ) {
-		var s = new haxe.Serializer();
-		s.serialize(false);
-		if( isException )
-			s.serializeException(answer);
-		else
-			s.serialize(answer);
-		sendMessage(s.toString());
-	}
-
-	public function sendMessage( msg : String ) {
-		var e = encodeMessageLength(msg.length + 3);
-		#if sys
-		var o = socket.output;
-		o.writeByte(e.c1);
-		o.writeByte(e.c2);
-		o.writeString(msg);
-		o.writeByte(0);
-		#else
-		socket.send(String.fromCharCode(e.c1)+String.fromCharCode(e.c2)+msg);
-		#end
-	}
-
-	public dynamic function decodeData( data : String ) {
-		return data;
-	}
-
-	public function isRequest( data : String ) {
-		return switch( haxe.Unserializer.run(data) ) {
-		case true: true;
-		case false: false;
-		default: throw "Invalid data";
-		}
-	}
-
-	public function processRequest( data : String, ?onError : Array<String> -> Array<Dynamic> -> Dynamic -> Void ) {
-		var s = new haxe.Unserializer(data);
-		var result : Dynamic;
-		var isException = false;
-		if( s.unserialize() != true )
-			throw "Not a request";
-		var path : Array<String> = s.unserialize();
-		var args : Array<Dynamic> = s.unserialize();
-		try {
-			if( context == null ) throw "No context is shared";
-			result = context.call(path,args);
-		} catch( e : Dynamic ) {
-			result = e;
-			isException = true;
-		}
-		// send back result/exception over network
-		sendAnswer(result,isException);
-		// send the error event
-		if( isException && onError != null )
-			onError(path,args,result);
-	}
-
-	public function processAnswer( data : String ) : Dynamic {
-		var s = new haxe.Unserializer(data);
-		if( s.unserialize() != false )
-			throw "Not an answer";
-		return s.unserialize();
-	}
-
-	#if sys
-
-	public function readMessage() {
-		var i = socket.input;
-		var c1 = i.readByte();
-		var c2 = i.readByte();
-		var len = messageLength(c1,c2);
-		if( len == null )
-			throw "Invalid header";
-		var data = i.readString(len - 3);
-		if( i.readByte() != 0 )
-			throw "Invalid message";
-		return decodeData(data);
-	}
-
-	#end
-
-}

+ 0 - 75
std/haxe/remoting/SocketWrapper.hx

@@ -1,75 +0,0 @@
-/*
- * Copyright (C)2005-2018 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package haxe.remoting;
-import haxe.remoting.SocketProtocol.Socket;
-
-/**
-	@see `js.XMLSocket`
-**/
-class SocketWrapper {
-
-	static var ID = 0;
-
-	static function create( prefix : String ) : String {
-		var id = prefix + "WrappedSocket"+(ID++);
-		var s = new Socket();
-		var ctx = new Context();
-		var cnx = haxe.remoting.ExternalConnection.jsConnect(id,ctx);
-		ctx.addObject("sock",s);
-		var o = {};
-		Reflect.setField(o,"close",cnx.close);
-		ctx.addObject("api",o);
-		#if flash
-		var connected = false;
-		s.addEventListener(flash.events.Event.CONNECT,function(_) {
-			connected = true;
-			cnx.api.onConnect.call([true]);
-		});
-		s.addEventListener(flash.events.SecurityErrorEvent.SECURITY_ERROR,function(_) {
-			if( connected )
-				cnx.api.onClose.call([]);
-			else
-				cnx.api.onConnect.call([false]);
-		});
-		s.addEventListener(flash.events.Event.CLOSE,function(_) {
-			cnx.api.onClose.call([]);
-		});
-		s.addEventListener(flash.events.DataEvent.DATA,function(e:flash.events.DataEvent) {
-			cnx.api.onData.call([e.data]);
-		});
-		#end
-		return id;
-	}
-
-	static function init() {
-		if( !flash.external.ExternalInterface.available ) return null;
-		var ctx = new Context();
-		var o = {};
-		Reflect.setField(o,"create",create);
-		ctx.addObject("api",o);
-		haxe.remoting.ExternalConnection.jsConnect("SocketWrapper", ctx);
-		return null;
-	}
-
-	static var _ = init();
-
-}

+ 0 - 82
std/haxe/remoting/SyncSocketConnection.hx

@@ -1,82 +0,0 @@
-/*
- * Copyright (C)2005-2018 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package haxe.remoting;
-import haxe.remoting.SocketProtocol.Socket;
-
-class SyncSocketConnection implements Connection implements Dynamic<Connection> {
-
-	var __path : Array<String>;
-	var __proto : SocketProtocol;
-
-	function new(proto,path) {
-		__proto = proto;
-		__path = path;
-	}
-
-	public function resolve( name ) : Connection {
-		var s = new SyncSocketConnection(__proto,__path.copy());
-		s.__path.push(name);
-		return s;
-	}
-
-	public function call( params : Array<Dynamic> ) : Dynamic {
-		var proto = __proto;
-		proto.sendRequest(__path,params);
-		while( true ) {
-			var data = proto.readMessage();
-			if( proto.isRequest(data) ) {
-				if( proto.context == null )
-					throw "Request received";
-				proto.processRequest(data,onRequestError);
-				continue;
-			}
-			return proto.processAnswer(data);
-		}
-	}
-
-	public function processRequest() {
-		if( __proto.context == null )
-			throw "Can't process request";
-		var data = __proto.readMessage();
-		__proto.processRequest(data,onRequestError);
-	}
-
-	public function onRequestError( path : Array<String>, args : Array<Dynamic>, exc : Dynamic ) {
-	}
-
-	public function setProtocol( p : SocketProtocol ) {
-		__proto = p;
-	}
-
-	public function getProtocol() : SocketProtocol {
-		return __proto;
-	}
-
-	public function close() {
-		try __proto.socket.close() catch( e : Dynamic ) { };
-	}
-
-	public static function create( s : Socket, ?ctx : Context ) {
-		return new SyncSocketConnection(new SocketProtocol(s,ctx),[]);
-	}
-
-}