├── .gitignore ├── buildfile └── src └── main └── as3 └── org └── devboy ├── examples └── ui │ ├── ChatWindow.as │ ├── LoginBox.as │ └── TextBox.as ├── hydra ├── HydraChannel.as ├── HydraEvent.as ├── HydraService.as ├── chat │ ├── ChatMessageCommand.as │ ├── ChatMessageCommandCreator.as │ ├── HydraChatChannel.as │ └── HydraChatEvent.as ├── commands │ ├── HydraCommand.as │ ├── HydraCommandEvent.as │ ├── HydraCommandFactory.as │ ├── IHydraCommand.as │ ├── IHydraCommandCreator.as │ ├── PingCommand.as │ └── PingCommandCreator.as ├── examples │ ├── chat │ │ └── ChatExample.as │ ├── clickcommand │ │ ├── ClickCommand.as │ │ ├── ClickCommandCreator.as │ │ └── ClickCommandExample.as │ └── videostream │ │ ├── PublishStreamCommand.as │ │ ├── PublishStreamCommandCreator.as │ │ └── VideoStreamExample.as └── users │ ├── HydraUser.as │ ├── HydraUserEvent.as │ ├── HydraUserTracker.as │ ├── NetGroupNeighbor.as │ └── NetGroupNeighborEvent.as └── toolkit └── net └── NetStatusCodes.as /.gitignore: -------------------------------------------------------------------------------- 1 | build.yaml 2 | HydraP2P.iml 3 | target 4 | .idea -------------------------------------------------------------------------------- /buildfile: -------------------------------------------------------------------------------- 1 | require "buildr/as3" 2 | 3 | repositories.remote << "http://artifacts.devboy.org" << "http://repo2.maven.org/maven2" 4 | 5 | THIS_VERSION = "0.1.1-SNAPSHOT" 6 | 7 | 8 | desc "HydraP2P" 9 | define "HydraP2P" do 10 | project.group = "org.devboy" 11 | project.version = THIS_VERSION 12 | compile.using :compc 13 | compile.options[:flexsdk] = FlexSDK.new("4.1.0.16076") 14 | compile.options[:other] = [] 15 | compile.options[:other] << "-static-link-runtime-shared-libraries=true" 16 | compile.options[:other] << "-compiler.incremental=true" 17 | compile.options[:other] << "-target-player=10.1" 18 | package :swc 19 | end -------------------------------------------------------------------------------- /src/main/as3/org/devboy/examples/ui/ChatWindow.as: -------------------------------------------------------------------------------- 1 | package org.devboy.examples.ui 2 | { 3 | import org.devboy.hydra.users.HydraUser; 4 | import flash.events.Event; 5 | import flash.display.Sprite; 6 | import flash.events.MouseEvent; 7 | import flash.text.TextFieldType; 8 | 9 | /** 10 | * @author Dominic Graefen - devboy.org 11 | */ 12 | public class ChatWindow extends Sprite 13 | { 14 | private var _messages : TextBox; 15 | private var _input : TextBox; 16 | private var _button : TextBox; 17 | private var _users : TextBox; 18 | 19 | public function ChatWindow() 20 | { 21 | init(); 22 | } 23 | 24 | private function init() : void 25 | { 26 | 27 | _messages = new TextBox(200, 250, true, true); 28 | addChild(_messages); 29 | _input = new TextBox(200, 20, false, true); 30 | _input.textFieldType = TextFieldType.INPUT; 31 | _input.y = 255; 32 | addChild(_input); 33 | _users = new TextBox(100, 250, true, false); 34 | _users.x = 205; 35 | addChild(_users); 36 | _button = new TextBox(100, 20, false, false, true); 37 | _button.x = 205; 38 | _button.y = 255; 39 | _button.text = "send"; 40 | _button.addEventListener(MouseEvent.CLICK, buttonClick); 41 | addChild(_button); 42 | } 43 | 44 | public function updateUsers( users : Vector. ) : void 45 | { 46 | _users.text = "Users (" + users.length + "):\n"; 47 | var user : HydraUser; 48 | for each( user in users ) 49 | _users.text += user.name + "\n"; 50 | } 51 | 52 | private function buttonClick(event : MouseEvent) : void 53 | { 54 | dispatchEvent( new Event("sendMessage") ); 55 | } 56 | 57 | public function addMessage( username: String, message : String ) : void 58 | { 59 | _messages.text += username + ": " + message+"\n"; 60 | } 61 | 62 | public function get messageInput() : String 63 | { 64 | return _input.text; 65 | } 66 | 67 | public function clearMessageInput() : void 68 | { 69 | _input.text = ""; 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/as3/org/devboy/examples/ui/LoginBox.as: -------------------------------------------------------------------------------- 1 | package org.devboy.examples.ui 2 | { 3 | import flash.events.Event; 4 | import flash.events.MouseEvent; 5 | import flash.text.TextFieldType; 6 | import flash.display.Sprite; 7 | 8 | /** 9 | * @author Dominic Graefen - devboy.org 10 | */ 11 | public class LoginBox extends Sprite 12 | { 13 | private var _label : TextBox; 14 | private var _input : TextBox; 15 | private var _button : TextBox; 16 | 17 | public function LoginBox() 18 | { 19 | init(); 20 | } 21 | 22 | private function init() : void 23 | { 24 | graphics.beginFill(0xEEEEEE); 25 | graphics.drawRect(0,0, 210, 60); 26 | graphics.endFill(); 27 | _label = new TextBox(200, 20, false, false); 28 | _label.text = "Choose username:"; 29 | _label.border = false; 30 | addChild(_label); 31 | _input = new TextBox(100, 20, false, true); 32 | _input.textFieldType = TextFieldType.INPUT; 33 | _input.y = 25; 34 | addChild(_input); 35 | _button = new TextBox(100, 20, false, false, true); 36 | _button.x = 105; 37 | _button.y = 25; 38 | _button.text = "Connect!"; 39 | _button.addEventListener(MouseEvent.CLICK, buttonClick); 40 | // _button.buttonMode = true; 41 | addChild(_button); 42 | } 43 | 44 | private function buttonClick(event : MouseEvent) : void 45 | { 46 | dispatchEvent(new Event("loginClick")); 47 | } 48 | 49 | public function get username() : String 50 | { 51 | return _input.text; 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/as3/org/devboy/examples/ui/TextBox.as: -------------------------------------------------------------------------------- 1 | package 2 | org.devboy.examples.ui{ 3 | import flash.text.TextFormat; 4 | import flash.text.TextField; 5 | import flash.display.Sprite; 6 | 7 | /** 8 | * @author Dominic Graefen - devboy.org 9 | */ 10 | public class TextBox extends Sprite 11 | { 12 | private var _width : Number; 13 | private var _height : Number; 14 | private var _multiline : Boolean; 15 | private var _text : TextField; 16 | private var _selectable : Boolean; 17 | 18 | public function TextBox(width : Number, height : Number, multiline : Boolean, selectable : Boolean, buttonMode : Boolean = false ) 19 | { 20 | _selectable = selectable; 21 | _multiline = multiline; 22 | _height = height; 23 | _width = width; 24 | init(); 25 | mouseChildren = !buttonMode; 26 | buttonMode = buttonMode; 27 | } 28 | 29 | private function init() : void 30 | { 31 | _text = new TextField(); 32 | _text.width = _width; 33 | _text.height = _height; 34 | _text.selectable = _selectable; 35 | _text.multiline = _multiline; 36 | _text.wordWrap = _multiline; 37 | _text.defaultTextFormat = new TextFormat("_sans", 14, 0); 38 | _text.backgroundColor = 0xDDDDDD; _text.background = true; 39 | _text.border = true; 40 | _text.borderColor = 0; 41 | addChild(_text); 42 | } 43 | 44 | public function set border( border : Boolean ) : void 45 | { 46 | _text.border = border; 47 | } 48 | 49 | public function set text( text : String ) : void 50 | { 51 | _text.text = text; 52 | } 53 | 54 | public function get text() : String 55 | { 56 | return _text.text; 57 | } 58 | 59 | public function set textFieldType( type : String ) : void 60 | { 61 | _text.type = type; 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/as3/org/devboy/hydra/HydraChannel.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 (c) Dominic Graefen, devboy.org. 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, 8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the 10 | * Software is furnished to do so, subject to the following 11 | * conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | * OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | package org.devboy.hydra 26 | { 27 | import org.devboy.hydra.users.HydraUserEvent; 28 | import org.devboy.hydra.users.HydraUserTracker; 29 | import org.devboy.hydra.commands.HydraCommandEvent; 30 | import org.devboy.hydra.commands.IHydraCommand; 31 | import org.devboy.hydra.users.NetGroupNeighbor; 32 | import org.devboy.hydra.users.NetGroupNeighborEvent; 33 | import org.devboy.toolkit.net.NetStatusCodes; 34 | 35 | import flash.events.EventDispatcher; 36 | import flash.events.NetStatusEvent; 37 | import flash.net.GroupSpecifier; 38 | import flash.net.NetGroup; 39 | 40 | /** 41 | * Dispatched when the HydraChannel connects 42 | * successfully to the service string. 43 | * 44 | * This event is dispatched only when the 45 | * hydra service trys to connect to the service url. 46 | * 47 | * @eventType org.devboy.hydra.HydraEvent.CHANNEL_CONNECT_SUCCESS 48 | */ 49 | [Event(name="channelConnectSuccess", type="org.devboy.hydra.HydraEvent")] 50 | 51 | /** 52 | * Dispatched when the HydraChannel connection 53 | * has failed. 54 | * 55 | * This event is dispatched only when the 56 | * hydra service trys to connect to the service url. 57 | * 58 | * @eventType org.devboy.hydra.HydraEvent.CHANNEL_CONNECT_FAILED 59 | */ 60 | [Event(name="channelConnectFailed", type="org.devboy.hydra.HydraEvent")] 61 | 62 | /** 63 | * Dispatched when the HydraChannel connection 64 | * is rejected. 65 | * 66 | * @eventType org.devboy.hydra.HydraEvent.CHANNEL_CONNECT_REJECTED 67 | */ 68 | [Event(name="channelConnectRejected", type="org.devboy.hydra.HydraEvent")] 69 | 70 | /** 71 | * Dispatched when the HydraChannel sends a message. 72 | * 73 | * @eventType org.devboy.hydra.commands.HydraCommandEvent.COMMAND_SENT 74 | */ 75 | [Event(name="commandSent", type="org.devboy.hydra.commands.HydraCommandEvent")] 76 | 77 | /** 78 | * Dispatched when the HydraChannel sends a message. 79 | * 80 | * @eventType org.devboy.hydra.commands.HydraCommandEvent.COMMAND_RECEIVED 81 | */ 82 | [Event(name="commandReceived", type="org.devboy.hydra.commands.HydraCommandEvent")] 83 | 84 | /** 85 | * Dispatched when the HydraChannel sends a message. 86 | * 87 | * @eventType org.devboy.hydra.commands.HydraCommandEvent.COMMAND_RECEIVED 88 | */ 89 | [Event(name="commandReceived", type="org.devboy.hydra.commands.HydraCommandEvent")] 90 | 91 | /** 92 | * Dispatched when a user joins the HydraChannel. 93 | * 94 | * @eventType org.devboy.hydra.users.HydraUserEvent.USER_CONNECT 95 | */ 96 | [Event(name="userConnect", type="org.devboy.hydra.users.HydraUserEvent")] 97 | 98 | /** 99 | * Dispatched when a user leaves the HydraChannel. 100 | * 101 | * @eventType org.devboy.hydra.users.HydraUserEvent.USER_DISCONNECT 102 | */ 103 | [Event(name="userDisconnect", type="org.devboy.hydra.users.HydraUserEvent")] 104 | 105 | /** 106 | * @author Dominic Graefen - devboy.org 107 | */ 108 | public class HydraChannel extends EventDispatcher 109 | { 110 | private var _channelId : String; 111 | private var _netGroup : NetGroup; 112 | private var _hydraService : HydraService; 113 | private var _connected : Boolean; 114 | private var _userTracker : HydraUserTracker; 115 | private var _specifier : GroupSpecifier; 116 | private var _withAuthorization : Boolean; 117 | private var _autoConnect : Boolean; 118 | 119 | public function HydraChannel(hydraService : HydraService, channelId : String, specifier : GroupSpecifier, withAuthorization : Boolean, autoConnect : Boolean = true ) 120 | { 121 | _autoConnect = autoConnect; 122 | _withAuthorization = withAuthorization; 123 | _specifier = specifier; 124 | _hydraService = hydraService; 125 | _channelId = channelId; 126 | super(this); 127 | init(); 128 | } 129 | 130 | private function init() : void 131 | { 132 | _userTracker = new HydraUserTracker(this); 133 | _userTracker.addEventListener(HydraUserEvent.USER_CONNECT, dispatchEvent); 134 | _userTracker.addEventListener(HydraUserEvent.USER_DISCONNECT, dispatchEvent); 135 | _hydraService.addChannel(this); 136 | } 137 | 138 | public function connect() : void 139 | { 140 | if(!_hydraService.connected) 141 | throw new Error( "HydraService needs to be connected first"); 142 | 143 | _hydraService.netConnection.addEventListener(NetStatusEvent.NET_STATUS, netStatus); 144 | _netGroup = new NetGroup(_hydraService.netConnection, _withAuthorization ? _specifier.groupspecWithAuthorizations() : _specifier.groupspecWithoutAuthorizations()); 145 | _netGroup.addEventListener(NetStatusEvent.NET_STATUS, netStatus); 146 | } 147 | 148 | public function addNeighbor(peerID : String) : Boolean 149 | { 150 | return netGroup.addNeighbor(peerID); 151 | } 152 | 153 | public function addMemberHint(peerID : String) : Boolean 154 | { 155 | return netGroup.addMemberHint(peerID); 156 | } 157 | 158 | private function netStatus(event : NetStatusEvent) : void 159 | { 160 | var infoCode : String = event.info.code; 161 | switch (infoCode) 162 | { 163 | case NetStatusCodes.NETGROUP_CONNECT_SUCCESS: 164 | case NetStatusCodes.NETGROUP_CONNECT_REJECTED: 165 | case NetStatusCodes.NETGROUP_CONNECT_FAILED: 166 | if (event.info.group && event.info.group == _netGroup) 167 | { 168 | _connected = infoCode == NetStatusCodes.NETGROUP_CONNECT_SUCCESS; 169 | _userTracker.addUser(_hydraService.user); 170 | dispatchEvent(new HydraEvent(getEventTypeForNetGroup(infoCode))); 171 | _hydraService.netConnection.removeEventListener(NetStatusEvent.NET_STATUS, netStatus); 172 | } 173 | break; 174 | case NetStatusCodes.NETGROUP_NEIGHBOUR_CONNECT: 175 | dispatchEvent(new NetGroupNeighborEvent(NetGroupNeighborEvent.NEIGHBOR_CONNECT, new NetGroupNeighbor(event.info.neighbor as String, event.info.peerID as String))); 176 | break; 177 | case NetStatusCodes.NETGROUP_NEIGHBOUR_DISCONNECT: 178 | dispatchEvent(new NetGroupNeighborEvent(NetGroupNeighborEvent.NEIGHBOR_DISCONNECT, new NetGroupNeighbor(event.info.neighbor as String, event.info.peerID as String))); 179 | break; 180 | case NetStatusCodes.NETGROUP_POSTING_NOTIFY: 181 | receiveCommand(event.info.message); 182 | break; 183 | } 184 | } 185 | 186 | private function receiveCommand( message : Object ) : void 187 | { 188 | var userId : String = message.userId; 189 | var type : String = message.type; 190 | var timestamp : Number = message.timestamp; 191 | var info : Object = message.info; 192 | var senderPeerId : String = message.senderPeerId; 193 | var command : IHydraCommand = _hydraService.commandFactory.createCommand(type, timestamp, userId, senderPeerId, info); 194 | if( command ) 195 | dispatchEvent( new HydraCommandEvent(HydraCommandEvent.COMMAND_RECEIVED, command)); 196 | } 197 | 198 | public function sendCommand( command : IHydraCommand ) : void 199 | { 200 | command.userId = _hydraService.user.uniqueId; 201 | command.timestamp = new Date().getTime(); 202 | var message : Object = new Object(); 203 | message.userId = command.userId; 204 | message.type = command.type; 205 | message.timestamp = command.timestamp; 206 | message.info = command.info; 207 | message.senderPeerId = _hydraService.netConnection.nearID; 208 | _netGroup.post(message); 209 | dispatchEvent( new HydraCommandEvent(HydraCommandEvent.COMMAND_SENT, command)); 210 | } 211 | 212 | private function getEventTypeForNetGroup(infoCode : String) : String 213 | { 214 | var eventType : String; 215 | switch(infoCode) 216 | { 217 | case NetStatusCodes.NETGROUP_CONNECT_SUCCESS: 218 | eventType = HydraEvent.CHANNEL_CONNECT_SUCCESS; 219 | break; 220 | case NetStatusCodes.NETGROUP_CONNECT_FAILED: 221 | eventType = HydraEvent.CHANNEL_CONNECT_FAILED; 222 | break; 223 | case NetStatusCodes.NETGROUP_CONNECT_REJECTED: 224 | eventType = HydraEvent.CHANNEL_CONNECT_REJECTED; 225 | break; 226 | } 227 | return eventType; 228 | } 229 | 230 | public function get connected() : Boolean 231 | { 232 | return _connected; 233 | } 234 | 235 | public function get channelId() : String 236 | { 237 | return _channelId; 238 | } 239 | 240 | public function get hydraService() : HydraService 241 | { 242 | return _hydraService; 243 | } 244 | 245 | public function get autoConnect() : Boolean 246 | { 247 | return _autoConnect; 248 | } 249 | 250 | public function get userTracker() : HydraUserTracker 251 | { 252 | return _userTracker; 253 | } 254 | 255 | protected function get netGroup() : NetGroup 256 | { 257 | return _netGroup; 258 | } 259 | } 260 | } 261 | -------------------------------------------------------------------------------- /src/main/as3/org/devboy/hydra/HydraEvent.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 (c) Dominic Graefen, devboy.org. 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, 8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the 10 | * Software is furnished to do so, subject to the following 11 | * conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | * OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | package org.devboy.hydra 26 | { 27 | import flash.events.Event; 28 | 29 | /** 30 | * @author Dominic Graefen - devboy.org 31 | */ 32 | public class HydraEvent extends Event 33 | { 34 | public static const SERVICE_CONNECT_SUCCESS : String = "org.devboy.hydra.HydraEvent.SERVICE_CONNECT_SUCCESS"; 35 | public static const SERVICE_CONNECT_FAILED : String = "org.devboy.hydra.HydraEvent.SERVICE_CONNECT_FAILED"; 36 | public static const SERVICE_CONNECT_CLOSED : String = "org.devboy.hydra.HydraEvent.SERVICE_CONNECT_CLOSED"; 37 | public static const SERVICE_CONNECT_REJECTED : String = "org.devboy.hydra.HydraEvent.SERVICE_CONNECT_REJECTED"; 38 | public static const CHANNEL_CONNECT_SUCCESS : String = "org.devboy.hydra.HydraEvent.CHANNEL_CONNECT_SUCCESS"; 39 | public static const CHANNEL_CONNECT_REJECTED : String = "org.devboy.hydra.HydraEvent.CHANNEL_CONNECT_REJECTE"; 40 | public static const CHANNEL_CONNECT_FAILED : String = "org.devboy.hydra.HydraEvent.CHANNEL_CONNECT_FAILED"; 41 | 42 | public function HydraEvent(type : String) 43 | { 44 | super(type, false, false); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/as3/org/devboy/hydra/HydraService.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 (c) Dominic Graefen, devboy.org. 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, 8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the 10 | * Software is furnished to do so, subject to the following 11 | * conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | * OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | package org.devboy.hydra 26 | { 27 | import flash.net.GroupSpecifier; 28 | import org.devboy.hydra.users.NetGroupNeighbor; 29 | import org.devboy.hydra.users.HydraUser; 30 | import org.devboy.hydra.commands.PingCommandCreator; 31 | import org.devboy.hydra.commands.HydraCommandFactory; 32 | import org.devboy.toolkit.net.NetStatusCodes; 33 | import flash.events.NetStatusEvent; 34 | import flash.net.NetConnection; 35 | import flash.events.EventDispatcher; 36 | 37 | /** 38 | * Dispatched when the HydraService connects 39 | * successfully to the service string. 40 | * 41 | * This event is dispatched only when the 42 | * hydra service trys to connect to the service url. 43 | * 44 | * @eventType org.devboy.hydra.HydraEvent.SERVICE_CONNECT_SUCCESS 45 | */ 46 | [Event(name="serviceConnectSuccess", type="org.devboy.hydra.HydraEvent")] 47 | 48 | /** 49 | * Dispatched when the HydraService connection 50 | * has failed. 51 | * 52 | * This event is dispatched only when the 53 | * hydra service trys to connect to the service url. 54 | * 55 | * @eventType org.devboy.hydra.HydraEvent.SERVICE_CONNECT_FAILED 56 | */ 57 | [Event(name="serviceConnectFailed", type="org.devboy.hydra.HydraEvent")] 58 | 59 | /** 60 | * Dispatched when the HydraService connection 61 | * closes. 62 | * 63 | * @eventType org.devboy.hydra.HydraEvent.SERVICE_CONNECT_CLOSED 64 | */ 65 | [Event(name="serviceConnectClosed", type="org.devboy.hydra.HydraEvent")] 66 | 67 | /** 68 | * Dispatched when the HydraService connection 69 | * is rejected. 70 | * 71 | * @eventType org.devboy.hydra.HydraEvent.SERVICE_CONNECT_REJECTED 72 | */ 73 | [Event(name="serviceConnectRejected", type="org.devboy.hydra.HydraEvent")] 74 | 75 | /** 76 | * @author Dominic Graefen - devboy.org 77 | */ 78 | public class HydraService extends EventDispatcher 79 | { 80 | private var _rtmfpService : String; 81 | private var _netConnection : NetConnection; 82 | private var _commandFactory : HydraCommandFactory; 83 | private var _user : HydraUser; 84 | private var _channels : Vector.; 85 | private var _serviceId : String; 86 | private var _serviceChannel : HydraChannel; 87 | 88 | public function HydraService(serviceId : String, rtmfpService : String) 89 | { 90 | _serviceId = serviceId; 91 | _rtmfpService = rtmfpService; 92 | super(this); 93 | init(); 94 | } 95 | 96 | public function connect( username : String ) : void 97 | { 98 | if( !connected ) 99 | { 100 | _user = new HydraUser(username, generateUserId(), null); 101 | _netConnection.connect(_rtmfpService); 102 | } 103 | } 104 | 105 | private function generateUserId() : String 106 | { 107 | var id : String = new Date().time.toString()+"/"+(Math.random()*100000).toFixed(0); 108 | return id; 109 | } 110 | 111 | public function close() : void 112 | { 113 | if( connected ) 114 | _netConnection.close(); 115 | } 116 | 117 | public function get connected() : Boolean 118 | { 119 | return _netConnection.connected; 120 | } 121 | 122 | public function addChannel( channel : HydraChannel ) : void 123 | { 124 | if( connected && channel.autoConnect && !channel.connected ) 125 | channel.connect(); 126 | _channels.push(channel); 127 | } 128 | 129 | private function connectAllChannels() : void 130 | { 131 | if(!connected) 132 | return; 133 | var channel : HydraChannel; 134 | for each(channel in _channels) 135 | if( channel.autoConnect && !channel.connected ) 136 | channel.connect(); 137 | } 138 | 139 | private function init() : void 140 | { 141 | _channels = new Vector.(); 142 | _commandFactory = new HydraCommandFactory(); 143 | _commandFactory.addCommandCreator( new PingCommandCreator() ); 144 | _netConnection = new NetConnection(); 145 | _netConnection.addEventListener(NetStatusEvent.NET_STATUS, netStatus); 146 | 147 | var serviceChannelId : String = _serviceId + "/" + "serviceChannel"; 148 | var groupSpecifier : GroupSpecifier = new GroupSpecifier(serviceChannelId); 149 | groupSpecifier.serverChannelEnabled = true; 150 | groupSpecifier.postingEnabled = true; 151 | _serviceChannel = new HydraChannel(this, serviceChannelId, groupSpecifier, false); 152 | } 153 | 154 | private function netStatus(event : NetStatusEvent) : void 155 | { 156 | switch(event.info.code) 157 | { 158 | case NetStatusCodes.NETCONNECTION_CONNECT_SUCCESS: 159 | _user.neighborId = new NetGroupNeighbor("", _netConnection.nearID); 160 | connectAllChannels(); 161 | dispatchEvent(new HydraEvent(HydraEvent.SERVICE_CONNECT_SUCCESS)); 162 | break; 163 | case NetStatusCodes.NETCONNECTION_CONNECT_CLOSED: 164 | dispatchEvent(new HydraEvent(HydraEvent.SERVICE_CONNECT_CLOSED)); 165 | break; 166 | case NetStatusCodes.NETCONNECTION_CONNECT_FAILED: 167 | dispatchEvent(new HydraEvent(HydraEvent.SERVICE_CONNECT_FAILED)); 168 | break; 169 | case NetStatusCodes.NETCONNECTION_CONNECT_REJECTED: 170 | dispatchEvent(new HydraEvent(HydraEvent.SERVICE_CONNECT_REJECTED)); 171 | break; 172 | } 173 | } 174 | 175 | public function get netConnection() : NetConnection 176 | { 177 | return _netConnection; 178 | } 179 | 180 | public function get commandFactory() : HydraCommandFactory 181 | { 182 | return _commandFactory; 183 | } 184 | 185 | public function get user() : HydraUser 186 | { 187 | return _user; 188 | } 189 | 190 | public function get serviceId() : String 191 | { 192 | return _serviceId; 193 | } 194 | 195 | public function get channels() : Vector. 196 | { 197 | return _channels; 198 | } 199 | 200 | public function get serviceChannel() : HydraChannel 201 | { 202 | return _serviceChannel; 203 | } 204 | } 205 | } 206 | -------------------------------------------------------------------------------- /src/main/as3/org/devboy/hydra/chat/ChatMessageCommand.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 (c) Dominic Graefen, devboy.org. 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, 8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the 10 | * Software is furnished to do so, subject to the following 11 | * conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | * OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | package org.devboy.hydra.chat 26 | { 27 | import org.devboy.hydra.commands.HydraCommand; 28 | /** 29 | * @author Dominic Graefen - devboy.org 30 | */ 31 | public class ChatMessageCommand extends HydraCommand 32 | { 33 | public static const TYPE : String = "org.devboy.hydra.chat.ChatMessageCommand.TYPE"; 34 | 35 | private var _chatMessage : String; 36 | 37 | public function ChatMessageCommand( chatMessage : String ) 38 | { 39 | _chatMessage = chatMessage; 40 | super(TYPE); 41 | } 42 | 43 | override public function get info() : Object 44 | { 45 | var info : Object = new Object(); 46 | info.chatMessage = _chatMessage; 47 | return info; 48 | } 49 | 50 | public function get chatMessage() : String 51 | { 52 | return _chatMessage; 53 | } 54 | 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/as3/org/devboy/hydra/chat/ChatMessageCommandCreator.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 (c) Dominic Graefen, devboy.org. 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, 8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the 10 | * Software is furnished to do so, subject to the following 11 | * conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | * OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | package org.devboy.hydra.chat 26 | { 27 | import org.devboy.hydra.commands.IHydraCommand; 28 | import org.devboy.hydra.commands.IHydraCommandCreator; 29 | 30 | /** 31 | * @author Dominic Graefen - devboy.org 32 | */ 33 | public class ChatMessageCommandCreator implements IHydraCommandCreator 34 | { 35 | public function createCommand(type : String, timestamp : Number, userId : String, senderPeerId : String, info : Object) : IHydraCommand 36 | { 37 | if( type != commandType ) 38 | throw new Error( "CommandTypes do not match!"); 39 | 40 | var chatMessage : String = info.chatMessage; 41 | var command : ChatMessageCommand = new ChatMessageCommand(chatMessage); 42 | command.timestamp = timestamp; 43 | command.userId = userId; 44 | command.senderPeerId = senderPeerId; 45 | return command; 46 | } 47 | 48 | public function get commandType() : String 49 | { 50 | return ChatMessageCommand.TYPE; 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/as3/org/devboy/hydra/chat/HydraChatChannel.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 (c) Dominic Graefen, devboy.org. 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, 8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the 10 | * Software is furnished to do so, subject to the following 11 | * conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | * OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | package org.devboy.hydra.chat 26 | { 27 | import org.devboy.hydra.commands.HydraCommandEvent; 28 | import org.devboy.hydra.HydraChannel; 29 | import org.devboy.hydra.HydraService; 30 | import flash.net.GroupSpecifier; 31 | /** 32 | * @author Dominic Graefen - devboy.org 33 | */ 34 | public class HydraChatChannel extends HydraChannel 35 | { 36 | public function HydraChatChannel( hydraService : HydraService, channelId : String, withAuthorization : Boolean = false, autoConnect : Boolean = true ) 37 | { 38 | var groupSpecifier : GroupSpecifier = new GroupSpecifier(channelId); 39 | groupSpecifier.serverChannelEnabled = true; 40 | groupSpecifier.postingEnabled = true; 41 | super( hydraService, channelId, groupSpecifier, withAuthorization, autoConnect ); 42 | init(); 43 | } 44 | 45 | private function init() : void 46 | { 47 | hydraService.commandFactory.addCommandCreator(new ChatMessageCommandCreator()); 48 | addEventListener(HydraCommandEvent.COMMAND_RECEIVED, commandEvent); 49 | } 50 | 51 | private function commandEvent(event : HydraCommandEvent) : void 52 | { 53 | switch( event.command.type ) 54 | { 55 | case ChatMessageCommand.TYPE: 56 | handleChatMessage(event.command as ChatMessageCommand); 57 | break; 58 | } 59 | } 60 | 61 | public function sendChatMessage( chatMessage : String ) : void 62 | { 63 | sendCommand(new ChatMessageCommand(chatMessage)); 64 | dispatchEvent(new HydraChatEvent(HydraChatEvent.MESSAGE_SENT, chatMessage, hydraService.user)); 65 | } 66 | 67 | private function handleChatMessage(command : ChatMessageCommand) : void 68 | { 69 | dispatchEvent( new HydraChatEvent(HydraChatEvent.MESSAGE_RECEIVED, command.chatMessage, userTracker.getUserByPeerId(command.senderPeerId) ) ); 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/as3/org/devboy/hydra/chat/HydraChatEvent.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 (c) Dominic Graefen, devboy.org. 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, 8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the 10 | * Software is furnished to do so, subject to the following 11 | * conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | * OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | package org.devboy.hydra.chat 26 | { 27 | import org.devboy.hydra.users.HydraUser; 28 | import flash.events.Event; 29 | 30 | /** 31 | * @author Dominic Graefen - devboy.org 32 | */ 33 | public class HydraChatEvent extends Event 34 | { 35 | public static const MESSAGE_RECEIVED : String = "org.devboy.hydra.chat.HydraChatEvent.MESSAGE_RECEIVED"; 36 | public static const MESSAGE_SENT : String = "org.devboy.hydra.chat.HydraChatEvent.MESSAGE_SENT"; 37 | 38 | private var _message : String; 39 | private var _sender : HydraUser; 40 | 41 | public function HydraChatEvent(type : String, message : String, sender : HydraUser) 42 | { 43 | _sender = sender; 44 | _message = message; 45 | super(type, false, false); 46 | } 47 | 48 | public function get message() : String 49 | { 50 | return _message; 51 | } 52 | 53 | public function get sender() : HydraUser 54 | { 55 | return _sender; 56 | } 57 | 58 | override public function clone() : Event 59 | { 60 | return new HydraChatEvent(type, message, sender); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/as3/org/devboy/hydra/commands/HydraCommand.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 (c) Dominic Graefen, devboy.org. 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, 8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the 10 | * Software is furnished to do so, subject to the following 11 | * conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | * OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | package org.devboy.hydra.commands 26 | { 27 | 28 | /** 29 | * @author Dominic Graefen - devboy.org 30 | */ 31 | public class HydraCommand implements IHydraCommand 32 | { 33 | private var _userId : String; 34 | private var _type : String; 35 | private var _timestamp : Number; 36 | private var _senderPeerId : String; 37 | 38 | public function HydraCommand( type : String ) 39 | { 40 | _type = type; 41 | } 42 | 43 | public function get userId() : String 44 | { 45 | return _userId; 46 | } 47 | 48 | public function get type() : String 49 | { 50 | return _type; 51 | } 52 | 53 | public function get timestamp() : Number 54 | { 55 | return _timestamp; 56 | } 57 | 58 | public function get info() : Object 59 | { 60 | throw new Error("Abstract method - needs to be overridden."); 61 | } 62 | 63 | public function set userId(id : String) : void 64 | { 65 | _userId = id; 66 | } 67 | 68 | public function set timestamp(time : Number) : void 69 | { 70 | _timestamp = time; 71 | } 72 | 73 | public function get senderPeerId() : String 74 | { 75 | return _senderPeerId; 76 | } 77 | 78 | public function set senderPeerId(senderPeerId : String) : void 79 | { 80 | _senderPeerId = senderPeerId; 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/main/as3/org/devboy/hydra/commands/HydraCommandEvent.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 (c) Dominic Graefen, devboy.org. 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, 8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the 10 | * Software is furnished to do so, subject to the following 11 | * conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | * OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | package org.devboy.hydra.commands 26 | { 27 | import flash.events.Event; 28 | 29 | /** 30 | * @author Dominic Graefen - devboy.org 31 | */ 32 | public class HydraCommandEvent extends Event 33 | { 34 | public static const COMMAND_SENT : String = "org.devboy.hydra.commands.HydraCommandEvent.COMMAND_SENT"; 35 | public static const COMMAND_RECEIVED : String = "org.devboy.hydra.commands.HydraCommandEvent.COMMAND_RECEIVED"; 36 | 37 | private var _command : IHydraCommand; 38 | 39 | public function HydraCommandEvent(type : String, command : IHydraCommand) 40 | { 41 | _command = command; 42 | super(type, false, false); 43 | } 44 | 45 | public function get command() : IHydraCommand 46 | { 47 | return _command; 48 | } 49 | 50 | override public function clone() : Event 51 | { 52 | return new HydraCommandEvent(type, command); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/as3/org/devboy/hydra/commands/HydraCommandFactory.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 (c) Dominic Graefen, devboy.org. 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, 8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the 10 | * Software is furnished to do so, subject to the following 11 | * conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | * OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | package org.devboy.hydra.commands 26 | { 27 | /** 28 | * @author Dominic Graefen - devboy.org 29 | */ 30 | public class HydraCommandFactory 31 | { 32 | private var _creators : Vector.; 33 | 34 | public function HydraCommandFactory() 35 | { 36 | init(); 37 | } 38 | 39 | private function init() : void 40 | { 41 | _creators = new Vector.(); 42 | } 43 | 44 | public function addCommandCreator( creator : IHydraCommandCreator ) : void 45 | { 46 | if( !containsCommandCreatorForType(creator.commandType) ) 47 | _creators.push(creator); 48 | } 49 | 50 | private function containsCommandCreatorForType( type : String ) : Boolean 51 | { 52 | var creator : IHydraCommandCreator; 53 | for each(creator in _creators) 54 | if( creator.commandType == type ) 55 | return true; 56 | return false; 57 | } 58 | 59 | public function removeCommandCreator( creator : IHydraCommandCreator ) : void 60 | { 61 | var i : int = 0; 62 | const l : int = _creators.length; 63 | for(;i 0 ) 96 | { 97 | _chatChannel.sendChatMessage(_chatWindow.messageInput); 98 | _chatWindow.clearMessageInput(); 99 | } 100 | } 101 | 102 | private function loginClick( e : Event ) : void 103 | { 104 | _loginBox.visible = false; 105 | _statusBox.text = "Connecting..."; 106 | _hydraService.connect(_loginBox.username); 107 | } 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /src/main/as3/org/devboy/hydra/examples/clickcommand/ClickCommand.as: -------------------------------------------------------------------------------- 1 | package org.devboy.hydra.examples.clickcommand 2 | { 3 | import org.devboy.hydra.commands.HydraCommand; 4 | 5 | /** 6 | * @author Dominic Graefen - devboy.org 7 | */ 8 | public class ClickCommand extends HydraCommand 9 | { 10 | public static const TYPE : String = "org.devboy.hydra.examples.clickcommand.ClickCommand.TYPE"; 11 | 12 | private var _x : Number; 13 | private var _y : Number; 14 | 15 | public function ClickCommand( x : Number, y : Number ) 16 | { 17 | _y = y; 18 | _x = x; 19 | super(TYPE); 20 | } 21 | 22 | override public function get info() : Object 23 | { 24 | var info : Object = new Object(); 25 | info.x = _x; 26 | info.y = _y; 27 | return info; 28 | } 29 | 30 | public function get x() : Number 31 | { 32 | return _x; 33 | } 34 | 35 | public function get y() : Number 36 | { 37 | return _y; 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/as3/org/devboy/hydra/examples/clickcommand/ClickCommandCreator.as: -------------------------------------------------------------------------------- 1 | package org.devboy.hydra.examples.clickcommand 2 | { 3 | import org.devboy.hydra.commands.IHydraCommand; 4 | import org.devboy.hydra.commands.IHydraCommandCreator; 5 | 6 | /** 7 | * @author Dominic Graefen - devboy.org 8 | */ 9 | public class ClickCommandCreator implements IHydraCommandCreator 10 | { 11 | public function createCommand( type : String, timestamp : Number, userId : String, senderPeerId : String, info : Object ) : IHydraCommand 12 | { 13 | if( type != commandType ) 14 | throw new Error("Command type mismatch"); 15 | 16 | var x : Number = info.x; 17 | var y : Number = info.y; 18 | 19 | var clickCommand : ClickCommand = new ClickCommand(x, y); 20 | clickCommand.timestamp = timestamp; 21 | clickCommand.userId = userId; 22 | clickCommand.senderPeerId = senderPeerId; 23 | return clickCommand; 24 | } 25 | 26 | public function get commandType() : String 27 | { 28 | return ClickCommand.TYPE; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/as3/org/devboy/hydra/examples/clickcommand/ClickCommandExample.as: -------------------------------------------------------------------------------- 1 | package org.devboy.hydra.examples.clickcommand 2 | { 3 | import org.devboy.hydra.HydraChannel; 4 | import org.devboy.hydra.HydraEvent; 5 | import org.devboy.hydra.HydraService; 6 | import org.devboy.hydra.commands.HydraCommandEvent; 7 | 8 | import flash.display.DisplayObject; 9 | import flash.display.Shape; 10 | import flash.display.Sprite; 11 | import flash.events.Event; 12 | import flash.events.MouseEvent; 13 | import flash.net.GroupSpecifier; 14 | 15 | /** 16 | * @author Dominic Graefen - devboy.org 17 | */ 18 | public class ClickCommandExample extends Sprite 19 | { 20 | private var _hydraService : HydraService; 21 | private var _clickChannel : HydraChannel; 22 | private var _shapeContainer : Sprite; 23 | public function ClickCommandExample() 24 | { 25 | init(); 26 | _shapeContainer = new Sprite(); 27 | _shapeContainer.graphics.beginFill(0, 0); 28 | _shapeContainer.graphics.drawRect(0, 0, 1000, 1000); 29 | _shapeContainer.graphics.endFill(); 30 | addChild(_shapeContainer); 31 | addEventListener(Event.ENTER_FRAME, enterFrame); 32 | addEventListener(MouseEvent.CLICK, mouseClick ); 33 | } 34 | 35 | private function init() : void 36 | { 37 | var stratusServiceUrl : String = "rtmfp://stratus.rtmfp.net/YOUR-API-KEY"; 38 | _hydraService = new HydraService("HydraClickExample", stratusServiceUrl); 39 | _hydraService.addEventListener(HydraEvent.SERVICE_CONNECT_SUCCESS, serviceEvent); 40 | _hydraService.addEventListener(HydraEvent.SERVICE_CONNECT_FAILED, serviceEvent); 41 | _hydraService.addEventListener(HydraEvent.SERVICE_CONNECT_REJECTED, serviceEvent); 42 | var groupSpecifier : GroupSpecifier = new GroupSpecifier("HydraClickExample/ClickChannel"); 43 | groupSpecifier.postingEnabled = true; 44 | groupSpecifier.serverChannelEnabled = true; 45 | _clickChannel = new HydraChannel(_hydraService, "HydraClickExample/ClickChannel", groupSpecifier, false ); 46 | _clickChannel.addEventListener(HydraCommandEvent.COMMAND_RECEIVED, handleCommand); 47 | _hydraService.commandFactory.addCommandCreator(new ClickCommandCreator()); 48 | _hydraService.connect(new Date().time.toFixed(0)+"/"+(Math.random()*100000).toFixed()); 49 | } 50 | 51 | private function enterFrame(event : Event) : void 52 | { 53 | var invisible : Vector. = new Vector.(); 54 | var displayObject : DisplayObject; 55 | var i : int = 0; 56 | var l : int = _shapeContainer.numChildren; 57 | for( ;i; 34 | private var _groupSpecifier:GroupSpecifier; 35 | 36 | public function VideoStreamExample() 37 | { 38 | stage.scaleMode = StageScaleMode.NO_SCALE; 39 | stage.align = StageAlign.TOP_LEFT; 40 | init(); 41 | } 42 | 43 | private function init() : void 44 | { 45 | var stratusServiceUrl : String = "rtmfp://stratus.rtmfp.net/API_KEY"; 46 | _hydraService = new HydraService("HydraVideoStreamExample", "rtmfp:"); 47 | _hydraService.addEventListener(HydraEvent.SERVICE_CONNECT_SUCCESS, serviceEvent); 48 | _hydraService.addEventListener(HydraEvent.SERVICE_CONNECT_FAILED, serviceEvent); 49 | _hydraService.addEventListener(HydraEvent.SERVICE_CONNECT_REJECTED, serviceEvent); 50 | _hydraService.commandFactory.addCommandCreator( new PublishStreamCommandCreator() ); 51 | _hydraService.connect("dom"); 52 | var groupSpecifier : GroupSpecifier = new GroupSpecifier("StreamChannel"); 53 | groupSpecifier.postingEnabled = true; 54 | groupSpecifier.serverChannelEnabled = true; 55 | groupSpecifier.multicastEnabled = true; 56 | groupSpecifier.addIPMulticastAddress("225.225.0.1:35353"); 57 | groupSpecifier.ipMulticastMemberUpdatesEnabled = true; 58 | _groupSpecifier = groupSpecifier; 59 | _streamChannel = new HydraChannel(_hydraService,"StreamChannel",groupSpecifier,false); 60 | _streamChannel.addEventListener(HydraCommandEvent.COMMAND_RECEIVED,commandReceived); 61 | _streamChannel.addEventListener(HydraUserEvent.USER_CONNECT, userUpdate ); 62 | _streamChannel.addEventListener(HydraUserEvent.USER_DISCONNECT, userUpdate ); 63 | _receivingIds = new Vector.(); 64 | } 65 | 66 | private function containsReceiver( streamId : String ) : Boolean 67 | { 68 | var test : String; 69 | for each( test in _receivingIds ) 70 | if( test == streamId ) 71 | return true; 72 | return false; 73 | } 74 | 75 | private function userUpdate(event:HydraUserEvent):void 76 | { 77 | _streamChannel.sendCommand( new PublishStreamCommand(_sendStreamId) ); 78 | } 79 | 80 | private function commandReceived(event:HydraCommandEvent):void 81 | { 82 | switch( event.command.type ) 83 | { 84 | case PublishStreamCommand.TYPE: 85 | handleIncomingStream(event.command as PublishStreamCommand); 86 | break; 87 | } 88 | } 89 | 90 | private function handleIncomingStream(publishStreamCommand:PublishStreamCommand):void 91 | { 92 | if( containsReceiver(publishStreamCommand.streamId)) 93 | return; 94 | var receiver : NetStream = new NetStream(_hydraService.netConnection,_groupSpecifier.groupspecWithAuthorizations()); 95 | receiver.play(publishStreamCommand.streamId); 96 | var video : Video = new Video(160,120); 97 | video.x = width; 98 | video.attachNetStream(receiver); 99 | addChild(video); 100 | _receivingIds.push(publishStreamCommand.streamId); 101 | } 102 | 103 | private function serviceEvent(event : HydraEvent) : void 104 | { 105 | switch( event.type ) 106 | { 107 | case HydraEvent.SERVICE_CONNECT_SUCCESS: 108 | initStreams(); 109 | break; 110 | case HydraEvent.SERVICE_CONNECT_FAILED: 111 | break; 112 | case HydraEvent.SERVICE_CONNECT_REJECTED: 113 | break; 114 | } 115 | } 116 | 117 | private function initStreams():void 118 | { 119 | var webcam : Camera = Camera.getCamera(); 120 | webcam.setMode(320,240,24); 121 | var video : Video = new Video(160,120); 122 | video.attachCamera(webcam); 123 | addChild(video); 124 | var mic : Microphone = Microphone.getMicrophone(); 125 | 126 | _sender = new NetStream(_hydraService.netConnection,_groupSpecifier.groupspecWithAuthorizations()); 127 | _sender.addEventListener(NetStatusEvent.NET_STATUS,netStatus); 128 | _sender.publish(_sendStreamId = getTimer().toFixed() + (Math.random() * 1000).toFixed() ); 129 | _sender.attachCamera(webcam); 130 | // _sender.attachAudio(mic); 131 | _streamChannel.sendCommand( new PublishStreamCommand(_sendStreamId) ); 132 | } 133 | 134 | private function netStatus(event:NetStatusEvent):void 135 | { 136 | } 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /src/main/as3/org/devboy/hydra/users/HydraUser.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 (c) Dominic Graefen, devboy.org. 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, 8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the 10 | * Software is furnished to do so, subject to the following 11 | * conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | * OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | package org.devboy.hydra.users 26 | { 27 | /** 28 | * @author Dominic Graefen - devboy.org 29 | */ 30 | public class HydraUser 31 | { 32 | private var _name : String; 33 | private var _uniqueId : String; 34 | private var _neighborId : NetGroupNeighbor; 35 | 36 | public function HydraUser(name : String, uniqueId : String, neighborId : NetGroupNeighbor) 37 | { 38 | _uniqueId = uniqueId; 39 | _name = name; 40 | _neighborId = neighborId; 41 | } 42 | 43 | public function get name() : String 44 | { 45 | return _name; 46 | } 47 | 48 | public function get uniqueId() : String 49 | { 50 | return _uniqueId; 51 | } 52 | 53 | public function get neighborId() : NetGroupNeighbor 54 | { 55 | return _neighborId; 56 | } 57 | 58 | public function set neighborId(neighborId : NetGroupNeighbor) : void 59 | { 60 | _neighborId = neighborId; 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/as3/org/devboy/hydra/users/HydraUserEvent.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 (c) Dominic Graefen, devboy.org. 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, 8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the 10 | * Software is furnished to do so, subject to the following 11 | * conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | * OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | package org.devboy.hydra.users 26 | { 27 | import flash.events.Event; 28 | 29 | /** 30 | * @author Dominic Graefen - devboy.org 31 | */ 32 | public class HydraUserEvent extends Event 33 | { 34 | public static const USER_CONNECT : String = "org.devboy.hydra.HydraUserEvent.USER_CONNECT"; 35 | public static const USER_DISCONNECT : String = "org.devboy.hydra.HydraUserEvent.USER_DISCONNECT"; 36 | 37 | private var _user : HydraUser; 38 | 39 | public function HydraUserEvent(type : String,user:HydraUser) 40 | { 41 | _user = user; 42 | super(type); 43 | } 44 | 45 | public function get user() : HydraUser 46 | { 47 | return _user; 48 | } 49 | 50 | override public function clone() : Event 51 | { 52 | return new HydraUserEvent(type, user); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/as3/org/devboy/hydra/users/HydraUserTracker.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 (c) Dominic Graefen, devboy.org. 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, 8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the 10 | * Software is furnished to do so, subject to the following 11 | * conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | * OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | package org.devboy.hydra.users 26 | { 27 | import org.devboy.hydra.commands.PingCommand; 28 | import org.devboy.hydra.commands.HydraCommandEvent; 29 | import org.devboy.hydra.HydraChannel; 30 | import flash.events.EventDispatcher; 31 | 32 | /** 33 | * @author Dominic Graefen - devboy.org 34 | */ 35 | public class HydraUserTracker extends EventDispatcher 36 | { 37 | private var _users : Vector.; 38 | private var _hydraChannel : HydraChannel; 39 | 40 | public function HydraUserTracker(hydraChannel:HydraChannel) 41 | { 42 | _hydraChannel = hydraChannel; 43 | super(this); 44 | init(); 45 | } 46 | 47 | private function init() : void 48 | { 49 | _users = new Vector.(); 50 | _hydraChannel.addEventListener(NetGroupNeighborEvent.NEIGHBOR_CONNECT, neighborEvent); 51 | _hydraChannel.addEventListener(NetGroupNeighborEvent.NEIGHBOR_DISCONNECT, neighborEvent); 52 | _hydraChannel.addEventListener(HydraCommandEvent.COMMAND_RECEIVED, commandEvent ); 53 | } 54 | 55 | private function commandEvent(event : HydraCommandEvent) : void 56 | { 57 | switch( event.command.type ) 58 | { 59 | case PingCommand.TYPE: 60 | handlePingCommand(event.command as PingCommand); 61 | break; 62 | } 63 | } 64 | 65 | private function handlePingCommand(command : PingCommand) : void 66 | { 67 | var user : HydraUser = new HydraUser(command.userName, command.userId, new NetGroupNeighbor("", command.senderPeerId) ); 68 | addUser(user); 69 | } 70 | 71 | private function neighborEvent(event : NetGroupNeighborEvent) : void 72 | { 73 | switch(event.type) 74 | { 75 | case NetGroupNeighborEvent.NEIGHBOR_CONNECT: 76 | break; 77 | case NetGroupNeighborEvent.NEIGHBOR_DISCONNECT: 78 | removeNeighbor(event.netGroupNeighbor); 79 | break; 80 | } 81 | _hydraChannel.sendCommand( new PingCommand( _hydraChannel.hydraService.user.name ) ); 82 | } 83 | 84 | private function removeNeighbor(netGroupNeighbor : NetGroupNeighbor) : void 85 | { 86 | var user : HydraUser = getUserByPeerId(netGroupNeighbor.peerId); 87 | if( user ) 88 | removeUser( user ); 89 | } 90 | 91 | public function addUser( user : HydraUser ) : void 92 | { 93 | var listedUser : HydraUser; 94 | for each(listedUser in _users) 95 | if( listedUser.uniqueId == user.uniqueId ) 96 | return; 97 | 98 | _users.push(user); 99 | _hydraChannel.addMemberHint(user.neighborId.peerId); 100 | _hydraChannel.addNeighbor(user.neighborId.peerId); 101 | dispatchEvent( new HydraUserEvent(HydraUserEvent.USER_CONNECT, user)); 102 | } 103 | 104 | private function removeUser(user : HydraUser) : void 105 | { 106 | var i : int = 0; 107 | const l : int = _users.length; 108 | for(;i 130 | { 131 | return _users; 132 | } 133 | 134 | 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /src/main/as3/org/devboy/hydra/users/NetGroupNeighbor.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 (c) Dominic Graefen, devboy.org. 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, 8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the 10 | * Software is furnished to do so, subject to the following 11 | * conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | * OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | package org.devboy.hydra.users 26 | { 27 | /** 28 | * @author Dominic Graefen - devboy.org 29 | */ 30 | public class NetGroupNeighbor 31 | { 32 | private var _neighborId : String; 33 | private var _peerId : String; 34 | 35 | public function NetGroupNeighbor(neighborId : String, peerId : String) 36 | { 37 | _peerId = peerId; 38 | _neighborId = neighborId; 39 | } 40 | 41 | public function get neighborId() : String 42 | { 43 | return _neighborId; 44 | } 45 | 46 | public function get peerId() : String 47 | { 48 | return _peerId; 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/as3/org/devboy/hydra/users/NetGroupNeighborEvent.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 (c) Dominic Graefen, devboy.org. 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, 8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the 10 | * Software is furnished to do so, subject to the following 11 | * conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | * OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | package org.devboy.hydra.users 26 | { 27 | import flash.events.Event; 28 | 29 | /** 30 | * @author Dominic Graefen - devboy.org 31 | */ 32 | public class NetGroupNeighborEvent extends Event 33 | { 34 | public static const NEIGHBOR_CONNECT : String = "org.devboy.hydra.NetGroupNeighborEvent.NEIGHBOR_CONNECT"; 35 | public static const NEIGHBOR_DISCONNECT : String = "org.devboy.hydra.NetGroupNeighborEvent.NEIGHBOR_DISCONNECT"; 36 | 37 | private var _netGroupNeighbor : NetGroupNeighbor; 38 | 39 | public function NetGroupNeighborEvent(type : String, netGroupNeighbor : NetGroupNeighbor) 40 | { 41 | _netGroupNeighbor = netGroupNeighbor; 42 | super(type, false, false); 43 | } 44 | 45 | public function get netGroupNeighbor() : NetGroupNeighbor 46 | { 47 | return _netGroupNeighbor; 48 | } 49 | 50 | override public function clone() : Event 51 | { 52 | return new NetGroupNeighborEvent(type, netGroupNeighbor); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/as3/org/devboy/toolkit/net/NetStatusCodes.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 (c) Dominic Graefen, devboy.org. 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, 8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the 10 | * Software is furnished to do so, subject to the following 11 | * conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | * OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | package org.devboy.toolkit.net 26 | { 27 | /** 28 | * @author Dominic Graefen - devboy.org 29 | */ 30 | public class NetStatusCodes 31 | { 32 | public static const NETCONNECTION_CONNECT_SUCCESS : String = "NetConnection.Connect.Success"; 33 | public static const NETCONNECTION_CONNECT_FAILED : String = "NetConnection.Connect.Failed"; 34 | public static const NETCONNECTION_CONNECT_CLOSED : String = "NetConnection.Connect.Closed"; 35 | public static const NETCONNECTION_CONNECT_REJECTED : String = "NetConnection.Connect.Rejected"; 36 | public static const NETGROUP_CONNECT_SUCCESS : String = "NetGroup.Connect.Success"; 37 | public static const NETGROUP_CONNECT_REJECTED : String = "NetGroup.Connect.Rejected"; 38 | public static const NETGROUP_CONNECT_FAILED : String = "NetGroup.Connect.Failed"; 39 | public static const NETGROUP_REPLICATION_FETCH_SENDNOTIFY : String = "NetGroup.Replication.Fetch.SendNotify"; 40 | public static const NETGROUP_REPLICATION_FETCH_FAILED : String = "NetGroup.Replication.Fetch.Failed"; 41 | public static const NETGROUP_REPLICATION_FETCH_RESULT : String = "NetGroup.Replication.Fetch.Result"; 42 | public static const NETGROUP_REPLICATION_FETCH_REQUEST : String = "NetGroup.Replication.Request"; 43 | public static const NETGROUP_POSTING_NOTIFY : String = "NetGroup.Posting.Notify"; 44 | public static const NETGROUP_NEIGHBOUR_CONNECT : String = "NetGroup.Neighbor.Connect"; 45 | public static const NETGROUP_NEIGHBOUR_DISCONNECT : String = "NetGroup.Neighbor.Disconnect"; 46 | } 47 | } --------------------------------------------------------------------------------