bidirectional messaging (websocket-socket)

261 views
Skip to first unread message

tiberius.alex...@gmail.com

unread,
Sep 9, 2013, 10:03:09 AM9/9/13
to action...@googlegroups.com
Hi,

I try to send/receive messages form/to websocket client -> socket client.
For my websocket client, I don't use actionHeroWebSocket.js, my application is written in angularjs and I use a simple angular-faye client (https://github.com/teamon/angular-faye);

My goal is to join both websocket client and socket client in same chat room and use "say" verb to exchange data between them.

For sockets, I tested using telnet:

telnet localhost 5000
roomChange test
roomView

For angular:
Faye.publish("/test", { msg: "hello" });
Faye.subscribe("/test", function(msg) {
console.log(msg);
});
Faye.publish('/test', {event: 'roomChange', room: 'test'});

When I execute: roomView in socket server ... just 1 client connected in there.

tiberius.alex...@gmail.com

unread,
Sep 9, 2013, 10:27:41 AM9/9/13
to action...@googlegroups.com, tiberius.alex...@gmail.com
after reading websocket.js server from actionHero I changed to Faye.publish('/test',{'event' : "roomChange", 'data' : "defaultRoom"});
But I still don't get anything

tiberius.alex...@gmail.com

unread,
Sep 9, 2013, 11:25:01 AM9/9/13
to action...@googlegroups.com, tiberius.alex...@gmail.com
Nwm. I tested with actionHeroWebSocket.js and is working, I will convert this to angularjs module.

Thanks

Evan Tahler

unread,
Sep 9, 2013, 12:35:12 PM9/9/13
to action...@googlegroups.com, tiberius.alex...@gmail.com
Awesome!   I'll bet other folks on this list might like to see how you do the implementation of you are OK to share it.  

A note on the internals of what actionHero does with faye:  

Some channels are "reserved" for server-to-server communication (any channel that starts with "/actionHero" like this or this).  This how actionHero coordinates between nodes.  Clients are restricted to a channel by their ID, and actionHero's internal chat mechanism should be used to chat so we can handle messaging between faye and the telnet clients. 

Because of this channel reservation, we explicitly block all subscriptions which involve wildcards

tiberius.alex...@gmail.com

unread,
Sep 9, 2013, 3:41:54 PM9/9/13
to action...@googlegroups.com, tiberius.alex...@gmail.com
I started to work on this lib and realised that I can use angular's register an existing value as a service trough value().

1. Load angular js
2. Load actionHeroWebSocket.js
3. Angular app
var app = angular.module('myApp', []);
app.value('actionherows',actionHeroWebSocket);

4. Angular controller
var ahero = new actionherows;
ahero.log = function(message){
$scope.data = message;
console.log(message);
}
ahero.events = {
disconnect: function(message){
ahero.log("DISCONNECTED");
},
reconnect: function(message){
ahero.log("RECONNECTED");
ahero.log("New ID: " + A.id);
},
say: function(message){
ahero.log("SAY:");
ahero.log(message)
},
welcome: function(message){
ahero.log("WELCOME:");
ahero.log(message);
},
alert: function(message){
ahero.log("ALERT:");
ahero.log(message);
}
}

ahero.connect(function(err, details){
if(err != null){
ahero.log(err);
}else{
ahero.log("CONNECTED");
ahero.log(details);
}
});

and is working without any new lib :)

Reply all
Reply to author
Forward
0 new messages