| 1 | /** |
|---|
| 2 | * Manages playback of live streams through a subscription mechanism. |
|---|
| 3 | **/ |
|---|
| 4 | package com.jeroenwijering.models { |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | import com.jeroenwijering.events.*; |
|---|
| 8 | import com.jeroenwijering.models.RTMPModel; |
|---|
| 9 | import com.jeroenwijering.player.Model; |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | import flash.events.*; |
|---|
| 13 | import flash.utils.*; |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | public class FCSubscribeModel extends RTMPModel { |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | /** Interval ID for subscription pings. **/ |
|---|
| 20 | private var subscribe:Number; |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | /** Constructor. **/ |
|---|
| 24 | public function FCSubscribeModel(mod:Model):void { |
|---|
| 25 | super(mod); |
|---|
| 26 | }; |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | /** Try subscribing. **/ |
|---|
| 30 | private function doSubscribe(id:String):void { |
|---|
| 31 | connection.call("FCSubscribe",null,id); |
|---|
| 32 | }; |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | /** Check metadata for subscription success/failure. **/ |
|---|
| 36 | override public function onData(dat:Object):void { |
|---|
| 37 | if(dat.type == 'fcsubscribe') { |
|---|
| 38 | if(dat.code == "NetStream.Play.StreamNotFound" ) { |
|---|
| 39 | model.sendEvent(ModelEvent.ERROR,{message:"Subscription failed: "+item['file']}); |
|---|
| 40 | } else if(dat.code == "NetStream.Play.Start") { |
|---|
| 41 | setStream(); |
|---|
| 42 | } |
|---|
| 43 | clearInterval(subscribe); |
|---|
| 44 | } |
|---|
| 45 | super.onData(dat); |
|---|
| 46 | }; |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | /** Receive NetStream status updates. **/ |
|---|
| 50 | override protected function statusHandler(evt:NetStatusEvent):void { |
|---|
| 51 | if (evt.info.code == 'NetConnection.Connect.Success') { |
|---|
| 52 | model.sendEvent(ModelEvent.META,{info:evt.info.code}); |
|---|
| 53 | subscribe = setInterval(doSubscribe,1000,getID(item['file'])); |
|---|
| 54 | } else { |
|---|
| 55 | super.statusHandler(evt); |
|---|
| 56 | } |
|---|
| 57 | }; |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | }; |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 63 | } |
|---|