root/trunk/as2/com/jeroenwijering/players/CallbackView.as @ 1

Revision 1, 2.6 kB (checked in by jeroen, 18 months ago)

initial commit of old repository into public one

  • Property svn:executable set to *
Line 
1/**
2* Callback to serverside script for statistics handling.
3* It sends the current file,title,id and state on start and complete.
4*
5* @author       Jeroen Wijering
6* @author       Nate Hanna
7* @version      1.7
8**/
9
10
11import com.jeroenwijering.players.*;
12
13
14class com.jeroenwijering.players.CallbackView extends AbstractView {
15
16
17        /** Currently playing item **/
18        private var currentItem:Number;
19        /** Currently playing item **/
20        private var varsObject:LoadVars;
21        /** Boolean for if a start call has already been sent for an item. **/
22        private var playSent:Boolean = false;
23        /** Small interval so both complete and play events won't be issued **/
24        private var playSentInt:Number;
25        /** Timestamp of the start of the movie **/
26        private var startStamp:Number;
27
28
29        /** Constructor **/
30        function CallbackView(ctr:AbstractController,cfg:Object,fed:Object) {
31                super(ctr,cfg,fed);
32                if(config['callback'] != "analytics") {
33                        varsObject = new LoadVars();
34                }
35        };
36
37
38        /** Send a callback on state change **/
39        private function setState(pr1:Number) {
40                var dat = new Date();
41                if(pr1 == 3) {
42                        var dur = Math.round(dat.valueOf()/1000 - startStamp);
43                        sendVars("stop",dur,true);
44                        playSent = false;
45                } else if (pr1 == 2 && playSent == false) {
46                        playSentInt = setInterval(this,"sendVars",500,"start",0);
47                        playSent = true;
48                        startStamp = dat.valueOf()/1000;
49                }
50        };
51
52
53        /** save the currently playing item **/
54        private function setItem(pr1:Number) {
55                if(playSent == true && currentItem != undefined)  {
56                        var dat = new Date();
57                        var dur = Math.round(dat.valueOf()/1000 - startStamp);
58                        sendVars("stop",dur,false);
59                        playSent = false;
60                }
61                currentItem = pr1;
62        };
63
64
65        /** sending the current file,title,id,state,timestamp to callback **/
66        private function sendVars(stt:String,dur:Number,cpl:Boolean) {
67                clearInterval(playSentInt);
68                if(config['callback'] == "urchin" || config['callback'] == "analytics") {
69                        var fil = feeder.feed[currentItem]["file"];
70                        var fcn = "javascript:pageTracker._trackPageview";
71                        if(config['callback'] == "urchin") {
72                                fcn = "javascript:urchinTracker";
73                        }
74                        if(fil.indexOf('http') != undefined) {
75                                fil = fil.substring(fil.indexOf('/',7)+1);
76                        }
77                        if(stt == "start") {
78                                getURL(fcn+"('/start_stream/"+fil+"');");
79                        } else if (stt == "stop" && cpl == true) {
80                                getURL(fcn+"('/end_stream/"+fil+"');");
81                        }
82                } else {
83                        varsObject.file = feeder.feed[currentItem]["file"];
84                        varsObject.title = feeder.feed[currentItem]["title"];
85                        varsObject.id = feeder.feed[currentItem]["id"];
86                        varsObject.state = stt;
87                        varsObject.duration = dur;
88                        varsObject.sendAndLoad(config["callback"],varsObject,"POST");
89                }
90        };
91
92
93}
Note: See TracBrowser for help on using the browser.