summaryrefslogtreecommitdiffstats
path: root/webapp/app/static/music.html
blob: 154e5192e0f24883010ea61845cf3f5cc9244780 (plain) (blame)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<!DOCTYPE html>
<html lang="en">
    <head>
    </head>
    <body>
        <audio id="ocean_waves" controls loop>
            <source src="/static/ocean_waves.mp3" type="audio/mpeg">
        </audio>

        <audio id="seashore" controls loop>
            <source src="/static/seashore.mp3" type="audio/mpeg">
        </audio>

        <audio id="underwater" controls loop>
            <source src="/static/underwater.mp3" type="audio/mpeg">
        </audio>


        <audio id="jellyfish" controls>
            <source src="/static/jellyfish.mp3" type="audio/mpeg">
        </audio>

        <audio id="dolphin" controls>
            <source src="/static/dolphin.mp3" type="audio/mpeg">
        </audio>

        <audio id="boat" controls>
            <source src="/static/boat.mp3" type="audio/mpeg">
        </audio>

        <audio id="nemo" controls>
            <source src="/static/nemo.mp3" type="audio/mpeg">
        </audio>

        <audio id="dory" controls>
            <source src="/static/dory.mp3" type="audio/mpeg">
        </audio>

        <audio id="whale" controls>
            <source src="/static/whale.mp3" type="audio/mpeg">
        </audio>

        <audio id="eel" controls>
            <source src="/static/eel.mp3" type="audio/mpeg">
        </audio>

        <audio id="stingray" controls>
            <source src="/static/stingray.mp3" type="audio/mpeg">
        </audio>

        <audio id="shark" controls>
            <source src="/static/shark.mp3" type="audio/mpeg">
        </audio>

    <script type="text/javascript" src="//code.jquery.com/jquery-2.1.4.min.js"></script>
    <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/socket.io/1.3.5/socket.io.min.js"></script>

        <script>
        var currently_playing = undefined;
        function playBackground(id) {
            new_playing = document.getElementById(id)
            if( !new_playing ) {
                return;
            }

            if (currently_playing && currently_playing != new_playing) {
                currently_playing.pause();
            }
            currently_playing = new_playing;
            currently_playing.play();
        }

        function playEffect(id) {
            document.getElementById(id).play();
        }

        $(document).ready(function() {
            var namespace = '/music';
            socket = io.connect('http://' + document.domain + ':' + location.port + namespace);
            
            socket.on('connect', function() {
                console.log('connected!');
            });

            socket.on('disconnect', function() {
                console.log('disconnected');
            });


            socket.on('background', function(msg) {
                console.log('background', msg);
                playBackground(msg.id);
            });

            socket.on('effect', function(msg) {
                playEffect(msg.id);
            });

            socket.emit('ready');
            setInterval(function() {
                socket.emit('ready');
            }, 5000);
        });
        </script>
    </body>
</html>