...
Overview
Supported platforms
Adobe Flash | |
---|---|
Windows | + |
Mac OS | + |
Linux | + |
Operation flowchart
- The browser establishes a connection via Websocket and sends the publish command.
- the browser sends the WebRTC stream to the server.
- Flash Player connects to the server via the RTMP protocol and sends the play command.
- Flash Player receives the RTMP stream from the server.
...
connect(); code
Code Block | ||||
---|---|---|---|---|
| ||||
private function connect():void{ var url:String = StringUtil.trim(connectUrl.text); Logger.info("connect " + url); nc = new NetConnection(); //if (url.indexOf("rtmp") == 0){ // nc.objectEncoding = ObjectEncoding.AMF0; //} nc.client = this; nc.addEventListener(NetStatusEvent.NET_STATUS, handleConnectionStatus); var obj:Object = new Object(); obj.login = generateRandomString(20); obj.appKey = "flashStreamingApp"; nc.connect(url,obj); } |
...
NetConnection.Connect.Success code
Code Block | ||||
---|---|---|---|---|
| ||||
private function handleConnectionStatus(event:NetStatusEvent):void{ Logger.info("handleConnectionStatus: "+event.info.code); if (event.info.code=="NetConnection.Connect.Success"){ Logger.info("near id: "+nc.nearID); Logger.info("far id: "+nc.farID); Logger.info("Connection opened"); disconnectBtn.visible = true; connectBtn.visible = false; playBtn.enabled = true; publishBtn.enabled = true; setConnectionStatus("CONNECTED"); } else if (event.info.code=="NetConnection.Connect.Closed" || event.info.code=="NetConnection.Connect.Failed"){ ... } } |
...
stream.play(); code
Code Block | ||||
---|---|---|---|---|
| ||||
private function addListenerAndPlay():void{ ... subscribeStreamObject = createStreamObject(); subscribeStream.play(playStreamName.text); videoFarEnd.attachNetStream(subscribeStream); videoFarEnd.width = 320; videoFarEnd.height = 240; videoFarEnd.visible = true; } |
...
NetStream.Play.Start code
Code Block | ||||
---|---|---|---|---|
| ||||
private function handleSubscribeStreamStatus(event:NetStatusEvent):void{ Logger.info("handleSubscribeStreamStatus: "+event.info.code); switch (event.info.code) { case "NetStream.Play.PublishNotify": case "NetStream.Play.Start": setPlayStatus("PLAYING"); playBtn.visible = false; stopBtn.enabled = true; stopBtn.visible = true; break; ... } } |
...
stream.close(); code
Code Block | ||||
---|---|---|---|---|
| ||||
private function stop():void{ if (subscribeStream != null) { stopBtn.enabled = false; subscribeStream.close(); subscribeStream = null; } subscribeStreamObject = null; videoFarEnd.visible = false; } |
...
NetStream.Play.Stop code
Code Block | ||||
---|---|---|---|---|
| ||||
private function handleSubscribeStreamStatus(event:NetStatusEvent):void{ Logger.info("handleSubscribeStreamStatus: "+event.info.code); switch (event.info.code) { ... case "NetStream.Play.UnpublishNotify": case "NetStream.Play.Stop": setPlayStatus("STOPPED"); playBtn.enabled = true; playBtn.visible = true; stopBtn.visible = false; break; ... } } |