HydraP2P is a library aiming to simplify the peer-to-peer API introduced in Flash Player 10.1. It is able to handle connections to the Cirrus service and is channel based, which means it splits up peer-to-peer communication into different channels, rather than filtering in a single one.
HydraP2P has a typed command system, so there is no parsing of objects or arrays outside of the API. The user tracking-system provides information about all connected users on a per channel level.
Sample
var stratusServiceUrl : String = "rtmfp://stratus.rtmfp.net/YOUR-API_KEY";
_hydraService = new HydraService("HydraChatExample", stratusServiceUrl);
_hydraService.addEventListener(HydraEvent.SERVICE_CONNECT_SUCCESS, serviceEvent);
_hydraService.addEventListener(HydraEvent.SERVICE_CONNECT_FAILED, serviceEvent);
_hydraService.addEventListener(HydraEvent.SERVICE_CONNECT_REJECTED, serviceEvent);
_chatChannel = new HydraChatChannel(_hydraService, "HydraChatExample/ChatChannel");
_chatChannel.addEventListener(HydraUserEvent.USER_CONNECT, userEvent);
_chatChannel.addEventListener(HydraUserEvent.USER_DISCONNECT, userEvent);
_chatChannel.addEventListener(HydraChatEvent.MESSAGE_RECEIVED, messageEvent);
_chatChannel.addEventListener(HydraChatEvent.MESSAGE_SENT, messageEvent);
_hydraService.connect(_loginBox.username);
private function serviceEvent(event : HydraEvent) : void
{
switch( event.type )
{
case HydraEvent.SERVICE_CONNECT_SUCCESS:
_statusBox.text = "Connected as " + _hydraService.user.name;
_chatWindow.visible = true;
break;
case HydraEvent.SERVICE_CONNECT_FAILED:
_statusBox.text = "Connection failed.";
break;
case HydraEvent.SERVICE_CONNECT_REJECTED:
_statusBox.text = "Connection rejected.";
break;
}
}
private function messageEvent(event : HydraChatEvent) : void
{
_chatWindow.addMessage(event.sender.name, event.message);
}
private function userEvent(event : HydraUserEvent) : void
{
_chatWindow.updateUsers(_chatChannel.userTracker.users);
}
private function sendMessage(e:Event) : void
{
if( _chatWindow.messageInput.length > 0 )
{
_chatChannel.sendChatMessage(_chatWindow.messageInput);
_chatWindow.clearMessageInput();
}
}






RT @as3gamegears http://t.co/h5v9JaoF #as3 #flash #gamedev: New: HydraP2P (lib aiming to simplify the Flash pee… http://t.co/ZtqCYBep