source: OpenRLabs-Git/web2py/applications/rlabs/static/js/guacamole-common-js/modules/AudioContextFactory.js

main
Last change on this file was 42bd667, checked in by David Fuertes <dfuertes@…>, 4 years ago

Historial Limpio

  • Property mode set to 100644
File size: 2.8 KB
Line 
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements.  See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership.  The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License.  You may obtain a copy of the License at
9 *
10 *   http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied.  See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20var Guacamole = Guacamole || {};
21
22/**
23 * Maintains a singleton instance of the Web Audio API AudioContext class,
24 * instantiating the AudioContext only in response to the first call to
25 * getAudioContext(), and only if no existing AudioContext instance has been
26 * provided via the singleton property. Subsequent calls to getAudioContext()
27 * will return the same instance.
28 *
29 * @namespace
30 */
31Guacamole.AudioContextFactory = {
32
33    /**
34     * A singleton instance of a Web Audio API AudioContext object, or null if
35     * no instance has yes been created. This property may be manually set if
36     * you wish to supply your own AudioContext instance, but care must be
37     * taken to do so as early as possible. Assignments to this property will
38     * not retroactively affect the value returned by previous calls to
39     * getAudioContext().
40     *
41     * @type {AudioContext}
42     */
43    'singleton' : null,
44
45    /**
46     * Returns a singleton instance of a Web Audio API AudioContext object.
47     *
48     * @return {AudioContext}
49     *     A singleton instance of a Web Audio API AudioContext object, or null
50     *     if the Web Audio API is not supported.
51     */
52    'getAudioContext' : function getAudioContext() {
53
54        // Fallback to Webkit-specific AudioContext implementation
55        var AudioContext = window.AudioContext || window.webkitAudioContext;
56
57        // Get new AudioContext instance if Web Audio API is supported
58        if (AudioContext) {
59            try {
60
61                // Create new instance if none yet exists
62                if (!Guacamole.AudioContextFactory.singleton)
63                    Guacamole.AudioContextFactory.singleton = new AudioContext();
64
65                // Return singleton instance
66                return Guacamole.AudioContextFactory.singleton;
67
68            }
69            catch (e) {
70                // Do not use Web Audio API if not allowed by browser
71            }
72        }
73
74        // Web Audio API not supported
75        return null;
76
77    }
78
79};
Note: See TracBrowser for help on using the repository browser.