-
Notifications
You must be signed in to change notification settings - Fork 0
/
io.js
executable file
·63 lines (58 loc) · 1.68 KB
/
io.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
'use strict'
var mongoose = require('mongoose');
var Song = mongoose.model('Song');
var camanTransform = require('./camanTransform');
var soundTransform = require('./transform');
module.exports = (function(io) {
console.log('Assigning io events');
io.on('connection', function(_io) {
_io.on('getOneSong', function(id) {
Song.find({filename: id}).limit(1).exec(function(err, song){
_io.emit('getOneSong', {
error: null,
data: ((song.length > 0) ? song[0] : null)
});
});
});
_io.on('getAllSongs', function() {
Song.find({}).sort([['created', -1]]).exec(function(err, songs) {
_io.emit('getAllSongs', {
error: null,
data: songs
});
});
});
_io.on('camanTransform', function(data) {
Song.find({filename: data.id}).limit(1).exec(function(err, song) {
if (!err) {
camanTransform(data.id, data.filters, function() {
_io.emit('camanTransform', {
error: null,
data: data.id
});
console.log("caman transform complete for "+data.id);
});
} else {
_io.emit('camanTransform', {
error: null,
data: null
});
}
});
});
_io.on('camanToAudio', function(data) {
// make sure song exists in db
Song.find({filename: data.id}).limit(1).exec(function(err, song) {
if (!err) {
soundTransform.pic(data.id, function() {
// emit to all with io
io.emit('camanToAudio', {
error: null,
data: data.id,
});
});
}
});
});
});
});