Created
August 29, 2012 19:38
-
-
Save mki/3517740 to your computer and use it in GitHub Desktop.
Action Script 3 P2P to Live example ( see more at http://mkifiles.ru/?p=1336)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package | |
{ | |
import states.LiveState; | |
import states.PeerState; | |
import states.state.IConnection; | |
import flash.net.NetStream; | |
public class Connections | |
{ | |
private var peerState:PeerState; | |
private var liveState:LiveState; | |
private var state:IConnection; | |
private var stateString:String; | |
public static var STATE_PEER:String = 'peerState'; | |
public static var STATE_LIVE:String = 'liveState'; | |
public function Connections() | |
{ | |
this.peerState = new PeerState(this); | |
this.liveState = new LiveState(this); | |
this.state = this.peerState; | |
this.stateString = Connections.STATE_PEER; | |
} | |
public function setLiveState():void | |
{ | |
this.state = this.liveState; | |
this.stateString = Connections.STATE_LIVE; | |
} | |
public function setP2PState():void | |
{ | |
this.state = this.peerState; | |
this.stateString = Connections.STATE_PEER; | |
} | |
public function connect():void | |
{ | |
this.state.connect(); | |
} | |
/*...*/ | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package states.state | |
{ | |
import flash.net.NetConnection; | |
import flash.net.NetStream; | |
public interface IConnection | |
{ | |
function connect():void; | |
function getNetConnect():NetConnection; | |
function startOutgoingStream():void; | |
function startIncomingStream(peerID:String):void; | |
function getOutgoingStream():NetStream; | |
function getIncomingStream():NetStream; | |
function disconnect():void; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package states | |
{ | |
import states.state.IConnection; | |
import flash.net.NetConnection; | |
import flash.net.NetStream; | |
import flash.events.NetStatusEvent; | |
public class LiveState implements IConnection | |
{ | |
private var URL_LIVE:String = ""; | |
private var netConnection:NetConnection = null; | |
private var _conn:Connections = null; | |
public var outgoingStream:NetStream = null; | |
public var incomingStream:NetStream = null; | |
public function LiveState(conn:Connections):void | |
{ | |
_conn = conn | |
URL_LIVE = 'rtmp://your_server/live'; | |
} | |
public function connect():void | |
{ | |
netConnection = new NetConnection(); | |
netConnection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler); | |
netConnection.connect(URL_LIVE); | |
} | |
/*...*/ | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package states | |
{ | |
import states.state.IConnection; | |
import flash.net.NetConnection; | |
import flash.net.NetStream; | |
import flash.events.NetStatusEvent; | |
public class PeerState implements IConnection | |
{ | |
private var URL_P2P:String = ""; | |
private var DEVKEY:String = ""; | |
private var netConnection:NetConnection = null; | |
private var _conn:Connections = null; | |
public var outgoingStream:NetStream = null; | |
public var incomingStream:NetStream = null; | |
public function PeerState(conn:Connections):void | |
{ | |
_conn = conn | |
URL_P2P = 'rtmfp://your_server/multicast'; | |
DEVKEY = ''; | |
} | |
public function connect():void | |
{ | |
netConnection = new NetConnection(); | |
netConnection.addEventListener(NetStatusEvent.NET_STATUS, /*...*/); | |
netConnection.connect(URL_P2P, DEVKEY); | |
} | |
/*...*/ | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public var connections:Connections; | |
// Подключаемся по-умолчанию к p2p | |
connections = new Connections(); | |
connections.connect(); | |
// Переключаемся на live, завершая текущее соединение | |
connections.disconnect(); | |
connections.setLiveState(); | |
connections.connect(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment