Adobe Stratusサンプルを読み解く
Stratus Sample Application
がコードといっしょに公開されているので読んでみる。
■NetConnectionでAdobeの提供しているrtmfpサーバstratusにつなぐ
予めDeveloperKeyを手に入れておく。
PLAIN TEXT
Actionscript:
netConnection = new NetConnection();
netConnection.addEventListener(NetStatusEvent.NET_STATUS, netConnectionHandler);
netConnection.connect("rtmfp://stratus.adobe.com/" + DeveloperKey);
NetStatusEventの NetConnection.Connect.Sucess になると、
NetConnection.nearID がとれる
この64桁のIDが、他のPeerから自分につなぐために、
相手が知る必要のある情報
webサービスに登録しておいて、
ユーザー名と照合できるようにしておく
#これがHttpIdManager.asのお仕事
なんだろサンプルでは4つのNetStream使ってるけど、
お互いの2つだけでいけそうだなぁ。
■音声/映像のやり取り
ユーザー名知ってる人に電話かけようかなと思ったら、
webサービスに照合して、相手の64桁のIDをもらい、
それをNetStreamに渡す(identity)
PLAIN TEXT
Actionscript:
incomingStream = new NetStream(netConnection, identity);
incomingStream.play("media-callee");
playすれば音が鳴るし、VideoにattachNetStreamすれば相手の映像が見える
出す方は、DIRECT_CONNECTIONS設定してpublishする
PLAIN TEXT
Actionscript:
outgoingStream = new NetStream(netConnection, NetStream.DIRECT_CONNECTIONS);
outgoingStream.publish("media-caller");
publish,playに渡す引数は、電話かける方はmedia-caller,受ける方はmedia-calleeとしてるけどなんでもよさそう。
ルールを決めておけばよい。
↓clientにonPeerConnectって関数を入れておくと、
誰かPeerがつないできたときに、farIDが取れる。
onPeerConnectがtrueを返せば接続ok、
falseを返せば接続ngッぽいので、
非接続側でもう一度webサービスにfarIDを照合して誰が電話かけてきたのか着信履歴表示や着信拒否ができそうだね
PLAIN TEXT
Actionscript:
var o:Object = new Object
o.onPeerConnect = function(caller:NetStream):Boolean {
status("Callee connecting to media stream: " + caller.farID + "\n");
return true;
}
outgoingStream.client = o;
■RPC
NetStream.sendを使えばPeer2PeerのRPCも簡単。
PLAIN TEXT
Actionscript:
outgoingStream.send("onIm", userNameInput.text, msg); [...]
FlashによるP2Pセッション確立用サーバStratus
って理解でいいのかな。
Adobe MAX 2008 US での発表つづき
Stratusってなんだろって探すとある
Stratus
http://labs.adobe.com/wiki/index.php/Stratus
Flash Player 10 and Adobe AIR 1.5 introduce a new communications protocol called the Real-Time Media Flow Protocol (RTMFP). The most important features of RTMFP include low latency, end-to-end peering capability, security and scalability. These properties make RTMFP especially well suited for developing real-time collaboration applications by not only providing superior [...]