|
1 IriSP.Widgets.Trace = function(player, config) { |
|
2 IriSP.Widgets.Widget.call(this, player, config); |
|
3 |
|
4 } |
|
5 |
|
6 IriSP.Widgets.Trace.prototype = new IriSP.Widgets.Widget(); |
|
7 |
|
8 IriSP.Widgets.Trace.prototype.defaults = { |
|
9 js_console : false, |
|
10 url: "http://traces.advene.org:5000/", |
|
11 requestmode: 'GET', |
|
12 syncmode: "sync" |
|
13 } |
|
14 |
|
15 IriSP.Widgets.Trace.prototype.draw = function() { |
|
16 this.lastEvent = ""; |
|
17 if (typeof window.tracemanager === "undefined") { |
|
18 console.log("Tracemanager not found"); |
|
19 return; |
|
20 } |
|
21 var _this = this, |
|
22 _listeners = { |
|
23 "IriSP.createAnnotationWidget.addedAnnotation" : 0, |
|
24 "IriSP.search.open" : 0, |
|
25 "IriSP.search.closed" : 0, |
|
26 "IriSP.search" : 0, |
|
27 "IriSP.search.cleared" : 0, |
|
28 "IriSP.search.matchFound" : 0, |
|
29 "IriSP.search.noMatchFound" : 0, |
|
30 "IriSP.search.triggeredSearch" : 0, |
|
31 "IriSP.TraceWidget.MouseEvents" : 0, |
|
32 "play" : 0, |
|
33 "pause" : 0, |
|
34 "volumechange" : 0, |
|
35 "seeked" : 0, |
|
36 "play" : 0, |
|
37 "pause" : 0, |
|
38 "timeupdate" : 2000 |
|
39 }; |
|
40 IriSP._(_listeners).each(function(_ms, _listener) { |
|
41 var _f = function(_arg) { |
|
42 _this.eventHandler(_listener, _arg); |
|
43 } |
|
44 if (_ms) { |
|
45 _f = IriSP._.throttle(_f, _ms); |
|
46 } |
|
47 _this.player.popcorn.listen(_listener, _f); |
|
48 }); |
|
49 this.player.popcorn.listen("timeupdate", IriSP._.throttle(function(_arg) { |
|
50 _this.eventHandler(_listener, _arg); |
|
51 })); |
|
52 |
|
53 this.tracer = window.tracemanager.init_trace("test", { |
|
54 url: this.url, |
|
55 requestmode: this.requestmode, |
|
56 syncmode: this.syncmode |
|
57 }); |
|
58 this.tracer.set_default_subject("metadataplayer"); |
|
59 this.tracer.trace("StartTracing", {}); |
|
60 |
|
61 this.mouseLocation = ''; |
|
62 IriSP.jQuery(".Ldt-Widget").bind("click mouseover mouseout dragstart dragstop", function(_e) { |
|
63 var _widget = IriSP.jQuery(this).attr("widget-type"), |
|
64 _class = _e.target.className; |
|
65 var _data = { |
|
66 "type": _e.type, |
|
67 "x": _e.clientX, |
|
68 "y": _e.clientY, |
|
69 "widget": _widget |
|
70 } |
|
71 if (typeof _class == "string" && _class.indexOf('Ldt-TraceMe') != -1) { |
|
72 var _name = _e.target.localName, |
|
73 _id = _e.target.id, |
|
74 _text = _e.target.textContent.trim(), |
|
75 _title = _e.target.title, |
|
76 _value = _e.target.value; |
|
77 _data.target = _name + (_id.length ? '#' + IriSP.jqEscape(_id) : '') + (_class.length ? ('.' + IriSP.jqEscape(_class).replace(/\s/g,'.')).replace(/\.Ldt-(Widget|TraceMe)/g,'') : ''); |
|
78 if (typeof _title == "string" && _title.length && _title.length < 140) { |
|
79 _data.title = _title; |
|
80 } |
|
81 if (typeof _text == "string" && _text.length && _text.length < 140) { |
|
82 _data.text = _text; |
|
83 } |
|
84 if (typeof _value == "string" && _value.length) { |
|
85 _data.value = _value; |
|
86 } |
|
87 this.player.popcorn.trigger('IriSP.TraceWidget.MouseEvents', _data); |
|
88 } else { |
|
89 //console.log(_e.type+','+_this.mouseLocation+','+_widget); |
|
90 if (_e.type == "mouseover") { |
|
91 if (_this.mouseLocation != _widget) { |
|
92 _this.player.popcorn.trigger('IriSP.TraceWidget.MouseEvents', _data); |
|
93 } else { |
|
94 if (typeof _this.moTimeout != "undefined") { |
|
95 clearTimeout(_this.moTimeout); |
|
96 delete _this.moTimeout; |
|
97 } |
|
98 } |
|
99 } |
|
100 if (_e.type == "click") { |
|
101 _this.player.popcorn.trigger('IriSP.TraceWidget.MouseEvents', _data); |
|
102 } |
|
103 if (_e.type == "mouseout") { |
|
104 if (typeof _this.moTimeout != "undefined") { |
|
105 clearTimeout(_this.moTimeout); |
|
106 } |
|
107 _this.moTimeout = setTimeout(function() { |
|
108 if (_data.widget != _this.mouseLocation) { |
|
109 _this.player.popcorn.trigger('IriSP.TraceWidget.MouseEvents', _data); |
|
110 } |
|
111 },100); |
|
112 } |
|
113 } |
|
114 _this.mouseLocation = _widget; |
|
115 }); |
|
116 } |
|
117 |
|
118 IriSP.Widgets.Trace.prototype.eventHandler = function(_listener, _arg) { |
|
119 var _traceName = 'Mdp_'; |
|
120 if (typeof _arg == "string" || typeof _arg == "number") { |
|
121 _arg = { "value" : _arg } |
|
122 } |
|
123 if (typeof _arg == "undefined") { |
|
124 _arg = {} |
|
125 } |
|
126 switch(_listener) { |
|
127 case 'IriSP.TraceWidget.MouseEvents': |
|
128 _traceName += _arg.widget + '_' + _arg.type; |
|
129 delete _arg.widget; |
|
130 delete _arg.type; |
|
131 break; |
|
132 case 'timeupdate': |
|
133 case 'play': |
|
134 case 'pause': |
|
135 _arg.time = this.player.popcorn.currentTime() * 1000; |
|
136 case 'seeked': |
|
137 case 'volumechange': |
|
138 _traceName += 'Popcorn_' + _listener; |
|
139 break; |
|
140 default: |
|
141 _traceName += _listener.replace('IriSP.','').replace('.','_'); |
|
142 } |
|
143 this.lastEvent = _traceName; |
|
144 this.tracer.trace(_traceName, _arg); |
|
145 if (this.js_console) { |
|
146 console.log("tracer.trace('" + _traceName + "', " + JSON.stringify(_arg) + ");"); |
|
147 } |
|
148 } |