emscripten Humble Cloud interface
Edward Rudd
2015-08-11 43635f08ebf7c813b69c0d02c39062f83b0826f3

add ability to register JS functions for the callbacks as well.

1 files modified
41 ■■■■ changed files
client/library/library_humble.js 41 ●●●● patch | view | raw | blame | history
client/library/library_humble.js
@@ -35,19 +35,32 @@
             */
            setPlayerFullscreen: null
        },
        _callCallback: function(callback, arg_types) {
            var cbInfo = HUMBLE_API.callbacks[callback];
            if (cbInfo == null) return false;
            var cb = cbInfo[0],
                data = cbInfo[1],
                js = cbInfo[2],
                args = Array.prototype.slice.call(arguments, 2);
            args.push(data);
            if (js) {
                cb.apply(null, args);
            } else {
                Runtime.dynCall(arg_types, cb, args);
            }
            return true;
        },
        /**
         * Attempts to call into the app to inform it that the volume should be adjusted
         * @param volume  the float volume (between 0.0 and 1.0)
         * @return bool.. true if the callback was successful.. false if no callback registered
         */
        setPlayerVolume: function(volume) {
            if (HUMBLE_API.callbacks.setPlayerVolume == null) return false;
            var cb = HUMBLE_API.callbacks.setPlayerVolume[0],
                data = HUMBLE_API.callbacks.setPlayerVolume[1];
            if (volume > 1.0) volume = 1.0;
            if (volume < 0.0) volume = 0.0;
            Runtime.dynCall('vdi', cb, [volume, data]);
            return true;
            return this._callCallback('setPlayerVolume', 'vdi', volume);
        },
        /**
         * Attempts to call into the app to inform it that it should change to or from fullscreen mode
@@ -55,11 +68,17 @@
         * @return bool.. true if the callback was successful.. false if no callback registered
         */
        setPlayerFullscreen: function(fullscreen) {
            if (HUMBLE_API.callbacks.setPlayerFullscreen == null) return false;
            var cb = HUMBLE_API.callbacks.setPlayerFullscreen[0],
                data = HUMBLE_API.callbacks.setPlayerFullscreen[1];
            Runtime.dynCall('vii', cb, [fullscreen ? 1 : 0, data]);
            return true;
            return this._callCallback('setPlayerFullscreen', 'vii', fullscreen ? 1 : 0);
        },
        /**
         * setCallback
         */
        setCallback: function(type, cb, data) {
            if (cb == null) {
                HUMBLE_API.callbacks[type] = null;
            } else {
                HUMBLE_API.callbacks[type] = [cb, data, true];
            }
        },
        /**
         * allows configuring the HUMBLE_API  simply call this method in a preRun to initialize..
@@ -282,7 +301,7 @@
        if (cb == 0) {
            HUMBLE_API.callbacks[key] = null;
        } else {
            HUMBLE_API.callbacks[key] = [cb, data];
            HUMBLE_API.callbacks[key] = [cb, data, false];
        }
        return 1;
    },