Skip to content
Browse files

using haxelib nodejs type definitions

  • Loading branch information...
1 parent 5848e49 commit 02bb8a5b5149067a813fa80cb0a12f511f263ce5 @tong committed
Showing with 29 additions and 15 deletions.
  1. +11 −8 jabber/SocketConnection.hx
  2. +1 −1 jabber/Stream.hx
  3. +7 −1 jabber/XMPPDebug.hx
  4. +5 −4 jabber/util/Base64.hx
  5. +5 −1 jabber/util/MD5.hx
View
19 jabber/SocketConnection.hx
@@ -389,12 +389,12 @@ class SocketConnection extends jabber.stream.SocketConnectionBase {
import js.Node;
-private typedef Socket = js.Stream;
+private typedef Socket = js.NodeNetSocket;
class SocketConnection extends jabber.stream.SocketConnectionBase {
public var socket(default,null) : Socket;
- public var credentials : Credentials;
+ public var credentials : NodeCredDetails;
var cleartext : Dynamic;
@@ -406,9 +406,10 @@ class SocketConnection extends jabber.stream.SocketConnectionBase {
public override function connect() {
createConnection();
- socket.on( Node.STREAM_END, sockDisconnectHandler );
- socket.on( Node.STREAM_ERROR, sockErrorHandler );
- socket.on( Node.STREAM_DATA, sockDataHandler );
+
+ socket.on( NodeC.EVENT_STREAM_END, sockDisconnectHandler );
+ socket.on( NodeC.EVENT_STREAM_ERROR, sockErrorHandler );
+ socket.on( NodeC.EVENT_STREAM_DATA, sockDataHandler );
}
public override function disconnect() {
@@ -460,15 +461,17 @@ class SocketConnection extends jabber.stream.SocketConnectionBase {
public override function read( ?yes : Bool = true ) : Bool {
if( !yes )
- socket.removeListener( Node.STREAM_DATA, sockDataHandler );
+ socket.removeListener( NodeC.EVENT_STREAM_DATA, sockDataHandler );
return true;
}
function createConnection() {
//if( credentials == null ) credentials = cast {};
//socket = Node.tls.connect( port, host, credentials, sockConnectHandler );
- socket = Node.net.connect( port, host, sockConnectHandler );
- socket.setEncoding( Node.UTF8 );
+ //socket = Node.net.connect( port, host, sockConnectHandler );
+ socket = Node.net.connect( port, host );
+ socket.setEncoding( NodeC.UTF8 );
+ socket.on( NodeC.EVENT_STREAM_CONNECT, sockConnectHandler );
/*
socket = Node.net.createConnection( port, host );
socket.setEncoding( Node.UTF8 );
View
2 jabber/Stream.hx
@@ -188,7 +188,7 @@ class Stream {
if( !cnx.connected )
return null;
if( intercept )
- interceptPacket( p );
+ interceptPacket( #if (java||cs) untyped #end p );
return ( sendData( untyped p.toString() ) != null ) ? p : null;
}
View
8 jabber/XMPPDebug.hx
@@ -23,6 +23,8 @@ package jabber;
#if (flash&&!air)
import flash.external.ExternalInterface;
+#elseif nodejs
+import js.Node;
#elseif rhino
import js.Lib;
#end
@@ -117,7 +119,9 @@ class XMPPDebug {
untyped __global__['trace']( t );
#elseif (air&&js)
untyped air.trace(t);
- #else
+ #elseif nodejs
+ Node.console.log( t );
+ #elseif
Sys.print( t );
#end
return;
@@ -137,6 +141,8 @@ class XMPPDebug {
#else
untyped air.trace( b.toString() );
#end
+ #elseif nodejs
+ Node.console.log( b.toString() );
#else
Sys.print( b.toString() );
#end
View
9 jabber/util/Base64.hx
@@ -69,7 +69,7 @@ class Base64 {
//#end
#if nodejs
- return new Buffer(s).toString( Node.BASE64 );
+ return new NodeBuffer(s).toString( NodeC.BASE64 );
//return new Buffer( s, Node.BASE64 ).toString( Node.UTF8 );
#elseif php
@@ -93,7 +93,7 @@ class Base64 {
public static inline function decode( s : String ) : String {
#if nodejs
- return new Buffer( s, Node.BASE64 ).toString( Node.ASCII );
+ return new NodeBuffer( s, NodeC.BASE64 ).toString( NodeC.ASCII );
#elseif php
return untyped __call__( "base64_decode", s );
#else
@@ -113,7 +113,8 @@ class Base64 {
#if php
return untyped __call__( "base64_encode", b.getData() );
#elseif nodejs
- return b.getData().toString( Node.BASE64 );
+ return new NodeBuffer( b.getData().toString(), NodeC.BASE64 ).toString( NodeC.ASCII );
+ //return b.getData().toString( NodeC.BASE64 );
#else
return fillNullbits( bc.encodeBytes( b ).toString() );
#end
@@ -123,7 +124,7 @@ class Base64 {
#if php
return Bytes.ofString( untyped __call__( "base64_decode", s ) );
#elseif nodejs
- return Bytes.ofData( new Buffer( s, Node.BASE64 ) );
+ return Bytes.ofString( new NodeBuffer( s ).toString( NodeC.BASE64 ) );
#else
return bc.decodeBytes( Bytes.ofString( removeNullbits( s ) ) );
#end
View
6 jabber/util/MD5.hx
@@ -21,6 +21,10 @@
*/
package jabber.util;
+#if nodejs
+import js.Node;
+#end
+
/**
Creates a MD5 of a String.
Modified version from the haXe std lib to provide raw encoding.
@@ -40,7 +44,7 @@ class MD5 {
#elseif nodejs
var h = js.Node.crypto.createHash( "md5" );
h.update( s );
- return h.digest( raw ? js.Node.BINARY : js.Node.HEX );
+ return h.digest( raw ? NodeC.BINARY : NodeC.HEX );
#elseif php
return untyped __call__( "md5", s, raw );

0 comments on commit 02bb8a5

Please sign in to comment.
Something went wrong with that request. Please try again.