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.
Thanks
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 :)