You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@guacamole.apache.org by jm...@apache.org on 2016/04/01 00:30:29 UTC
[1/2] incubator-guacamole-client git commit: GUAC-1517: Maintain
singleton instance of AudioContext.
Repository: incubator-guacamole-client
Updated Branches:
refs/heads/master 065548fcd -> ac79cacea
GUAC-1517: Maintain singleton instance of AudioContext.
Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/commit/93783cf5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/tree/93783cf5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/diff/93783cf5
Branch: refs/heads/master
Commit: 93783cf5d5066ec2a23e2381b78ea49a3f4728fc
Parents: 065548f
Author: Michael Jumper <mj...@apache.org>
Authored: Thu Mar 31 15:12:29 2016 -0700
Committer: Michael Jumper <mj...@apache.org>
Committed: Thu Mar 31 15:22:49 2016 -0700
----------------------------------------------------------------------
.../main/webapp/modules/AudioContextFactory.js | 79 ++++++++++++++++++++
.../src/main/webapp/modules/AudioPlayer.js | 24 +-----
.../src/main/webapp/modules/AudioRecorder.js | 24 +-----
3 files changed, 85 insertions(+), 42 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/93783cf5/guacamole-common-js/src/main/webapp/modules/AudioContextFactory.js
----------------------------------------------------------------------
diff --git a/guacamole-common-js/src/main/webapp/modules/AudioContextFactory.js b/guacamole-common-js/src/main/webapp/modules/AudioContextFactory.js
new file mode 100644
index 0000000..f39ea35
--- /dev/null
+++ b/guacamole-common-js/src/main/webapp/modules/AudioContextFactory.js
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+var Guacamole = Guacamole || {};
+
+/**
+ * Maintains a singleton instance of the Web Audio API AudioContext class,
+ * instantiating the AudioContext only in response to the first call to
+ * getAudioContext(), and only if no existing AudioContext instance has been
+ * provided via the singleton property. Subsequent calls to getAudioContext()
+ * will return the same instance.
+ *
+ * @namespace
+ */
+Guacamole.AudioContextFactory = {
+
+ /**
+ * A singleton instance of a Web Audio API AudioContext object, or null if
+ * no instance has yes been created. This property may be manually set if
+ * you wish to supply your own AudioContext instance, but care must be
+ * taken to do so as early as possible. Assignments to this property will
+ * not retroactively affect the value returned by previous calls to
+ * getAudioContext().
+ *
+ * @type {AudioContext}
+ */
+ 'singleton' : null,
+
+ /**
+ * Returns a singleton instance of a Web Audio API AudioContext object.
+ *
+ * @return {AudioContext}
+ * A singleton instance of a Web Audio API AudioContext object, or null
+ * if the Web Audio API is not supported.
+ */
+ 'getAudioContext' : function getAudioContext() {
+
+ // Fallback to Webkit-specific AudioContext implementation
+ var AudioContext = window.AudioContext || window.webkitAudioContext;
+
+ // Get new AudioContext instance if Web Audio API is supported
+ if (AudioContext) {
+ try {
+
+ // Create new instance if none yet exists
+ if (!Guacamole.AudioContextFactory.singleton)
+ Guacamole.AudioContextFactory.singleton = new AudioContext();
+
+ // Return singleton instance
+ return Guacamole.AudioContextFactory.singleton;
+
+ }
+ catch (e) {
+ // Do not use Web Audio API if not allowed by browser
+ }
+ }
+
+ // Web Audio API not supported
+ return null;
+
+ }
+
+};
http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/93783cf5/guacamole-common-js/src/main/webapp/modules/AudioPlayer.js
----------------------------------------------------------------------
diff --git a/guacamole-common-js/src/main/webapp/modules/AudioPlayer.js b/guacamole-common-js/src/main/webapp/modules/AudioPlayer.js
index 881ef94..9cc6b3a 100644
--- a/guacamole-common-js/src/main/webapp/modules/AudioPlayer.js
+++ b/guacamole-common-js/src/main/webapp/modules/AudioPlayer.js
@@ -137,25 +137,7 @@ Guacamole.RawAudioPlayer = function RawAudioPlayer(stream, mimetype) {
* @private
* @type {AudioContext}
*/
- var context = (function getAudioContext() {
-
- // Fallback to Webkit-specific AudioContext implementation
- var AudioContext = window.AudioContext || window.webkitAudioContext;
-
- // Get new AudioContext instance if Web Audio API is supported
- if (AudioContext) {
- try {
- return new AudioContext();
- }
- catch (e) {
- // Do not use Web Audio API if not allowed by browser
- }
- }
-
- // Web Audio API not supported
- return null;
-
- })();
+ var context = Guacamole.AudioContextFactory.getAudioContext();
/**
* The earliest possible time that the next packet could play without
@@ -488,7 +470,7 @@ Guacamole.RawAudioPlayer.prototype = new Guacamole.AudioPlayer();
Guacamole.RawAudioPlayer.isSupportedType = function isSupportedType(mimetype) {
// No supported types if no Web Audio API
- if (!window.AudioContext && !window.webkitAudioContext)
+ if (!Guacamole.AudioContextFactory.getAudioContext())
return false;
return Guacamole.RawAudioFormat.parse(mimetype) !== null;
@@ -511,7 +493,7 @@ Guacamole.RawAudioPlayer.isSupportedType = function isSupportedType(mimetype) {
Guacamole.RawAudioPlayer.getSupportedTypes = function getSupportedTypes() {
// No supported types if no Web Audio API
- if (!window.AudioContext && !window.webkitAudioContext)
+ if (!Guacamole.AudioContextFactory.getAudioContext())
return [];
// We support 8-bit and 16-bit raw PCM
http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/93783cf5/guacamole-common-js/src/main/webapp/modules/AudioRecorder.js
----------------------------------------------------------------------
diff --git a/guacamole-common-js/src/main/webapp/modules/AudioRecorder.js b/guacamole-common-js/src/main/webapp/modules/AudioRecorder.js
index 34185ad..dff35d7 100644
--- a/guacamole-common-js/src/main/webapp/modules/AudioRecorder.js
+++ b/guacamole-common-js/src/main/webapp/modules/AudioRecorder.js
@@ -129,25 +129,7 @@ Guacamole.RawAudioRecorder = function RawAudioRecorder(stream, mimetype) {
* @private
* @type {AudioContext}
*/
- var context = (function getAudioContext() {
-
- // Fallback to Webkit-specific AudioContext implementation
- var AudioContext = window.AudioContext || window.webkitAudioContext;
-
- // Get new AudioContext instance if Web Audio API is supported
- if (AudioContext) {
- try {
- return new AudioContext();
- }
- catch (e) {
- // Do not use Web Audio API if not allowed by browser
- }
- }
-
- // Web Audio API not supported
- return null;
-
- })();
+ var context = Guacamole.AudioContextFactory.getAudioContext();
/**
* A function which directly invokes the browser's implementation of
@@ -289,7 +271,7 @@ Guacamole.RawAudioRecorder.prototype = new Guacamole.AudioRecorder();
Guacamole.RawAudioRecorder.isSupportedType = function isSupportedType(mimetype) {
// No supported types if no Web Audio API
- if (!window.AudioContext && !window.webkitAudioContext)
+ if (!Guacamole.AudioContextFactory.getAudioContext())
return false;
return Guacamole.RawAudioFormat.parse(mimetype) !== null;
@@ -312,7 +294,7 @@ Guacamole.RawAudioRecorder.isSupportedType = function isSupportedType(mimetype)
Guacamole.RawAudioRecorder.getSupportedTypes = function getSupportedTypes() {
// No supported types if no Web Audio API
- if (!window.AudioContext && !window.webkitAudioContext)
+ if (!Guacamole.AudioContextFactory.getAudioContext())
return [];
// We support 8-bit and 16-bit raw PCM
[2/2] incubator-guacamole-client git commit: GUAC-1517: Merge PR for
only creating one AudioContext.
Posted by jm...@apache.org.
GUAC-1517: Merge PR for only creating one AudioContext.
Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/commit/ac79cace
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/tree/ac79cace
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/diff/ac79cace
Branch: refs/heads/master
Commit: ac79cacea09e74c304ba0d92c8e67fef24078dec
Parents: 065548f 93783cf
Author: James Muehlner <ja...@guac-dev.org>
Authored: Thu Mar 31 15:29:42 2016 -0700
Committer: James Muehlner <ja...@guac-dev.org>
Committed: Thu Mar 31 15:29:42 2016 -0700
----------------------------------------------------------------------
.../main/webapp/modules/AudioContextFactory.js | 79 ++++++++++++++++++++
.../src/main/webapp/modules/AudioPlayer.js | 24 +-----
.../src/main/webapp/modules/AudioRecorder.js | 24 +-----
3 files changed, 85 insertions(+), 42 deletions(-)
----------------------------------------------------------------------