Skip to content

Commit 77e296b

Browse files
committed
ajax script to get waveform data from server
1 parent f78591b commit 77e296b

File tree

4 files changed

+126
-18
lines changed

4 files changed

+126
-18
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Thumbs.db
1717
desktop.ini
1818

1919
node_modules
20-
examples/client/scripts/vendor
20+
vendor
2121
yeoman
2222
nbproject
2323
.sass-cache

examples/client/scripts/library/event.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/**
22
*
33
* events manager
4+
*
45
* simplified events manager based on backbone.events
56
* extends this to add your own events manager
67
*
@@ -24,8 +25,6 @@ define([
2425
*/
2526
var eventsManager = function eventsManagerConstructor() {
2627

27-
//this.events = events;
28-
2928
this.events = events;
3029

3130
};
@@ -41,6 +40,12 @@ define([
4140
*/
4241
eventsManager.prototype.on = function onFunction(name, callback, context) {
4342

43+
if (name === undefined) {
44+
45+
return;
46+
47+
}
48+
4449
var eventsContainer;
4550

4651
if (!(name in this.events)) {
@@ -98,7 +103,11 @@ define([
98103
*/
99104
eventsManager.prototype.once = function onFunction(name, callback, context) {
100105

101-
//console.log('once');
106+
if (name === undefined) {
107+
108+
return;
109+
110+
}
102111

103112
var that = this;
104113

examples/client/scripts/main-test-data.js

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,18 @@ require.config({
1313
paths: {
1414
// vendor scripts
1515
'jquery': 'vendor/jquery/dist/jquery',
16-
'player': 'vendor/web-audio-api-player/source/player',
17-
'ajax': 'vendor/web-audio-api-player/source/ajax',
18-
'audio': 'vendor/web-audio-api-player/source/audio',
16+
17+
// player
18+
'player.core': 'vendor/web-audio-api-player/source/player',
19+
'player.audio': 'vendor/web-audio-api-player/source/audio',
1920

2021
// own small event manager for this example
2122
'event': 'library/event',
2223

2324
// waveform visualizer scripts
2425
'canvas': '../../../source/scripts/library/canvas',
25-
'waveform': '../../../source/scripts/library/waveform'
26+
'waveform': '../../../source/scripts/library/waveform',
27+
'waveform.ajax': 'vendor/web-audio-api-player/source/ajax'
2628
}
2729

2830
});
@@ -33,23 +35,20 @@ require.config({
3335
*
3436
* @param {type} $
3537
* @param {type} ajax
36-
* @param {type} Waveform
37-
* @param {type} canvas
3838
* @param {type} audio
39-
* @param {type} Player
39+
* @param {type} EventsManager
40+
*
4041
* @returns {undefined}
4142
*/
4243
require([
4344
'jquery',
44-
'ajax',
45-
'waveform',
46-
'canvas',
47-
'audio',
48-
'player'
45+
'waveform.ajax',
46+
'player.audio',
47+
'event'
4948

50-
], function ($, ajax, Waveform, canvas, audio, Player) {
49+
], function ($, ajax, audio, EventsManager) {
5150

52-
var addPlayer = function addPlayer(waveform, options) {
51+
var addPlayer = function addPlayer(options) {
5352

5453
// create an audio context
5554
var audioContext = audio.getContext();

source/scripts/library/ajax.js

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/**
2+
*
3+
* ajax
4+
*
5+
* @param {type} $
6+
* @returns {ajax_L7.ajaxAnonym$1}
7+
*/
8+
define([
9+
'jquery'
10+
11+
], function (
12+
$
13+
) {
14+
15+
'use strict';
16+
17+
/**
18+
*
19+
* get the peaks data from server
20+
*
21+
* @param {type} options
22+
* @param {type} callback
23+
* @returns {undefined}
24+
*/
25+
var getWaveDataFromServer = function getWaveDataFromServerFunction(options, callback) {
26+
27+
if (options === undefined) {
28+
29+
callback('options is undefined');
30+
31+
}
32+
33+
if (options.trackId === undefined) {
34+
35+
callback('trackId is undefined');
36+
37+
}
38+
39+
if (options.trackFormat === undefined) {
40+
41+
callback('trackFormat is undefined');
42+
43+
}
44+
45+
if (options.peaksAmount === undefined) {
46+
47+
callback('peaksAmount is undefined');
48+
49+
}
50+
51+
if (options.service === undefined) {
52+
53+
callback('service is undefined');
54+
55+
}
56+
57+
var request = $.ajax({
58+
url: '/getwavedata?trackId=' + options.trackId + '&trackFormat=' + options.trackFormat + '&peaksAmount=' + options.peaksAmount + '&service=' + options.service,
59+
type: 'GET',
60+
dataType: 'json'
61+
});
62+
63+
request.done(function(data) {
64+
65+
if (typeof data !== 'undefined' && data.peaks !== undefined) {
66+
67+
callback(false, data.peaks);
68+
69+
} else {
70+
71+
if (typeof data === 'undefined' || data.error === undefined) {
72+
73+
callback('undefined response from server');
74+
75+
} else {
76+
77+
callback(data.error);
78+
79+
}
80+
81+
}
82+
83+
});
84+
85+
request.fail(function(jqXHR, textStatus) {
86+
87+
callback(textStatus);
88+
89+
});
90+
91+
};
92+
93+
/**
94+
* public functions
95+
*/
96+
return {
97+
getWaveDataFromServer: getWaveDataFromServer
98+
};
99+
100+
});

0 commit comments

Comments
 (0)