Permalink
Browse files

Allow Channels to be https, this amounts to providing

the http endpoint to the session client start() function,
and starting the server with credentials.

see the usage/chat for more details.
  • Loading branch information...
cloudshift committed Jun 5, 2012
1 parent 32c2675 commit f3a6c897de97baffc371edfc38961d3ff7442a5d
View
@@ -81,7 +81,7 @@ enum ChannelClientError {
interface ChannelClient
implements ChannelProvider,
- implements Part<String,ChannelClientError,ChannelClient,ESession> {
+ implements Part<SessionClient,ChannelClientError,ChannelClient,ESession> {
// function unsub(chan:Chan<Dynamic>):Void;
function channel<T>(id:String):Outcome<String,Chan<T>>;
View
@@ -31,7 +31,9 @@ interface SessionMgr implements Part<HttpServer,String,SessionMgr,ESessionOp> {
#elseif CS_BROWSER
-interface SessionClient implements Part<Dynamic,String,SessionClient,ESession> {
+typedef SessionStart = {endPoint:String};
+
+interface SessionClient implements Part<SessionStart,String,SessionClient,ESession> {
/**
ErrMsg on Left
SessionID on Right
@@ -40,6 +42,7 @@ interface SessionClient implements Part<Dynamic,String,SessionClient,ESession> {
function logout():Outcome<String,String>;
function signup(pkt:Dynamic):Outcome<String,String>;
function sessID():String;
+ function endPoint():String;
}
#end
@@ -27,8 +27,7 @@ interface ConduitSession {
}
typedef ConduitClientStart = {
- var host:String;
- var port:Int;
+ var endPoint:String;
var sessID:String;
}
@@ -15,7 +15,7 @@ class PushClientImpl implements Conduit {
var _port:Int;
var _url:String;
var _parted:Bool;
-
+
public function new() {
part_ = Core.part(this);
}
@@ -24,9 +24,12 @@ class PushClientImpl implements Conduit {
if (oc == null)
oc = Core.outcome();
- _url = "http://"+js.Lib.window.location.host;
-
+ _url = cs.endPoint;
_sessID = cs.sessID;
+
+
+ trace("client endPoint:"+_url);
+
_parted = false;
remoteInit(function(ignore) {
@@ -13,9 +13,9 @@ import cloudshift.channel.Flow;
using cloudshift.Mixin;
class TChannelClient implements ChannelClient,
- implements Part<String,ChannelClientError,ChannelClient,ESession> {
+ implements Part<SessionClient,ChannelClientError,ChannelClient,ESession> {
- public var part_:Part_<String,ChannelClientError,ChannelClient,ESession>;
+ public var part_:Part_<SessionClient,ChannelClientError,ChannelClient,ESession>;
var _sink:Sink;
var _host:String;
var _port:Int;
@@ -26,12 +26,13 @@ class TChannelClient implements ChannelClient,
}
public function
- start_(sessID:String,?oc:Outcome<ChannelClientError,ChannelClient>) {
+ start_(session:SessionClient,?oc:Outcome<ChannelClientError,ChannelClient>) {
if (oc == null)
oc = Core.outcome();
+ var sessID = session.sessID();
trace("init conduit with sessID:"+sessID);
- Flow.pushConduit().start({host:"localhost",port:8082,sessID:sessID})
+ Flow.pushConduit().start({endPoint:session.endPoint(),sessID:sessID})
.oflatMap(function(conduit) {
trace("--> setting sink with "+sessID+" new conduit ="+conduit);
return Flow.sink().start(conduit);
@@ -7,22 +7,29 @@ using cloudshift.Mixin;
private class SessionProxy extends haxe.remoting.AsyncProxy<cloudshift.session.SessionMgrProxy> { }
-class SessionClientImpl implements Part<Dynamic,String,SessionClient,ESession>,implements SessionClient {
+class SessionClientImpl implements Part<SessionStart,String,SessionClient,ESession>,implements SessionClient {
var _sessID:String;
var _proxy:SessionProxy;
var _stash:Hash<Dynamic>;
+ var _endPoint:String;
- public var part_:Part_<Dynamic,String,SessionClient,ESession>;
+ public var part_:Part_<SessionStart,String,SessionClient,ESession>;
public function new() {
part_ = Core.part(this);
}
public function
- start_(d:Dynamic,?oc:Outcome<String,SessionClient>) {
+ start_(d:SessionStart,?oc:Outcome<String,SessionClient>) {
if (oc == null)
oc = Core.outcome();
- var cnx = haxe.remoting.HttpAsyncConnection.urlConnect("http://"+js.Lib.window.location.host+Session.REMOTE);
+
+ if (d.endPoint == null)
+ Core.error("Session must be started with an endPoint (url)");
+
+ _endPoint = d.endPoint;
+
+ var cnx = haxe.remoting.HttpAsyncConnection.urlConnect(_endPoint + Session.REMOTE);
cnx.setErrorHandler( function(err) trace("Error : "+Std.string(err)) );
_proxy = new SessionProxy(cnx.Auth);
oc.resolve(Right(cast this));
@@ -72,5 +79,5 @@ class SessionClientImpl implements Part<Dynamic,String,SessionClient,ESession>,i
}
public function sessID() { return _sessID; }
-
+ public function endPoint() { return _endPoint ; }
}
View
@@ -22,11 +22,11 @@ class ChatClient {
}
function login(nick:String) {
- Session.client().start({}).outcome(function(sess) {
+ Session.client().start({endPoint:"https://"+js.Lib.window.location.host}).outcome(function(sess) {
_session = sess;
sess.login({nick:nick}).outcome(function(sessID) {
Channel.client()
- .start(sessID)
+ .start(_session)
.outcome(function(client) {
_chanClient = client;
startRoom(nick,client);
View
@@ -22,7 +22,10 @@ class ChatServer {
public function new() {
Core.init();
- Http.server().root("www").start({host:"localhost",port:8082})
+ Http.server()
+ .root("www")
+ .credentials("privatekey.pem","certificate.pem")
+ .start({host:"localhost",port:8082})
.outcome(function(http) {
Session.manager().start(http)
.outcome(function(sess:SessionMgr) {
View
@@ -22,6 +22,9 @@ class Client {
p.echo("woot",function(s) {
trace("client return:"+s);
});
+
+
+
}
View
@@ -1,4 +1,8 @@
+/*
+ hxc: -D nodejs
+*/
+
package ;
#if nodejs

0 comments on commit f3a6c89

Please sign in to comment.