code
stringlengths
24
2.07M
docstring
stringlengths
25
85.3k
func_name
stringlengths
1
92
language
stringclasses
1 value
repo
stringlengths
5
64
path
stringlengths
4
172
url
stringlengths
44
218
license
stringclasses
7 values
async getRepoFromPath(currentRepo, token, cb) { if (!detect.shouldEnable()) { return cb(); } await this.getRepoData(currentRepo, token, cb); }
Github renders the branch name in one of below structure depending on the length of branch name. We're using this for default code page or tree/blob. Option 1: when the length is short enough <summary title="Switch branches or tags"> <span class="css-truncate-target">feature/1/2/3</span> </summary> Option 2: when the length is too long <summary title="feature/1/2/3/4/5/6/7/8"> <span class="css-truncate-target">feature/1/2/3...</span> </summary>
getRepoFromPath
javascript
ineo6/git-master
src/common/adapters/gogs.js
https://github.com/ineo6/git-master/blob/master/src/common/adapters/gogs.js
MIT
loadCodeTree(opts, cb) { opts.encodedBranch = encodeURIComponent(decodeURIComponent(opts.repo.branch)); opts.path = (opts.node && (opts.node.sha || opts.encodedBranch)) || opts.encodedBranch + '?recursive=1'; this._loadCodeTreeInternal(opts, null, cb); }
Github renders the branch name in one of below structure depending on the length of branch name. We're using this for default code page or tree/blob. Option 1: when the length is short enough <summary title="Switch branches or tags"> <span class="css-truncate-target">feature/1/2/3</span> </summary> Option 2: when the length is too long <summary title="feature/1/2/3/4/5/6/7/8"> <span class="css-truncate-target">feature/1/2/3...</span> </summary>
loadCodeTree
javascript
ineo6/git-master
src/common/adapters/gogs.js
https://github.com/ineo6/git-master/blob/master/src/common/adapters/gogs.js
MIT
selectFile(path) { window.location.href = path; }
Github renders the branch name in one of below structure depending on the length of branch name. We're using this for default code page or tree/blob. Option 1: when the length is short enough <summary title="Switch branches or tags"> <span class="css-truncate-target">feature/1/2/3</span> </summary> Option 2: when the length is too long <summary title="feature/1/2/3/4/5/6/7/8"> <span class="css-truncate-target">feature/1/2/3...</span> </summary>
selectFile
javascript
ineo6/git-master
src/common/adapters/gogs.js
https://github.com/ineo6/git-master/blob/master/src/common/adapters/gogs.js
MIT
getItemHref(repo, type, encodedPath, encodedBranch) { return `/${repo.username}/${repo.reponame}/src/${encodedBranch}/${encodedPath}`; }
Github renders the branch name in one of below structure depending on the length of branch name. We're using this for default code page or tree/blob. Option 1: when the length is short enough <summary title="Switch branches or tags"> <span class="css-truncate-target">feature/1/2/3</span> </summary> Option 2: when the length is too long <summary title="feature/1/2/3/4/5/6/7/8"> <span class="css-truncate-target">feature/1/2/3...</span> </summary>
getItemHref
javascript
ineo6/git-master
src/common/adapters/gogs.js
https://github.com/ineo6/git-master/blob/master/src/common/adapters/gogs.js
MIT
getAccessToken() { return window.extStore.get(window.STORE.GOGS_TOKEN); }
Github renders the branch name in one of below structure depending on the length of branch name. We're using this for default code page or tree/blob. Option 1: when the length is short enough <summary title="Switch branches or tags"> <span class="css-truncate-target">feature/1/2/3</span> </summary> Option 2: when the length is too long <summary title="feature/1/2/3/4/5/6/7/8"> <span class="css-truncate-target">feature/1/2/3...</span> </summary>
getAccessToken
javascript
ineo6/git-master
src/common/adapters/gogs.js
https://github.com/ineo6/git-master/blob/master/src/common/adapters/gogs.js
MIT
get isOnPRPage() { // eslint-disable-next-line no-useless-escape const match = window.location.pathname.match(/([^\/]+)\/([^\/]+)(?:\/([^\/]+))?(?:\/([^\/]+))?/); if (!match) return false; const type = match[3]; return type === 'pulls'; }
Github renders the branch name in one of below structure depending on the length of branch name. We're using this for default code page or tree/blob. Option 1: when the length is short enough <summary title="Switch branches or tags"> <span class="css-truncate-target">feature/1/2/3</span> </summary> Option 2: when the length is too long <summary title="feature/1/2/3/4/5/6/7/8"> <span class="css-truncate-target">feature/1/2/3...</span> </summary>
isOnPRPage
javascript
ineo6/git-master
src/common/adapters/gogs.js
https://github.com/ineo6/git-master/blob/master/src/common/adapters/gogs.js
MIT
_getTree(path, opts, cb) { this._get(`/git/trees/${path}`, opts, (err, res) => { if (err) { cb(err); } else { cb(null, res.tree); } }); }
Github renders the branch name in one of below structure depending on the length of branch name. We're using this for default code page or tree/blob. Option 1: when the length is short enough <summary title="Switch branches or tags"> <span class="css-truncate-target">feature/1/2/3</span> </summary> Option 2: when the length is too long <summary title="feature/1/2/3/4/5/6/7/8"> <span class="css-truncate-target">feature/1/2/3...</span> </summary>
_getTree
javascript
ineo6/git-master
src/common/adapters/gogs.js
https://github.com/ineo6/git-master/blob/master/src/common/adapters/gogs.js
MIT
_getPatch(opts, cb) { const { pullNumber } = opts.repo; this._get(`/pulls/${pullNumber}/files?per_page=300`, opts, (err, res) => { if (err) { cb(err); } else { const diffMap = {}; res.forEach((file, index) => { // Record file patch info diffMap[file.filename] = { type: 'blob', diffId: index, action: file.status, additions: file.additions, blob_url: file.blob_url, deletions: file.deletions, filename: file.filename, path: file.path, sha: file.sha, }; // Record ancestor folders const folderPath = file.filename .split('/') .slice(0, -1) .join('/'); const split = folderPath.split('/'); // Aggregate metadata for ancestor folders split.reduce((path, curr) => { if (path.length) { path = `${path}/${curr}`; } else { path = `${curr}`; } if (diffMap[path] == null) { diffMap[path] = { type: 'tree', filename: path, filesChanged: 1, additions: file.additions, deletions: file.deletions, }; } else { diffMap[path].additions += file.additions; diffMap[path].deletions += file.deletions; diffMap[path].filesChanged++; } return path; }, ''); }); // Transform to emulate response from get `tree` const tree = Object.keys(diffMap).map(fileName => { const patch = diffMap[fileName]; return { patch, path: fileName, sha: patch.sha, type: patch.type, url: patch.blob_url, }; }); // Sort by path, needs to be alphabetical order (so parent folders come before children) // Note: this is still part of the above transform to mimic the behavior of get tree tree.sort((a, b) => a.path.localeCompare(b.path)); cb(null, tree); } }); }
Get files that were patched in Pull Request. The diff map that is returned contains changed files, as well as the parents of the changed files. This allows the tree to be filtered for only folders that contain files with diffs. @param {Object} opts: { path: the starting path to load the tree, repo: the current repository, node (optional): the selected node (null to load entire tree), token (optional): the personal access token } @param {Function} cb(err: error, diffMap: Object)
_getPatch
javascript
ineo6/git-master
src/common/adapters/gogs.js
https://github.com/ineo6/git-master/blob/master/src/common/adapters/gogs.js
MIT
_getSubmodules(tree, opts, cb) { const item = tree.filter(item => /^\.gitmodules$/i.test(item.path))[0]; if (!item) return cb(); this._get(`/git/blobs/${item.sha}`, opts, (err, res) => { if (err) return cb(err); const data = atob(res.content.replace(/\n/g, '')); cb(null, parseGitmodules(data)); }); }
Get files that were patched in Pull Request. The diff map that is returned contains changed files, as well as the parents of the changed files. This allows the tree to be filtered for only folders that contain files with diffs. @param {Object} opts: { path: the starting path to load the tree, repo: the current repository, node (optional): the selected node (null to load entire tree), token (optional): the personal access token } @param {Function} cb(err: error, diffMap: Object)
_getSubmodules
javascript
ineo6/git-master
src/common/adapters/gogs.js
https://github.com/ineo6/git-master/blob/master/src/common/adapters/gogs.js
MIT
async loadRepoData(path, isRepoMetaData = false) { const token = await this.getAccessToken(); try { const repo = await this.getRepoDataWrap(false, token); if (repo) { const data = await this.getContent(path, { repo, isRepoMetaData, }); return { repo, contentData: data, }; } } catch (e) { return false; } }
Get files that were patched in Pull Request. The diff map that is returned contains changed files, as well as the parents of the changed files. This allows the tree to be filtered for only folders that contain files with diffs. @param {Object} opts: { path: the starting path to load the tree, repo: the current repository, node (optional): the selected node (null to load entire tree), token (optional): the personal access token } @param {Function} cb(err: error, diffMap: Object)
loadRepoData
javascript
ineo6/git-master
src/common/adapters/gogs.js
https://github.com/ineo6/git-master/blob/master/src/common/adapters/gogs.js
MIT
getContentPath() { let str = window.location.href; let result = str.match(/.*[bt][lr][oe][be]\/[^//]+\/(.*)/); // blob/tree :D return result && result.length && result[1]; }
Get files that were patched in Pull Request. The diff map that is returned contains changed files, as well as the parents of the changed files. This allows the tree to be filtered for only folders that contain files with diffs. @param {Object} opts: { path: the starting path to load the tree, repo: the current repository, node (optional): the selected node (null to load entire tree), token (optional): the personal access token } @param {Function} cb(err: error, diffMap: Object)
getContentPath
javascript
ineo6/git-master
src/common/adapters/gogs.js
https://github.com/ineo6/git-master/blob/master/src/common/adapters/gogs.js
MIT
async getContent(path, opts) { const host = window.location.protocol + '//' + (window.location.host + '/api/v1'); const url = `${host}/repos/${opts.repo.username}/${opts.repo.reponame}`; const contentPath = path || this.getContentPath() || ''; let contentParams = ''; const branch = encodeURIComponent(decodeURIComponent(opts.repo.branch)); if (!opts.isRepoMetaData) { contentParams = '/contents/' + contentPath + '?ref=' + branch; } const cfg = { url: `${url}${contentParams}`, method: 'GET', cache: false, }; const token = await this.getAccessToken(); if (token) { cfg.headers = { Authorization: 'token ' + token }; } return new Promise((resolve, reject) => { $.ajax(cfg) .done((data, textStatus, jqXHR) => { resolve(data, jqXHR); }) .fail(jqXHR => this._handleError(cfg, jqXHR, resolve)); }); }
Get files that were patched in Pull Request. The diff map that is returned contains changed files, as well as the parents of the changed files. This allows the tree to be filtered for only folders that contain files with diffs. @param {Object} opts: { path: the starting path to load the tree, repo: the current repository, node (optional): the selected node (null to load entire tree), token (optional): the personal access token } @param {Function} cb(err: error, diffMap: Object)
getContent
javascript
ineo6/git-master
src/common/adapters/gogs.js
https://github.com/ineo6/git-master/blob/master/src/common/adapters/gogs.js
MIT
_get(path, opts, cb) { let url; if (path && path.startsWith('http')) { url = path; } else { const host = window.location.protocol + '//' + (window.location.host + '/api/v1'); url = `${host}/repos/${opts.repo.username}/${opts.repo.reponame}${path || ''}`; } const cfg = { url, method: 'GET', cache: false, }; if (opts.token) { cfg.headers = { Authorization: 'token ' + opts.token }; } $.ajax(cfg) .done((data, textStatus, jqXHR) => { (async () => { if (path && path.indexOf('/git/trees') === 0 && data.truncated) { try { const hugeRepos = await extStore.get(STORE.HUGE_REPOS); const repo = `${opts.repo.username}/${opts.repo.reponame}`; const repos = Object.keys(hugeRepos).filter(hugeRepoKey => isValidTimeStamp(hugeRepos[hugeRepoKey])); if (!hugeRepos[repo]) { // If there are too many repos memoized, delete the oldest one if (repos.length >= GH_MAX_HUGE_REPOS_SIZE) { const oldestRepo = repos.reduce((min, p) => (hugeRepos[p] < hugeRepos[min] ? p : min)); delete hugeRepos[oldestRepo]; } hugeRepos[repo] = new Date().getTime(); await extStore.set(STORE.HUGE_REPOS, hugeRepos); } // eslint-disable-next-line no-empty } catch (ignored) { } finally { await this._handleError(cfg, { status: 206 }, cb); } } else { cb(null, data, jqXHR); } })(); }) .fail(jqXHR => this._handleError(cfg, jqXHR, cb)); }
Get files that were patched in Pull Request. The diff map that is returned contains changed files, as well as the parents of the changed files. This allows the tree to be filtered for only folders that contain files with diffs. @param {Object} opts: { path: the starting path to load the tree, repo: the current repository, node (optional): the selected node (null to load entire tree), token (optional): the personal access token } @param {Function} cb(err: error, diffMap: Object)
_get
javascript
ineo6/git-master
src/common/adapters/gogs.js
https://github.com/ineo6/git-master/blob/master/src/common/adapters/gogs.js
MIT
_handlePjaxEvent(event, gitmasterEventName, pjaxEventName) { // Avoid re-entrance, which would blow the callstack. Because dispatchEvent() is synchronous, it's possible // for badly implemented handler from another extension to prevent legit event handling if users navigate // among files too quickly. Hopefully none is that bad. We'll deal with it IFF it happens. if (this._isDispatching) { return; } this._isDispatching = true; try { $(document).trigger(gitmasterEventName); // Only dispatch to native DOM if the event is started by gitmaster. If the event is started in the DOM, jQuery // wraps it in the originalEvent property, that's what we use to check. Fixes #864. if (event.originalEvent === null) { this._dispatchPjaxEventInDom(pjaxEventName); } } finally { this._isDispatching = false; } }
Event handler of pjax events. @api private
_handlePjaxEvent
javascript
ineo6/git-master
src/common/adapters/pjax.js
https://github.com/ineo6/git-master/blob/master/src/common/adapters/pjax.js
MIT
_dispatchPjaxEventInDom(type) { const pjaxContainer = $(this._pjaxContainerSel)[0]; if (pjaxContainer) { pjaxContainer.dispatchEvent( new Event(type, { bubbles: true, }) ); } }
Dispatches a pjax event directly in the DOM. GitHub's own pjax implementation dispatches its events directly in the DOM, while the jQuery pjax library we use dispatches its events (during selectFile()) only within its jQuery instance. Because some GitHub add-ons listen to certain pjax events in the DOM it may be necessary to forward an event from jQuery to the DOM to make sure those add-ons don't break. Note that we don't forward the details/extra parameters or whether they're cancellable, because the pjax implementations differ in this case! @see https://github.com/ovity/octotree/issues/490 @param {string} type The name of the event @api private
_dispatchPjaxEventInDom
javascript
ineo6/git-master
src/common/adapters/pjax.js
https://github.com/ineo6/git-master/blob/master/src/common/adapters/pjax.js
MIT
_patchPjax() { // The pjax plugin ($.pjax) is loaded in same time with Octotree (document ready event) and // we don't know when $.pjax fully loaded, so we will do patching once in runtime if (this._$pjaxPatched) return; /** * At this moment, when users are on Github Code page, Github sometime refreshes the page when * a file is clicked on its file list. Internally, Github uses pjax * (a jQuery plugin - defunkt/jquery-pjax) to fetch the file content being selected, and there is * a change on Github's server rendering that cause the refreshing problem. And this also impacts * on Octotree where Github page refreshes when users select a file in Octotree's sidebar * * The refresh happens due to this code https://github.com/defunkt/jquery-pjax/blob/c9acf5e7e9e16fdd34cb2de882d627f97364a952/jquery.pjax.js#L272. * * While waiting for Github to solve the wrong refreshing, below code is a hacking fix that * Octotree won't trigger refreshing when a file selected in sidebar (but Github still refreshes * if file selected at Github file view) */ $.pjax.defaults.version = function() { // Disables checking layout version to prevent refreshing in pjax library return null; }; this._$pjaxPatched = true; }
Dispatches a pjax event directly in the DOM. GitHub's own pjax implementation dispatches its events directly in the DOM, while the jQuery pjax library we use dispatches its events (during selectFile()) only within its jQuery instance. Because some GitHub add-ons listen to certain pjax events in the DOM it may be necessary to forward an event from jQuery to the DOM to make sure those add-ons don't break. Note that we don't forward the details/extra parameters or whether they're cancellable, because the pjax implementations differ in this case! @see https://github.com/ovity/octotree/issues/490 @param {string} type The name of the event @api private
_patchPjax
javascript
ineo6/git-master
src/common/adapters/pjax.js
https://github.com/ineo6/git-master/blob/master/src/common/adapters/pjax.js
MIT
function round(value) { return Math.round(value * 10) / 10; }
Given a number of seconds, returns a String representing that length of time in a human-readable format. @param {Number} seconds The number of seconds. @return {String} A human-readable description of the duration specified.
round
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/admin-ui.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/admin-ui.js
MIT
function updateKeyboardSize() { var currentSize = keyboard.getElement().offsetWidth; if (last_keyboard_width != currentSize) { keyboard.resize(currentSize); last_keyboard_width = currentSize; } }
Event target. This is a hidden textarea element which will receive key events. @private
updateKeyboardSize
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/client-ui.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/client-ui.js
MIT
function force_reconnect() { if (!reconnect_forced) { reconnect_forced = true; window.clearInterval(reconnect_interval); GuacUI.Client.connect(); } }
Stops the reconnect countdown and forces a client reconnect.
force_reconnect
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/client-ui.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/client-ui.js
MIT
function update_status() { // Use appropriate description of time remaining if (reconnect === 0) countdown.textContent = "Reconnecting..."; if (reconnect === 1) countdown.textContent = "Reconnecting in 1 second..."; else countdown.textContent = "Reconnecting in " + reconnect + " seconds..."; // Reconnect if countdown complete if (reconnect === 0) force_reconnect(); }
Stops the reconnect countdown and forces a client reconnect.
update_status
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/client-ui.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/client-ui.js
MIT
function pinch_distance(e) { var touch_a = e.touches[0]; var touch_b = e.touches[1]; var delta_x = touch_a.clientX - touch_b.clientX; var delta_y = touch_a.clientY - touch_b.clientY; return Math.sqrt(delta_x*delta_x + delta_y*delta_y); }
Given a touch event, calculates the distance between the first two touches in pixels. @param {TouchEvent} e The touch event to use when performing distance calculation. @return {Number} The distance in pixels between the first two touches.
pinch_distance
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/client-ui.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/client-ui.js
MIT
function pinch_center_x(e) { var touch_a = e.touches[0]; var touch_b = e.touches[1]; return (touch_a.clientX + touch_b.clientX) / 2; }
Given a touch event, calculates the center between the first two touches in pixels, returning the X coordinate of this center. @param {TouchEvent} e The touch event to use when performing center calculation. @return {Number} The X-coordinate of the center of the first two touches.
pinch_center_x
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/client-ui.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/client-ui.js
MIT
function pinch_center_y(e) { var touch_a = e.touches[0]; var touch_b = e.touches[1]; return (touch_a.clientY + touch_b.clientY) / 2; }
Given a touch event, calculates the center between the first two touches in pixels, returning the Y coordinate of this center. @param {TouchEvent} e The touch event to use when performing center calculation. @return {Number} The Y-coordinate of the center of the first two touches.
pinch_center_y
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/client-ui.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/client-ui.js
MIT
function __handle_mouse_state(mouseState) { // Get client - do nothing if not attached var guac = GuacUI.Client.attachedClient; if (!guac) return; // Determine mouse position within view var guac_display = guac.getDisplay().getElement(); var mouse_view_x = mouseState.x + guac_display.offsetLeft - GuacUI.Client.main.scrollLeft; var mouse_view_y = mouseState.y + guac_display.offsetTop - GuacUI.Client.main.scrollTop; // Determine viewport dimensioins var view_width = GuacUI.Client.main.offsetWidth; var view_height = GuacUI.Client.main.offsetHeight; // Determine scroll amounts based on mouse position relative to document var scroll_amount_x; if (mouse_view_x > view_width) scroll_amount_x = mouse_view_x - view_width; else if (mouse_view_x < 0) scroll_amount_x = mouse_view_x; else scroll_amount_x = 0; var scroll_amount_y; if (mouse_view_y > view_height) scroll_amount_y = mouse_view_y - view_height; else if (mouse_view_y < 0) scroll_amount_y = mouse_view_y; else scroll_amount_y = 0; // Scroll (if necessary) to keep mouse on screen. GuacUI.Client.main.scrollLeft += scroll_amount_x; GuacUI.Client.main.scrollTop += scroll_amount_y; // Scale event by current scale var scaledState = new Guacamole.Mouse.State( mouseState.x / guac.getDisplay().getScale(), mouseState.y / guac.getDisplay().getScale(), mouseState.left, mouseState.middle, mouseState.right, mouseState.up, mouseState.down); // Send mouse event guac.sendMouseState(scaledState); }
Sets the mouse emulation mode to absolute or relative. @param {Boolean} absolute Whether mouse emulation should use absolute (touchscreen) mode.
__handle_mouse_state
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/client-ui.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/client-ui.js
MIT
function __send_key(pressed, keysym) { if (GuacUI.Client.isMenuShown() || !GuacUI.Client.text_input.enabled) return true; if(lastCtrl){ if(keysym !== 99 && keysym !== 118 && keysym !== 120){ GuacUI.Client.attachedClient.sendKeyEvent(1, lastCtrl); lastCtrl = false; } } if(keysym === 0xFFE3 || keysym === 0xFFE4){ lastCtrl = pressed ? keysym : false; } if(CTRL_KEYS[keysym] && ctrlKeyCount > -1){ ctrlKeyCount += (pressed?1:-1); } if((keysym > 0xFF || ctrlKeyCount > 0) && lastCtrl === false){ GuacUI.Client.attachedClient.sendKeyEvent(pressed, keysym); return false; } return true; }
Attaches a Guacamole.Client to the client UI, such that Guacamole events affect the UI, and local events affect the Guacamole.Client. If a client is already attached, it is replaced. @param {Guacamole.Client} guac The Guacamole.Client to attach to the UI.
__send_key
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/client-ui.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/client-ui.js
MIT
function __update_layout() { // Only reflow if size or scroll have changed if (document.body.scrollLeft !== last_scroll_left || document.body.scrollTop !== last_scroll_top || document.body.scrollWidth !== last_scroll_width || document.body.scrollHeight !== last_scroll_height || window.innerWidth !== last_window_width || window.innerHeight !== last_window_height) { last_scroll_top = document.body.scrollTop; last_scroll_left = document.body.scrollLeft; last_scroll_width = document.body.scrollWidth; last_scroll_height = document.body.scrollHeight; last_window_width = window.innerWidth; last_window_height = window.innerHeight; // Reset scroll and reposition document such that it's on-screen window.scrollTo(document.body.scrollWidth, document.body.scrollHeight); // Determine height of bottom section (currently only text input) var bottom = GuacUI.Client.text_input.container; var bottom_height = (bottom && bottom.offsetHeight) | 0; // Calculate correct height of main section (display) var main_width = window.innerWidth; var main_height = window.innerHeight - bottom_height; // Anchor main to top-left of viewport, sized to fit above bottom var main = GuacUI.Client.main; main.style.top = document.body.scrollTop + "px"; main.style.left = document.body.scrollLeft + "px"; main.style.width = main_width + "px"; main.style.height = main_height + "px"; // Send new size if (GuacUI.Client.attachedClient) { var pixel_density = window.devicePixelRatio || 1; var width = main_width * pixel_density; var height = main_height * pixel_density; GuacUI.Client.attachedClient.sendSize(width, height); } // Rescale display appropriately GuacUI.Client.updateDisplayScale(); } }
Attaches a Guacamole.Client to the client UI, such that Guacamole events affect the UI, and local events affect the Guacamole.Client. If a client is already attached, it is replaced. @param {Guacamole.Client} guac The Guacamole.Client to attach to the UI.
__update_layout
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/client-ui.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/client-ui.js
MIT
function _ignore(e) { e.preventDefault(); e.stopPropagation(); }
Ignores the given event. @private @param {Event} e The event to ignore.
_ignore
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/client-ui.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/client-ui.js
MIT
function _get_base64(bytes) { var data = ""; // Produce binary string from bytes in buffer for (var i=0; i<bytes.byteLength; i++) data += String.fromCharCode(bytes[i]); // Convert to base64 return window.btoa(data); }
Converts the given bytes to a base64-encoded string. @private @param {Uint8Array} bytes A Uint8Array which contains the data to be encoded as base64. @return {String} The base64-encoded string.
_get_base64
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/client-ui.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/client-ui.js
MIT
function _upload_file(file) { // Construct reader for file var reader = new FileReader(); reader.onloadend = function() { // Add upload notification var upload = new GuacUI.Upload(file.name); upload.updateProgress(GuacUI.Client.getSizeString(0), 0); GuacUI.Client.notification_area.appendChild(upload.getElement()); // Open file for writing var stream = GuacUI.Client.attachedClient.createFileStream(file.type, file.name); var valid = true; var bytes = new Uint8Array(reader.result); var offset = 0; // Invalidate stream on all errors // Continue upload when acknowledged stream.onack = function(status) { // Handle errors if (status.isError()) { valid = false; var message = GuacUI.Client.upload_errors[status.code] || GuacUI.Client.upload_errors.DEFAULT; upload.showError(message); } // Abort upload if stream is invalid if (!valid) return false; // Encode packet as base64 var slice = bytes.subarray(offset, offset+4096); var base64 = _get_base64(slice); // Write packet stream.sendBlob(base64); // Advance to next packet offset += 4096; // If at end, stop upload if (offset >= bytes.length) { stream.sendEnd(); GuacUI.Client.notification_area.removeChild(upload.getElement()); GuacUI.Client.showNotification("Upload of \"" + file.name + "\" complete."); } // Otherwise, update progress else upload.updateProgress(GuacUI.Client.getSizeString(offset), offset / bytes.length * 100); }; // Close dialog and abort when close is clicked upload.onclose = function() { GuacUI.Client.notification_area.removeChild(upload.getElement()); // TODO: Abort transfer }; }; reader.readAsArrayBuffer(file); }
Uploads the given file to the server. @private @param {File} file The file to upload.
_upload_file
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/client-ui.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/client-ui.js
MIT
function keysym_from_codepoint(codepoint) { // Keysyms for control characters if (codepoint <= 0x1F || (codepoint >= 0x7F && codepoint <= 0x9F)) return 0xFF00 | codepoint; // Keysyms for ASCII chars if (codepoint >= 0x0000 && codepoint <= 0x00FF) return codepoint; // Keysyms for Unicode if (codepoint >= 0x0100 && codepoint <= 0x10FFFF) return 0x01000000 | codepoint; return null; }
Uploads the given file to the server. @private @param {File} file The file to upload.
keysym_from_codepoint
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/client-ui.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/client-ui.js
MIT
function send_keysym(keysym) { var guac = GuacUI.Client.attachedClient; if (!guac) return; guac.sendKeyEvent(1, keysym); guac.sendKeyEvent(0, keysym); }
Presses and releases the key corresponding to the given keysym, as if typed by the user. @param {Number} keysym The keysym of the key to send.
send_keysym
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/client-ui.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/client-ui.js
MIT
function send_codepoint(codepoint) { if (codepoint === 10) { send_keysym(0xFF0D); release_sticky_keys(); return; } var keysym = keysym_from_codepoint(codepoint); if (keysym) { send_keysym(keysym); release_sticky_keys(); } }
Presses and releases the key having the keysym corresponding to the Unicode codepoint given, as if typed by the user. @param {Number} codepoint The Unicode codepoint of the key to send.
send_codepoint
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/client-ui.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/client-ui.js
MIT
function send_string(content) { var sent_text = ""; for (var i=0; i<content.length; i++) { var codepoint = content.charCodeAt(i); if (codepoint !== GuacUI.Client.TEXT_INPUT_PADDING_CODEPOINT) { sent_text += String.fromCharCode(codepoint); send_codepoint(codepoint); } } // Display the text that was sent var notify_sent = GuacUI.createChildElement(GuacUI.Client.text_input.sent, "div", "sent-text"); notify_sent.textContent = sent_text; // Remove text after one second window.setTimeout(function __remove_notify_sent() { notify_sent.parentNode.removeChild(notify_sent); }, 1000); }
Translates each character within the given string to keysyms and sends each, in order, as if typed by the user. @param {String} content The string to send.
send_string
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/client-ui.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/client-ui.js
MIT
function apply_key_behavior(key) { function __update_key(e) { var guac = GuacUI.Client.attachedClient; if (!guac) return; e.preventDefault(); e.stopPropagation(); // Pull properties of key var keysym = parseInt(key.getAttribute("data-keysym")); var sticky = (key.getAttribute("data-sticky") === "true"); var pressed = (key.className.indexOf("pressed") !== -1); // If sticky, toggle pressed state if (sticky) { if (pressed) { GuacUI.removeClass(key, "pressed"); guac.sendKeyEvent(0, keysym); delete active_sticky_keys[keysym]; } else { GuacUI.addClass(key, "pressed"); guac.sendKeyEvent(1, keysym); active_sticky_keys[keysym] = key; } } // For all non-sticky keys, press and release key immediately else send_keysym(keysym); } var ignore_mouse = false; // Press/release key when clicked key.addEventListener("mousedown", function __mouse_key(e) { // Ignore clicks which follow touches if (ignore_mouse) return; __update_key(e); }, false); // Press/release key when tapped key.addEventListener("touchstart", function __touch_key(e) { // Ignore following clicks ignore_mouse = true; __update_key(e); }, false); // Restore handling of mouse events when mouse is used key.addEventListener("mousemove", function __reset_mouse() { ignore_mouse = false; }, false); }
Presses/releases the keysym defined by the "data-keysym" attribute on the given element whenever the element is pressed. The "data-sticky" attribute, if present and set to "true", causes the key to remain pressed until text is sent. @param {Element} key The element which will control its associated key.
apply_key_behavior
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/client-ui.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/client-ui.js
MIT
function __update_key(e) { var guac = GuacUI.Client.attachedClient; if (!guac) return; e.preventDefault(); e.stopPropagation(); // Pull properties of key var keysym = parseInt(key.getAttribute("data-keysym")); var sticky = (key.getAttribute("data-sticky") === "true"); var pressed = (key.className.indexOf("pressed") !== -1); // If sticky, toggle pressed state if (sticky) { if (pressed) { GuacUI.removeClass(key, "pressed"); guac.sendKeyEvent(0, keysym); delete active_sticky_keys[keysym]; } else { GuacUI.addClass(key, "pressed"); guac.sendKeyEvent(1, keysym); active_sticky_keys[keysym] = key; } } // For all non-sticky keys, press and release key immediately else send_keysym(keysym); }
Presses/releases the keysym defined by the "data-keysym" attribute on the given element whenever the element is pressed. The "data-sticky" attribute, if present and set to "true", causes the key to remain pressed until text is sent. @param {Element} key The element which will control its associated key.
__update_key
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/client-ui.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/client-ui.js
MIT
function release_sticky_keys() { var guac = GuacUI.Client.attachedClient; if (!guac) return; // Release all active sticky keys for (var keysym in active_sticky_keys) { var key = active_sticky_keys[keysym]; GuacUI.removeClass(key, "pressed"); guac.sendKeyEvent(0, keysym); } // Reset set of active keys active_sticky_keys = {}; }
Releases all currently-held sticky keys within the text input UI.
release_sticky_keys
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/client-ui.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/client-ui.js
MIT
function reset_text_input_target(padding) { var padding_char = String.fromCharCode(GuacUI.Client.TEXT_INPUT_PADDING_CODEPOINT); // Pad text area with an arbitrary, non-typable character (so there is something // to delete with backspace or del), and position cursor in middle. GuacUI.Client.text_input.target.value = new Array(padding*2 + 1).join(padding_char); GuacUI.Client.text_input.target.setSelectionRange(padding-1, padding); }
Removes all content from the text input target, replacing it with the given number of padding characters. Padding of the requested size is added on both sides of the cursor, thus the overall number of characters added will be twice the number specified. @param {Number} padding The number of characters to pad the text area with.
reset_text_input_target
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/client-ui.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/client-ui.js
MIT
function addGroupContents(group, appendChild) { var i; // Add all contained connections if (show_connections) { for (i=0; i<group.connections.length; i++) addConnection(group.connections[i], appendChild); } // Add all contained groups for (i=0; i<group.groups.length; i++) addGroup(group.groups[i], appendChild); }
Adds the contents of the given group via the given appendChild() function, but not the given group itself. @param {GuacamoleService.ConnectionGroup} group The group whose contents should be added. @param {Function} appendChild A function which, given an element, will add that element the the display as desired.
addGroupContents
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/guac-ui.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/guac-ui.js
MIT
function addConnection(connection, appendChild) { // Do not add connection if filter says "no" if (connection_filter && !connection_filter(connection)) return; group_view.connections[connection.id] = connection; // Add connection to connection list or parent group var guacui_connection = new GuacUI.ListConnection(connection); GuacUI.addClass(guacui_connection.getElement(), "list-item"); // If multiselect, add checkbox for each connection if (multiselect) { var connection_choice = GuacUI.createElement("div", "choice"); var connection_checkbox = GuacUI.createChildElement(connection_choice, "input"); connection_checkbox.setAttribute("type", "checkbox"); connection_choice.appendChild(guacui_connection.getElement()); appendChild(connection_choice); function fire_connection_change(e) { // Prevent click from affecting parent e.stopPropagation(); // Fire event if handler defined if (group_view.onconnectionchange) group_view.onconnectionchange(connection, this.checked); } // Fire change events when checkbox modified connection_checkbox.addEventListener("click", fire_connection_change, false); connection_checkbox.addEventListener("change", fire_connection_change, false); // Add checbox to set of connection checkboxes connection_checkboxes[connection.id] = connection_checkbox; } else appendChild(guacui_connection.getElement()); // Fire click events when connection clicked guacui_connection.onclick = function() { if (group_view.onconnectionclick) group_view.onconnectionclick(connection); }; }
Adds the given connection via the given appendChild() function. @param {GuacamoleService.Connection} connection The connection to add. @param {Function} appendChild A function which, given an element, will add that element the the display as desired.
addConnection
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/guac-ui.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/guac-ui.js
MIT
function fire_connection_change(e) { // Prevent click from affecting parent e.stopPropagation(); // Fire event if handler defined if (group_view.onconnectionchange) group_view.onconnectionchange(connection, this.checked); }
Adds the given connection via the given appendChild() function. @param {GuacamoleService.Connection} connection The connection to add. @param {Function} appendChild A function which, given an element, will add that element the the display as desired.
fire_connection_change
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/guac-ui.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/guac-ui.js
MIT
function addGroup(group, appendChild) { // Do not add group if filter says "no" if (group_filter && !group_filter(group)) return; // Add group to groups collection group_view.groups[group.id] = group; // Create element for group var list_group = new GuacUI.ListGroup(group.name); list_groups[group.id] = list_group; GuacUI.addClass(list_group.getElement(), "list-item"); // Mark group as balancer if appropriate if (group.type === GuacamoleService.ConnectionGroup.Type.BALANCING) GuacUI.addClass(list_group.getElement(), "balancer"); // Recursively add all children to the new element addGroupContents(group, list_group.addElement); // If multiselect, add checkbox for each group if (multiselect) { var group_choice = GuacUI.createElement("div", "choice"); var group_checkbox = GuacUI.createChildElement(group_choice, "input"); group_checkbox.setAttribute("type", "checkbox"); group_choice.appendChild(list_group.getElement()); appendChild(group_choice); function fire_group_change(e) { // Prevent click from affecting parent e.stopPropagation(); // Fire event if handler defined if (group_view.ongroupchange) group_view.ongroupchange(group, this.checked); } // Fire change events when checkbox modified group_checkbox.addEventListener("click", fire_group_change, false); group_checkbox.addEventListener("change", fire_group_change, false); // Add checbox to set of group checkboxes group_checkboxes[group.id] = group_checkbox; } else appendChild(list_group.getElement()); // Fire click events when group clicked list_group.onclick = function() { if (group_view.ongroupclick) group_view.ongroupclick(group); }; }
Adds the given group via the given appendChild() function. @param {GuacamoleService.ConnectionGroup} group The group to add. @param {Function} appendChild A function which, given an element, will add that element the the display as desired.
addGroup
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/guac-ui.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/guac-ui.js
MIT
function fire_group_change(e) { // Prevent click from affecting parent e.stopPropagation(); // Fire event if handler defined if (group_view.ongroupchange) group_view.ongroupchange(group, this.checked); }
Adds the given group via the given appendChild() function. @param {GuacamoleService.ConnectionGroup} group The group to add. @param {Function} appendChild A function which, given an element, will add that element the the display as desired.
fire_group_change
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/guac-ui.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/guac-ui.js
MIT
function truncate() { // Build list of entries var entries = []; for (var old_id in history) entries.push(history[old_id]); // Avoid history growth beyond defined number of entries if (entries.length > IDEAL_LENGTH) { // Sort list entries.sort(GuacamoleHistory.Entry.compare); // Remove entries until length is ideal or all are recent var now = new Date().getTime(); while (entries.length > IDEAL_LENGTH && now - entries[0].accessed > CUTOFF_AGE) { // Remove entry var removed = entries.shift(); delete history[removed.id]; } } }
The maximum age of a history entry before it is removed, in milliseconds.
truncate
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/history.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/history.js
MIT
function hasEntry(object) { for (var name in object) return true; return false; }
Resets the interface such that the login UI is displayed if the user is not authenticated (or authentication fails) and the connection list UI (or the client for the only available connection, if there is only one) is displayed if the user is authenticated.
hasEntry
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/root-ui.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/root-ui.js
MIT
function parseConnection(parent, element) { var i; var connection = new GuacamoleService.Connection( element.getAttribute("protocol"), element.getAttribute("id"), element.getAttribute("name") ); // Set parent connection.parent = parent; // Add parameter values for each parmeter received var paramElements = element.getElementsByTagName("param"); for (i=0; i<paramElements.length; i++) { var paramElement = paramElements[i]; var name = paramElement.getAttribute("name"); connection.parameters[name] = paramElement.textContent; } // Parse history, if available var historyElements = element.getElementsByTagName("history"); if (historyElements.length === 1) { // For each record in history var history = historyElements[0]; var recordElements = history.getElementsByTagName("record"); for (i=0; i<recordElements.length; i++) { // Get record var recordElement = recordElements[i]; var record = new GuacamoleService.Connection.Record( recordElement.textContent, parseInt(recordElement.getAttribute("start")), parseInt(recordElement.getAttribute("end")), recordElement.getAttribute("active") === "yes" ); // Append to connection history connection.history.push(record); } } // Return parsed connection return connection; }
Parse the contents of the given connection element within XML, returning a corresponding GuacamoleService.Connection. @param {GuacamoleService.ConnectionGroup} The connection group containing this connection. @param {Element} element The element being parsed. @return {GuacamoleService.Connection} The connection represented by the element just parsed.
parseConnection
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/service.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/service.js
MIT
function parseGroup(parent, element) { var id = element.getAttribute("id"); var name = element.getAttribute("name"); var type_string = element.getAttribute("type"); // Translate type name var type; if (type_string === "organizational") type = GuacamoleService.ConnectionGroup.Type.ORGANIZATIONAL; else if (type_string === "balancing") type = GuacamoleService.ConnectionGroup.Type.BALANCING; // Create corresponding group var group = new GuacamoleService.ConnectionGroup(type, id, name); // Set parent group.parent = parent; // For each child element var current = element.firstChild; while (current !== null) { var i, child; var children = current.childNodes; if (current.localName === "connections") { // Parse all child connections for (i=0; i<children.length; i++) { var child = children[i]; if (child.localName === "connection") group.connections.push(parseConnection(group, child)); } } else if (current.localName === "groups") { // Parse all child groups for (i=0; i<children.length; i++) { var child = children[i]; if (child.localName === "group") group.groups.push(parseGroup(group, child)); } } // Next element current = current.nextSibling; } // Sort groups and connections group.groups.sort(GuacamoleService.Connections.comparator); group.connections.sort(GuacamoleService.Connections.comparator); // Return created group return group; }
Recursively parse the contents of the given group element within XML, returning a corresponding GuacamoleService.ConnectionGroup. @param {GuacamoleService.ConnectionGroup} The connection group containing this group. @param {Element} element The element being parsed. @return {GuacamoleService.ConnectionGroup} The connection group represented by the element just parsed.
parseGroup
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/service.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/service.js
MIT
function __notify_changed(name, value) { for (var i=0; i<listeners.length; i++) listeners[i](name, value); }
Notifies all listeners that an item has changed. @param {String} name The name of the item that changed. @param value The new item value.
__notify_changed
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/session.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole/src/main/webapp/scripts/session.js
MIT
function __send_blob(bytes) { var binary = ""; // Produce binary string from bytes in buffer for (var i=0; i<bytes.byteLength; i++) binary += String.fromCharCode(bytes[i]); // Send as base64 stream.sendBlob(window.btoa(binary)); }
Encodes the given data as base64, sending it as a blob. The data must be small enough to fit into a single blob instruction. @private @param {Uint8Array} bytes The data to send.
__send_blob
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/ArrayBufferWriter.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/ArrayBufferWriter.js
MIT
handleReady = function(buffer) { readyBuffer = buffer; }
Schedules this packet for playback at the given time. @function @param {Number} when The time this packet should be played, in milliseconds.
handleReady
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/AudioChannel.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/AudioChannel.js
MIT
function playDelayed(buffer) { source.buffer = buffer; source.start(play_when / 1000); }
Schedules this packet for playback at the given time. @function @param {Number} when The time this packet should be played, in milliseconds.
playDelayed
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/AudioChannel.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/AudioChannel.js
MIT
function getLayer(index) { // Get layer, create if necessary var layer = layers[index]; if (!layer) { // Create layer based on index if (index === 0) layer = display.getDefaultLayer(); else if (index > 0) layer = display.createLayer(); else layer = display.createBuffer(); // Add new layer layers[index] = layer; } return layer; }
Returns the layer with the given index, creating it if necessary. Positive indices refer to visible layers, an index of zero refers to the default layer, and negative indices refer to buffers. @param {Number} index The index of the layer to retrieve. @return {Guacamole.Display.VisibleLayer|Guacamole.Layer} The layer having the given index.
getLayer
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Client.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Client.js
MIT
function getParser(index) { var parser = parsers[index]; // If parser not yet created, create it, and tie to the // oninstruction handler of the tunnel. if (parser == null) { parser = parsers[index] = new Guacamole.Parser(); parser.oninstruction = tunnel.oninstruction; } return parser; }
Returns the layer with the given index, creating it if necessary. Positive indices refer to visible layers, an index of zero refers to the default layer, and negative indices refer to buffers. @param {Number} index The index of the layer to retrieve. @return {Guacamole.Display.VisibleLayer|Guacamole.Layer} The layer having the given index.
getParser
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Client.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Client.js
MIT
function getAudioChannel(index) { var audio_channel = audio_channels[index]; // If audio channel not yet created, create it if (audio_channel == null) audio_channel = audio_channels[index] = new Guacamole.AudioChannel(); return audio_channel; }
Returns the layer with the given index, creating it if necessary. Positive indices refer to visible layers, an index of zero refers to the default layer, and negative indices refer to buffers. @param {Number} index The index of the layer to retrieve. @return {Guacamole.Display.VisibleLayer|Guacamole.Layer} The layer having the given index.
getAudioChannel
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Client.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Client.js
MIT
function Frame(callback, tasks) { /** * Returns whether this frame is ready to be rendered. This function * returns true if and only if ALL underlying tasks are unblocked. * * @returns {Boolean} true if all underlying tasks are unblocked, * false otherwise. */ this.isReady = function() { // Search for blocked tasks for (var i=0; i < tasks.length; i++) { if (tasks[i].blocked) return false; } // If no blocked tasks, the frame is ready return true; }; /** * Renders this frame, calling the associated callback, if any, after * the frame is complete. This function MUST only be called when no * blocked tasks exist. Calling this function with blocked tasks * will result in undefined behavior. */ this.flush = function() { // Draw all pending tasks. for (var i=0; i < tasks.length; i++) tasks[i].execute(); // Call callback if (callback) callback(); }; }
An ordered list of tasks which must be executed atomically. Once executed, an associated (and optional) callback will be called. @private @constructor @param {function} callback The function to call when this frame is rendered. @param {Task[]} tasks The set of tasks which must be executed to render this frame.
Frame
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Display.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Display.js
MIT
function Task(taskHandler, blocked) { var task = this; /** * Whether this Task is blocked. * * @type boolean */ this.blocked = blocked; /** * Unblocks this Task, allowing it to run. */ this.unblock = function() { if (task.blocked) { task.blocked = false; __flush_frames(); } }; /** * Calls the handler associated with this task IMMEDIATELY. This * function does not track whether this task is marked as blocked. * Enforcing the blocked status of tasks is up to the caller. */ this.execute = function() { if (taskHandler) taskHandler(); }; }
A container for an task handler. Each operation which must be ordered is associated with a Task that goes into a task queue. Tasks in this queue are executed in order once their handlers are set, while Tasks without handlers block themselves and any following Tasks from running. @constructor @private @param {function} taskHandler The function to call when this task runs, if any. @param {boolean} blocked Whether this task should start blocked.
Task
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Display.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Display.js
MIT
function scheduleTask(handler, blocked) { var task = new Task(handler, blocked); tasks.push(task); return task; }
Schedules a task for future execution. The given handler will execute immediately after all previous tasks upon frame flush, unless this task is blocked. If any tasks is blocked, the entire frame will not render (and no tasks within will execute) until all tasks are unblocked. @private @param {function} handler The function to call when possible, if any. @param {boolean} blocked Whether the task should start blocked. @returns {Task} The Task created and added to the queue for future running.
scheduleTask
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Display.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Display.js
MIT
function render_callback() { layer.drawImage(0, 0, video); if (!video.ended) window.setTimeout(render_callback, 20); }
Plays the video at the specified URL within this layer. The video will be loaded automatically, and this and any future operations will wait for the video to finish loading. Future operations will not be executed until the video finishes playing. @param {Guacamole.Layer} layer The layer to draw upon. @param {String} mimetype The mimetype of the video to play. @param {Number} duration The duration of the video in milliseconds. @param {String} url The URL of the video to play.
render_callback
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Display.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Display.js
MIT
function get_children(layer) { // Build array of children var children = []; for (var index in layer.children) children.push(layer.children[index]); // Sort children.sort(function children_comparator(a, b) { // Compare based on Z order var diff = a.z - b.z; if (diff !== 0) return diff; // If Z order identical, use document order var a_element = a.getElement(); var b_element = b.getElement(); var position = b_element.compareDocumentPosition(a_element); if (position & Node.DOCUMENT_POSITION_PRECEDING) return -1; if (position & Node.DOCUMENT_POSITION_FOLLOWING) return 1; // Otherwise, assume same return 0; }); // Done return children; }
Returns a canvas element containing the entire display, with all child layers composited within. @return {HTMLCanvasElement} A new canvas element containing a copy of the display.
get_children
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Display.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Display.js
MIT
function draw_layer(layer, x, y) { // Draw layer if (layer.width > 0 && layer.height > 0) { // Save and update alpha var initial_alpha = context.globalAlpha; context.globalAlpha *= layer.alpha / 255.0; // Copy data context.drawImage(layer.getCanvas(), x, y); // Draw all children var children = get_children(layer); for (var i=0; i<children.length; i++) { var child = children[i]; draw_layer(child, x + child.x, y + child.y); } // Restore alpha context.globalAlpha = initial_alpha; } }
Returns a canvas element containing the entire display, with all child layers composited within. @return {HTMLCanvasElement} A new canvas element containing a copy of the display.
draw_layer
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Display.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Display.js
MIT
KeyEvent = function() { /** * Reference to this key event. */ var key_event = this; /** * An arbitrary timestamp in milliseconds, indicating this event's * position in time relative to other events. * * @type Number */ this.timestamp = new Date().getTime(); /** * Whether the default action of this key event should be prevented. * * @type Boolean */ this.defaultPrevented = false; /** * The keysym of the key associated with this key event, as determined * by a best-effort guess using available event properties and keyboard * state. * * @type Number */ this.keysym = null; /** * Whether the keysym value of this key event is known to be reliable. * If false, the keysym may still be valid, but it's only a best guess, * and future key events may be a better source of information. * * @type Boolean */ this.reliable = false; /** * Returns the number of milliseconds elapsed since this event was * received. * * @return {Number} The number of milliseconds elapsed since this * event was received. */ this.getAge = function() { return new Date().getTime() - key_event.timestamp; }; }
A key event having a corresponding timestamp. This event is non-specific. Its subclasses should be used instead when recording specific key events. @private @constructor
KeyEvent
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Keyboard.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Keyboard.js
MIT
KeydownEvent = function(keyCode, keyIdentifier, key, location) { // We extend KeyEvent KeyEvent.apply(this); /** * The JavaScript key code of the key pressed. * * @type Number */ this.keyCode = keyCode; /** * The legacy DOM3 "keyIdentifier" of the key pressed, as defined at: * http://www.w3.org/TR/2009/WD-DOM-Level-3-Events-20090908/#events-Events-KeyboardEvent * * @type String */ this.keyIdentifier = keyIdentifier; /** * The standard name of the key pressed, as defined at: * http://www.w3.org/TR/DOM-Level-3-Events/#events-KeyboardEvent * * @type String */ this.key = key; /** * The location on the keyboard corresponding to the key pressed, as * defined at: * http://www.w3.org/TR/DOM-Level-3-Events/#events-KeyboardEvent * * @type Number */ this.location = location; // If key is known from keyCode or DOM3 alone, use that this.keysym = keysym_from_key_identifier(key, location) || keysym_from_keycode(keyCode, location); // DOM3 and keyCode are reliable sources if (this.keysym) this.reliable = true; // Use legacy keyIdentifier as a last resort, if it looks sane if (!this.keysym && key_identifier_sane(keyCode, keyIdentifier)) this.keysym = keysym_from_key_identifier(keyIdentifier, location, guac_keyboard.modifiers.shift); // Determine whether default action for Alt+combinations must be prevented var prevent_alt = !guac_keyboard.modifiers.ctrl && !(navigator && navigator.platform && navigator.platform.match(/^mac/i)); // Determine whether default action for Ctrl+combinations must be prevented var prevent_ctrl = !guac_keyboard.modifiers.alt; // We must rely on the (potentially buggy) keyIdentifier if preventing // the default action is important if ((prevent_ctrl && guac_keyboard.modifiers.ctrl) || (prevent_alt && guac_keyboard.modifiers.alt) || guac_keyboard.modifiers.meta || guac_keyboard.modifiers.hyper) this.reliable = true; // Record most recently known keysym by associated key code recentKeysym[keyCode] = this.keysym; }
Information related to the pressing of a key, which need not be a key associated with a printable character. The presence or absence of any information within this object is browser-dependent. @private @constructor @augments Guacamole.Keyboard.KeyEvent @param {Number} keyCode The JavaScript key code of the key pressed. @param {String} keyIdentifier The legacy DOM3 "keyIdentifier" of the key pressed, as defined at: http://www.w3.org/TR/2009/WD-DOM-Level-3-Events-20090908/#events-Events-KeyboardEvent @param {String} key The standard name of the key pressed, as defined at: http://www.w3.org/TR/DOM-Level-3-Events/#events-KeyboardEvent @param {Number} location The location on the keyboard corresponding to the key pressed, as defined at: http://www.w3.org/TR/DOM-Level-3-Events/#events-KeyboardEvent
KeydownEvent
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Keyboard.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Keyboard.js
MIT
KeypressEvent = function(charCode) { // We extend KeyEvent KeyEvent.apply(this); /** * The Unicode codepoint of the character that would be typed by the * key pressed. * * @type Number */ this.charCode = charCode; // Pull keysym from char code this.keysym = keysym_from_charcode(charCode); // Keypress is always reliable this.reliable = true; }
Information related to the pressing of a key, which MUST be associated with a printable character. The presence or absence of any information within this object is browser-dependent. @private @constructor @augments Guacamole.Keyboard.KeyEvent @param {Number} charCode The Unicode codepoint of the character that would be typed by the key pressed.
KeypressEvent
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Keyboard.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Keyboard.js
MIT
KeyupEvent = function(keyCode, keyIdentifier, key, location) { // We extend KeyEvent KeyEvent.apply(this); /** * The JavaScript key code of the key released. * * @type Number */ this.keyCode = keyCode; /** * The legacy DOM3 "keyIdentifier" of the key released, as defined at: * http://www.w3.org/TR/2009/WD-DOM-Level-3-Events-20090908/#events-Events-KeyboardEvent * * @type String */ this.keyIdentifier = keyIdentifier; /** * The standard name of the key released, as defined at: * http://www.w3.org/TR/DOM-Level-3-Events/#events-KeyboardEvent * * @type String */ this.key = key; /** * The location on the keyboard corresponding to the key released, as * defined at: * http://www.w3.org/TR/DOM-Level-3-Events/#events-KeyboardEvent * * @type Number */ this.location = location; // If key is known from keyCode or DOM3 alone, use that this.keysym = keysym_from_keycode(keyCode, location) || recentKeysym[keyCode] || keysym_from_key_identifier(key, location); // keyCode is still more reliable for keyup when dead keys are in use // Keyup is as reliable as it will ever be this.reliable = true; }
Information related to the pressing of a key, which need not be a key associated with a printable character. The presence or absence of any information within this object is browser-dependent. @private @constructor @augments Guacamole.Keyboard.KeyEvent @param {Number} keyCode The JavaScript key code of the key released. @param {String} keyIdentifier The legacy DOM3 "keyIdentifier" of the key released, as defined at: http://www.w3.org/TR/2009/WD-DOM-Level-3-Events-20090908/#events-Events-KeyboardEvent @param {String} key The standard name of the key released, as defined at: http://www.w3.org/TR/DOM-Level-3-Events/#events-KeyboardEvent @param {Number} location The location on the keyboard corresponding to the key released, as defined at: http://www.w3.org/TR/DOM-Level-3-Events/#events-KeyboardEvent
KeyupEvent
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Keyboard.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Keyboard.js
MIT
function get_keysym(keysyms, location) { if (!keysyms) return null; return keysyms[location] || keysyms[0]; }
Given an array of keysyms indexed by location, returns the keysym for the given location, or the keysym for the standard location if undefined. @param {Array} keysyms An array of keysyms, where the index of the keysym in the array is the location value. @param {Number} location The location on the keyboard corresponding to the key pressed, as defined at: http://www.w3.org/TR/DOM-Level-3-Events/#events-KeyboardEvent
get_keysym
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Keyboard.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Keyboard.js
MIT
function keysym_from_key_identifier(identifier, location, shifted) { if (!identifier) return null; var typedCharacter; // If identifier is U+xxxx, decode Unicode character var unicodePrefixLocation = identifier.indexOf("U+"); if (unicodePrefixLocation >= 0) { var hex = identifier.substring(unicodePrefixLocation+2); typedCharacter = String.fromCharCode(parseInt(hex, 16)); } // If single character, use that as typed character else if (identifier.length === 1) typedCharacter = identifier; // Otherwise, look up corresponding keysym else return get_keysym(keyidentifier_keysym[identifier], location); // Alter case if necessary if (shifted === true) typedCharacter = typedCharacter.toUpperCase(); else if (shifted === false) typedCharacter = typedCharacter.toLowerCase(); // Get codepoint var codepoint = typedCharacter.charCodeAt(0); return keysym_from_charcode(codepoint); }
Given an array of keysyms indexed by location, returns the keysym for the given location, or the keysym for the standard location if undefined. @param {Array} keysyms An array of keysyms, where the index of the keysym in the array is the location value. @param {Number} location The location on the keyboard corresponding to the key pressed, as defined at: http://www.w3.org/TR/DOM-Level-3-Events/#events-KeyboardEvent
keysym_from_key_identifier
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Keyboard.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Keyboard.js
MIT
function isControlCharacter(codepoint) { return codepoint <= 0x1F || (codepoint >= 0x7F && codepoint <= 0x9F); }
Given an array of keysyms indexed by location, returns the keysym for the given location, or the keysym for the standard location if undefined. @param {Array} keysyms An array of keysyms, where the index of the keysym in the array is the location value. @param {Number} location The location on the keyboard corresponding to the key pressed, as defined at: http://www.w3.org/TR/DOM-Level-3-Events/#events-KeyboardEvent
isControlCharacter
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Keyboard.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Keyboard.js
MIT
function keysym_from_charcode(codepoint) { // Keysyms for control characters if (isControlCharacter(codepoint)) return 0xFF00 | codepoint; // Keysyms for ASCII chars if (codepoint >= 0x0000 && codepoint <= 0x00FF) return codepoint; // Keysyms for Unicode if (codepoint >= 0x0100 && codepoint <= 0x10FFFF) return 0x01000000 | codepoint; return null; }
Given an array of keysyms indexed by location, returns the keysym for the given location, or the keysym for the standard location if undefined. @param {Array} keysyms An array of keysyms, where the index of the keysym in the array is the location value. @param {Number} location The location on the keyboard corresponding to the key pressed, as defined at: http://www.w3.org/TR/DOM-Level-3-Events/#events-KeyboardEvent
keysym_from_charcode
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Keyboard.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Keyboard.js
MIT
function keysym_from_keycode(keyCode, location) { return get_keysym(keycodeKeysyms[keyCode], location); }
Given an array of keysyms indexed by location, returns the keysym for the given location, or the keysym for the standard location if undefined. @param {Array} keysyms An array of keysyms, where the index of the keysym in the array is the location value. @param {Number} location The location on the keyboard corresponding to the key pressed, as defined at: http://www.w3.org/TR/DOM-Level-3-Events/#events-KeyboardEvent
keysym_from_keycode
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Keyboard.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Keyboard.js
MIT
function key_identifier_sane(keyCode, keyIdentifier) { // Assume non-Unicode keyIdentifier values are sane var unicodePrefixLocation = keyIdentifier.indexOf("U+"); if (unicodePrefixLocation === -1) return true; // If the Unicode codepoint isn't identical to the keyCode, // then the identifier is likely correct var codepoint = parseInt(keyIdentifier.substring(unicodePrefixLocation+2), 16); if (keyCode !== codepoint) return true; // The keyCodes for A-Z and 0-9 are actually identical to their // Unicode codepoints if ((keyCode >= 65 && keyCode <= 90) || (keyCode >= 48 && keyCode <= 57)) return true; // The keyIdentifier does NOT appear sane return false; }
Heuristically detects if the legacy keyIdentifier property of a keydown/keyup event looks incorrectly derived. Chrome, and presumably others, will produce the keyIdentifier by assuming the keyCode is the Unicode codepoint for that key. This is not correct in all cases. @param {Number} keyCode The keyCode from a browser keydown/keyup event. @param {String} keyIdentifier The legacy keyIdentifier from a browser keydown/keyup event. @returns {Boolean} true if the keyIdentifier looks sane, false if the keyIdentifier appears incorrectly derived.
key_identifier_sane
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Keyboard.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Keyboard.js
MIT
function press_key(keysym) { // Don't bother with pressing the key if the key is unknown if (keysym === null) return; // Only press if released if (!guac_keyboard.pressed[keysym]) { // Mark key as pressed guac_keyboard.pressed[keysym] = true; // Send key event if (guac_keyboard.onkeydown) { var result = guac_keyboard.onkeydown(keysym); last_keydown_result[keysym] = result; // Stop any current repeat window.clearTimeout(key_repeat_timeout); window.clearInterval(key_repeat_interval); // Repeat after a delay as long as pressed if (!no_repeat[keysym]) key_repeat_timeout = window.setTimeout(function() { key_repeat_interval = window.setInterval(function() { guac_keyboard.onkeyup(keysym); guac_keyboard.onkeydown(keysym); }, 50); }, 500); return result; } } // Return the last keydown result by default, resort to false if unknown return last_keydown_result[keysym] || false; }
Marks a key as pressed, firing the keydown event if registered. Key repeat for the pressed key will start after a delay if that key is not a modifier. @private @param keysym The keysym of the key to press. @return {Boolean} true if event should NOT be canceled, false otherwise.
press_key
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Keyboard.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Keyboard.js
MIT
function release_key(keysym) { // Only release if pressed if (guac_keyboard.pressed[keysym]) { // Mark key as released delete guac_keyboard.pressed[keysym]; // Stop repeat window.clearTimeout(key_repeat_timeout); window.clearInterval(key_repeat_interval); // Send key event if (keysym !== null && guac_keyboard.onkeyup) guac_keyboard.onkeyup(keysym); } }
Marks a key as released, firing the keyup event if registered. @private @param keysym The keysym of the key to release.
release_key
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Keyboard.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Keyboard.js
MIT
function update_modifier_state(e) { // Get state var state = Guacamole.Keyboard.ModifierState.fromKeyboardEvent(e); // Release alt if implicitly released if (guac_keyboard.modifiers.alt && state.alt === false) { release_key(0xFFE9); // Left alt release_key(0xFFEA); // Right alt release_key(0xFE03); // AltGr } // Release shift if implicitly released if (guac_keyboard.modifiers.shift && state.shift === false) { release_key(0xFFE1); // Left shift release_key(0xFFE2); // Right shift } // Release ctrl if implicitly released if (guac_keyboard.modifiers.ctrl && state.ctrl === false) { release_key(0xFFE3); // Left ctrl release_key(0xFFE4); // Right ctrl } // Release meta if implicitly released if (guac_keyboard.modifiers.meta && state.meta === false) { release_key(0xFFE7); // Left meta release_key(0xFFE8); // Right meta } // Release hyper if implicitly released if (guac_keyboard.modifiers.hyper && state.hyper === false) { release_key(0xFFEB); // Left hyper release_key(0xFFEC); // Right hyper } // Update state guac_keyboard.modifiers = state; }
Given a keyboard event, updates the local modifier state and remote key state based on the modifier flags within the event. This function pays no attention to keycodes. @param {KeyboardEvent} e The keyboard event containing the flags to update.
update_modifier_state
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Keyboard.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Keyboard.js
MIT
function interpret_events() { // Do not prevent default if no event could be interpreted var handled_event = interpret_event(); if (!handled_event) return false; // Interpret as much as possible var last_event; do { last_event = handled_event; handled_event = interpret_event(); } while (handled_event !== null); return last_event.defaultPrevented; }
Reads through the event log, removing events from the head of the log when the corresponding true key presses are known (or as known as they can be). @return {Boolean} Whether the default action of the latest event should be prevented.
interpret_events
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Keyboard.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Keyboard.js
MIT
function indexof_keyup(keydown) { var i; // Search event log for keyup events having the given keysym for (i=0; i<eventLog.length; i++) { // Return index of key event if found var event = eventLog[i]; if (event instanceof KeyupEvent && event.keyCode === keydown.keyCode) return i; } // No such keyup found return -1; }
Searches the event log for a keyup event corresponding to the given keydown event, returning its index within the log. @param {KeydownEvent} keydown The keydown event whose corresponding keyup event we are to search for. @returns {Number} The index of the first keyup event in the event log matching the given keydown event, or -1 if no such event exists.
indexof_keyup
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Keyboard.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Keyboard.js
MIT
function release_simulated_altgr(keysym) { // Both Ctrl+Alt must be pressed if simulated AltGr is in use if (!guac_keyboard.modifiers.ctrl || !guac_keyboard.modifiers.alt) return; // Assume [A-Z] never require AltGr if (keysym >= 0x0041 && keysym <= 0x005A) return; // Assume [a-z] never require AltGr if (keysym >= 0x0061 && keysym <= 0x007A) return; // Release Ctrl+Alt if the keysym is printable if (keysym <= 0xFF || (keysym & 0xFF000000) === 0x01000000) { release_key(0xFFE3); // Left ctrl release_key(0xFFE4); // Right ctrl release_key(0xFFE9); // Left alt release_key(0xFFEA); // Right alt } }
Releases Ctrl+Alt, if both are currently pressed and the given keysym looks like a key that may require AltGr. @param {Number} keysym The key that was just pressed.
release_simulated_altgr
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Keyboard.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Keyboard.js
MIT
function interpret_event() { // Peek at first event in log var first = eventLog[0]; if (!first) return null; // Keydown event if (first instanceof KeydownEvent) { var keysym = null; var accepted_events = []; // If event itself is reliable, no need to wait for other events if (first.reliable) { keysym = first.keysym; accepted_events = eventLog.splice(0, 1); } // If keydown is immediately followed by a keypress, use the indicated character else if (eventLog[1] instanceof KeypressEvent) { keysym = eventLog[1].keysym; accepted_events = eventLog.splice(0, 2); } // If there is a keyup already, the event must be handled now else if (indexof_keyup(first) !== -1) { keysym = first.keysym; accepted_events = eventLog.splice(0, 1); } // Fire a key press if valid events were found if (accepted_events.length > 0) { if (keysym) { // Fire event release_simulated_altgr(keysym); var defaultPrevented = !press_key(keysym); recentKeysym[first.keyCode] = keysym; // If a key is pressed while meta is held down, the keyup will // never be sent in Chrome, so send it now. (bug #108404) if (guac_keyboard.modifiers.meta && keysym !== 0xFFE7 && keysym !== 0xFFE8) release_key(keysym); // Record whether default was prevented for (var i=0; i<accepted_events.length; i++) accepted_events[i].defaultPrevented = defaultPrevented; } return first; } } // end if keydown // Keyup event else if (first instanceof KeyupEvent) { var keysym = first.keysym; if (keysym) { release_key(keysym); first.defaultPrevented = true; } return eventLog.shift(); } // end if keyup // Ignore any other type of event (keypress by itself is invalid) else return eventLog.shift(); // No event interpreted return null; }
Reads through the event log, interpreting the first event, if possible, and returning that event. If no events can be interpreted, due to a total lack of events or the need for more events, null is returned. Any interpreted events are automatically removed from the log. @return {KeyEvent} The first key event in the log, if it can be interpreted, or null otherwise.
interpret_event
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Keyboard.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Keyboard.js
MIT
function resize(newWidth, newHeight) { // Only preserve old data if width/height are both non-zero var oldData = null; if (layer.width !== 0 && layer.height !== 0) { // Create canvas and context for holding old data oldData = document.createElement("canvas"); oldData.width = layer.width; oldData.height = layer.height; var oldDataContext = oldData.getContext("2d"); // Copy image data from current oldDataContext.drawImage(canvas, 0, 0, layer.width, layer.height, 0, 0, layer.width, layer.height); } // Preserve composite operation var oldCompositeOperation = context.globalCompositeOperation; // Resize canvas canvas.width = newWidth; canvas.height = newHeight; // Redraw old data, if any if (oldData) context.drawImage(oldData, 0, 0, layer.width, layer.height, 0, 0, layer.width, layer.height); // Restore composite operation context.globalCompositeOperation = oldCompositeOperation; layer.width = newWidth; layer.height = newHeight; // Acknowledge reset of stack (happens on resize of canvas) stackSize = 0; context.save(); }
Resizes the canvas element backing this Layer without testing the new size. This function should only be used internally. @private @param {Number} newWidth The new width to assign to this Layer. @param {Number} newHeight The new height to assign to this Layer.
resize
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Layer.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Layer.js
MIT
function fitRect(x, y, w, h) { // Calculate bounds var opBoundX = w + x; var opBoundY = h + y; // Determine max width var resizeWidth; if (opBoundX > layer.width) resizeWidth = opBoundX; else resizeWidth = layer.width; // Determine max height var resizeHeight; if (opBoundY > layer.height) resizeHeight = opBoundY; else resizeHeight = layer.height; // Resize if necessary layer.resize(resizeWidth, resizeHeight); }
Given the X and Y coordinates of the upper-left corner of a rectangle and the rectangle's width and height, resize the backing canvas element as necessary to ensure that the rectangle fits within the canvas element's coordinate space. This function will only make the canvas larger. If the rectangle already fits within the canvas element's coordinate space, the canvas is left unchanged. @private @param {Number} x The X coordinate of the upper-left corner of the rectangle to fit. @param {Number} y The Y coordinate of the upper-left corner of the rectangle to fit. @param {Number} w The width of the the rectangle to fit. @param {Number} h The height of the the rectangle to fit.
fitRect
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Layer.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Layer.js
MIT
function cancelEvent(e) { e.stopPropagation(); if (e.preventDefault) e.preventDefault(); e.returnValue = false; }
Cumulative scroll delta amount. This value is accumulated through scroll events and results in scroll button clicks if it exceeds a certain threshold.
cancelEvent
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Mouse.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Mouse.js
MIT
function mousewheel_handler(e) { // Determine approximate scroll amount (in pixels) var delta = e.deltaY || -e.wheelDeltaY || -e.wheelDelta; // If successfully retrieved scroll amount, convert to pixels if not // already in pixels if (delta) { // Convert to pixels if delta was lines if (e.deltaMode === 1) delta = e.deltaY * guac_mouse.PIXELS_PER_LINE; // Convert to pixels if delta was pages else if (e.deltaMode === 2) delta = e.deltaY * guac_mouse.PIXELS_PER_PAGE; } // Otherwise, assume legacy mousewheel event and line scrolling else delta = e.detail * guac_mouse.PIXELS_PER_LINE; // Update overall delta scroll_delta += delta; // Up while (scroll_delta <= -guac_mouse.scrollThreshold) { if (guac_mouse.onmousedown) { guac_mouse.currentState.up = true; guac_mouse.onmousedown(guac_mouse.currentState); } if (guac_mouse.onmouseup) { guac_mouse.currentState.up = false; guac_mouse.onmouseup(guac_mouse.currentState); } scroll_delta += guac_mouse.scrollThreshold; } // Down while (scroll_delta >= guac_mouse.scrollThreshold) { if (guac_mouse.onmousedown) { guac_mouse.currentState.down = true; guac_mouse.onmousedown(guac_mouse.currentState); } if (guac_mouse.onmouseup) { guac_mouse.currentState.down = false; guac_mouse.onmouseup(guac_mouse.currentState); } scroll_delta -= guac_mouse.scrollThreshold; } cancelEvent(e); }
Cumulative scroll delta amount. This value is accumulated through scroll events and results in scroll button clicks if it exceeds a certain threshold.
mousewheel_handler
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Mouse.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Mouse.js
MIT
function press_button(button) { if (!guac_touchscreen.currentState[button]) { guac_touchscreen.currentState[button] = true; if (guac_touchscreen.onmousedown) guac_touchscreen.onmousedown(guac_touchscreen.currentState); } }
Presses the given mouse button, if it isn't already pressed. Valid button values are "left", "middle", "right", "up", and "down". @private @param {String} button The mouse button to press.
press_button
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Mouse.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Mouse.js
MIT
function release_button(button) { if (guac_touchscreen.currentState[button]) { guac_touchscreen.currentState[button] = false; if (guac_touchscreen.onmouseup) guac_touchscreen.onmouseup(guac_touchscreen.currentState); } }
Releases the given mouse button, if it isn't already released. Valid button values are "left", "middle", "right", "up", and "down". @private @param {String} button The mouse button to release.
release_button
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Mouse.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Mouse.js
MIT
function click_button(button) { press_button(button); release_button(button); }
Clicks (presses and releases) the given mouse button. Valid button values are "left", "middle", "right", "up", and "down". @private @param {String} button The mouse button to click.
click_button
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Mouse.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Mouse.js
MIT
function move_mouse(x, y) { guac_touchscreen.currentState.fromClientPosition(element, x, y); if (guac_touchscreen.onmousemove) guac_touchscreen.onmousemove(guac_touchscreen.currentState); }
Moves the mouse to the given coordinates. These coordinates must be relative to the browser window, as they will be translated based on the touch event target's location within the browser window. @private @param {Number} x The X coordinate of the mouse pointer. @param {Number} y The Y coordinate of the mouse pointer.
move_mouse
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Mouse.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Mouse.js
MIT
function finger_moved(e) { var touch = e.touches[0] || e.changedTouches[0]; var delta_x = touch.clientX - gesture_start_x; var delta_y = touch.clientY - gesture_start_y; return Math.sqrt(delta_x*delta_x + delta_y*delta_y) >= guac_touchscreen.clickMoveThreshold; }
Returns whether the given touch event exceeds the movement threshold for clicking, based on where the touch gesture began. @private @param {TouchEvent} e The touch event to check. @return {Boolean} true if the movement threshold is exceeded, false otherwise.
finger_moved
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Mouse.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Mouse.js
MIT
function begin_gesture(e) { var touch = e.touches[0]; gesture_in_progress = true; gesture_start_x = touch.clientX; gesture_start_y = touch.clientY; }
Begins a new gesture at the location of the first touch in the given touch event. @private @param {TouchEvent} e The touch event beginning this new gesture.
begin_gesture
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Mouse.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Mouse.js
MIT
function end_gesture() { window.clearTimeout(click_release_timeout); window.clearTimeout(long_press_timeout); gesture_in_progress = false; }
End the current gesture entirely. Wait for all touches to be done before resuming gesture detection. @private
end_gesture
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Mouse.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Mouse.js
MIT
function __decode_utf8(buffer) { var text = ""; var bytes = new Uint8Array(buffer); for (var i=0; i<bytes.length; i++) { // Get current byte var value = bytes[i]; // Start new codepoint if nothing yet read if (bytes_remaining === 0) { // 1 byte (0xxxxxxx) if ((value | 0x7F) === 0x7F) text += String.fromCharCode(value); // 2 byte (110xxxxx) else if ((value | 0x1F) === 0xDF) { codepoint = value & 0x1F; bytes_remaining = 1; } // 3 byte (1110xxxx) else if ((value | 0x0F )=== 0xEF) { codepoint = value & 0x0F; bytes_remaining = 2; } // 4 byte (11110xxx) else if ((value | 0x07) === 0xF7) { codepoint = value & 0x07; bytes_remaining = 3; } // Invalid byte else text += "\uFFFD"; } // Continue existing codepoint (10xxxxxx) else if ((value | 0x3F) === 0xBF) { codepoint = (codepoint << 6) | (value & 0x3F); bytes_remaining--; // Write codepoint if finished if (bytes_remaining === 0) text += String.fromCharCode(codepoint); } // Invalid byte else { bytes_remaining = 0; text += "\uFFFD"; } } return text; }
Decodes the given UTF-8 data into a Unicode string. The data may end in the middle of a multibyte character. @private @param {ArrayBuffer} buffer Arbitrary UTF-8 data. @return {String} A decoded Unicode string.
__decode_utf8
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/StringReader.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/StringReader.js
MIT
function __expand(bytes) { // Resize buffer if more space needed if (length+bytes >= buffer.length) { var new_buffer = new Uint8Array((length+bytes)*2); new_buffer.set(buffer); buffer = new_buffer; } length += bytes; }
Expands the size of the underlying buffer by the given number of bytes, updating the length appropriately. @private @param {Number} bytes The number of bytes to add to the underlying buffer.
__expand
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/StringWriter.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/StringWriter.js
MIT
function __append_utf8(codepoint) { var mask; var bytes; // 1 byte if (codepoint <= 0x7F) { mask = 0x00; bytes = 1; } // 2 byte else if (codepoint <= 0x7FF) { mask = 0xC0; bytes = 2; } // 3 byte else if (codepoint <= 0xFFFF) { mask = 0xE0; bytes = 3; } // 4 byte else if (codepoint <= 0x1FFFFF) { mask = 0xF0; bytes = 4; } // If invalid codepoint, append replacement character else { __append_utf8(0xFFFD); return; } // Offset buffer by size __expand(bytes); var offset = length - 1; // Add trailing bytes, if any for (var i=1; i<bytes; i++) { buffer[offset--] = 0x80 | (codepoint & 0x3F); codepoint >>= 6; } // Set initial byte buffer[offset] = mask | codepoint; }
Appends a single Unicode character to the current buffer, resizing the buffer if necessary. The character will be encoded as UTF-8. @private @param {Number} codepoint The codepoint of the Unicode character to append.
__append_utf8
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/StringWriter.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/StringWriter.js
MIT
function __encode_utf8(text) { // Fill buffer with UTF-8 for (var i=0; i<text.length; i++) { var codepoint = text.charCodeAt(i); __append_utf8(codepoint); } // Flush buffer if (length > 0) { var out_buffer = buffer.subarray(0, length); length = 0; return out_buffer; } }
Encodes the given string as UTF-8, returning an ArrayBuffer containing the resulting bytes. @private @param {String} text The string to encode as UTF-8. @return {Uint8Array} The encoded UTF-8 data.
__encode_utf8
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/StringWriter.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/StringWriter.js
MIT
function reset_timeout() { // Get rid of old timeout (if any) window.clearTimeout(receive_timeout); // Set new timeout receive_timeout = window.setTimeout(function () { close_tunnel(new Guacamole.Status(Guacamole.Status.Code.UPSTREAM_TIMEOUT, "Server timeout.")); }, tunnel.receiveTimeout); }
Initiates a timeout which, if data is not received, causes the tunnel to close with an error. @private
reset_timeout
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Tunnel.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Tunnel.js
MIT
function close_tunnel(status) { // Ignore if already closed if (tunnel.state === Guacamole.Tunnel.State.CLOSED) return; // If connection closed abnormally, signal error. if (status.code !== Guacamole.Status.Code.SUCCESS && tunnel.onerror) { // Ignore RESOURCE_NOT_FOUND if we've already connected, as that // only signals end-of-stream for the HTTP tunnel. if (tunnel.state === Guacamole.Tunnel.State.CONNECTING || status.code !== Guacamole.Status.Code.RESOURCE_NOT_FOUND) tunnel.onerror(status); } // Mark as closed tunnel.state = Guacamole.Tunnel.State.CLOSED; if (tunnel.onstatechange) tunnel.onstatechange(tunnel.state); }
Closes this tunnel, signaling the given status and corresponding message, which will be sent to the onerror handler if the status is an error status. @private @param {Guacamole.Status} status The status causing the connection to close;
close_tunnel
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Tunnel.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Tunnel.js
MIT
function getElement(value) { var string = new String(value); return string.length + "." + string; }
Converts the given value to a length/string pair for use as an element in a Guacamole instruction. @private @param value The value to convert. @return {String} The converted value.
getElement
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Tunnel.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Tunnel.js
MIT
function sendPendingMessages() { // Do not attempt to send messages if not connected if (tunnel.state !== Guacamole.Tunnel.State.OPEN) return; if (outputMessageBuffer.length > 0) { sendingMessages = true; var message_xmlhttprequest = new XMLHttpRequest(); message_xmlhttprequest.open("POST", TUNNEL_WRITE + tunnel_uuid); message_xmlhttprequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8"); // Once response received, send next queued event. message_xmlhttprequest.onreadystatechange = function() { if (message_xmlhttprequest.readyState === 4) { // If an error occurs during send, handle it if (message_xmlhttprequest.status !== 200) handleHTTPTunnelError(message_xmlhttprequest); // Otherwise, continue the send loop else sendPendingMessages(); } }; message_xmlhttprequest.send(outputMessageBuffer); outputMessageBuffer = ""; // Clear buffer } else sendingMessages = false; }
Converts the given value to a length/string pair for use as an element in a Guacamole instruction. @private @param value The value to convert. @return {String} The converted value.
sendPendingMessages
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Tunnel.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Tunnel.js
MIT
function handleHTTPTunnelError(xmlhttprequest) { var code = parseInt(xmlhttprequest.getResponseHeader("Guacamole-Status-Code")); var message = xmlhttprequest.getResponseHeader("Guacamole-Error-Message"); close_tunnel(new Guacamole.Status(code, message)); }
Converts the given value to a length/string pair for use as an element in a Guacamole instruction. @private @param value The value to convert. @return {String} The converted value.
handleHTTPTunnelError
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Tunnel.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Tunnel.js
MIT
function handleResponse(xmlhttprequest) { var interval = null; var nextRequest = null; var dataUpdateEvents = 0; // The location of the last element's terminator var elementEnd = -1; // Where to start the next length search or the next element var startIndex = 0; // Parsed elements var elements = new Array(); function parseResponse() { // Do not handle responses if not connected if (tunnel.state !== Guacamole.Tunnel.State.OPEN) { // Clean up interval if polling if (interval !== null) clearInterval(interval); return; } // Do not parse response yet if not ready if (xmlhttprequest.readyState < 2) return; // Attempt to read status var status; try { status = xmlhttprequest.status; } // If status could not be read, assume successful. catch (e) { status = 200; } // Start next request as soon as possible IF request was successful if (!nextRequest && status === 200) nextRequest = makeRequest(); // Parse stream when data is received and when complete. if (xmlhttprequest.readyState === 3 || xmlhttprequest.readyState === 4) { reset_timeout(); // Also poll every 30ms (some browsers don't repeatedly call onreadystatechange for new data) if (pollingMode === POLLING_ENABLED) { if (xmlhttprequest.readyState === 3 && !interval) interval = setInterval(parseResponse, 30); else if (xmlhttprequest.readyState === 4 && !interval) clearInterval(interval); } // If canceled, stop transfer if (xmlhttprequest.status === 0) { tunnel.disconnect(); return; } // Halt on error during request else if (xmlhttprequest.status !== 200) { handleHTTPTunnelError(xmlhttprequest); return; } // Attempt to read in-progress data var current; try { current = xmlhttprequest.responseText; } // Do not attempt to parse if data could not be read catch (e) { return; } // While search is within currently received data while (elementEnd < current.length) { // If we are waiting for element data if (elementEnd >= startIndex) { // We now have enough data for the element. Parse. var element = current.substring(startIndex, elementEnd); var terminator = current.substring(elementEnd, elementEnd+1); // Add element to array elements.push(element); // If last element, handle instruction if (terminator === ";") { // Get opcode var opcode = elements.shift(); // Call instruction handler. if (tunnel.oninstruction) tunnel.oninstruction(opcode, elements); // Clear elements elements.length = 0; } // Start searching for length at character after // element terminator startIndex = elementEnd + 1; } // Search for end of length var lengthEnd = current.indexOf(".", startIndex); if (lengthEnd !== -1) { // Parse length var length = parseInt(current.substring(elementEnd+1, lengthEnd)); // If we're done parsing, handle the next response. if (length === 0) { // Clean up interval if polling if (!interval) clearInterval(interval); // Clean up object xmlhttprequest.onreadystatechange = null; xmlhttprequest.abort(); // Start handling next request if (nextRequest) handleResponse(nextRequest); // Done parsing break; } // Calculate start of element startIndex = lengthEnd + 1; // Calculate location of element terminator elementEnd = startIndex + length; } // If no period yet, continue search when more data // is received else { startIndex = current.length; break; } } // end parse loop } } // If response polling enabled, attempt to detect if still // necessary (via wrapping parseResponse()) if (pollingMode === POLLING_ENABLED) { xmlhttprequest.onreadystatechange = function() { // If we receive two or more readyState==3 events, // there is no need to poll. if (xmlhttprequest.readyState === 3) { dataUpdateEvents++; if (dataUpdateEvents >= 2) { pollingMode = POLLING_DISABLED; xmlhttprequest.onreadystatechange = parseResponse; } } parseResponse(); }; } // Otherwise, just parse else xmlhttprequest.onreadystatechange = parseResponse; parseResponse(); }
Converts the given value to a length/string pair for use as an element in a Guacamole instruction. @private @param value The value to convert. @return {String} The converted value.
handleResponse
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Tunnel.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Tunnel.js
MIT
function parseResponse() { // Do not handle responses if not connected if (tunnel.state !== Guacamole.Tunnel.State.OPEN) { // Clean up interval if polling if (interval !== null) clearInterval(interval); return; } // Do not parse response yet if not ready if (xmlhttprequest.readyState < 2) return; // Attempt to read status var status; try { status = xmlhttprequest.status; } // If status could not be read, assume successful. catch (e) { status = 200; } // Start next request as soon as possible IF request was successful if (!nextRequest && status === 200) nextRequest = makeRequest(); // Parse stream when data is received and when complete. if (xmlhttprequest.readyState === 3 || xmlhttprequest.readyState === 4) { reset_timeout(); // Also poll every 30ms (some browsers don't repeatedly call onreadystatechange for new data) if (pollingMode === POLLING_ENABLED) { if (xmlhttprequest.readyState === 3 && !interval) interval = setInterval(parseResponse, 30); else if (xmlhttprequest.readyState === 4 && !interval) clearInterval(interval); } // If canceled, stop transfer if (xmlhttprequest.status === 0) { tunnel.disconnect(); return; } // Halt on error during request else if (xmlhttprequest.status !== 200) { handleHTTPTunnelError(xmlhttprequest); return; } // Attempt to read in-progress data var current; try { current = xmlhttprequest.responseText; } // Do not attempt to parse if data could not be read catch (e) { return; } // While search is within currently received data while (elementEnd < current.length) { // If we are waiting for element data if (elementEnd >= startIndex) { // We now have enough data for the element. Parse. var element = current.substring(startIndex, elementEnd); var terminator = current.substring(elementEnd, elementEnd+1); // Add element to array elements.push(element); // If last element, handle instruction if (terminator === ";") { // Get opcode var opcode = elements.shift(); // Call instruction handler. if (tunnel.oninstruction) tunnel.oninstruction(opcode, elements); // Clear elements elements.length = 0; } // Start searching for length at character after // element terminator startIndex = elementEnd + 1; } // Search for end of length var lengthEnd = current.indexOf(".", startIndex); if (lengthEnd !== -1) { // Parse length var length = parseInt(current.substring(elementEnd+1, lengthEnd)); // If we're done parsing, handle the next response. if (length === 0) { // Clean up interval if polling if (!interval) clearInterval(interval); // Clean up object xmlhttprequest.onreadystatechange = null; xmlhttprequest.abort(); // Start handling next request if (nextRequest) handleResponse(nextRequest); // Done parsing break; } // Calculate start of element startIndex = lengthEnd + 1; // Calculate location of element terminator elementEnd = startIndex + length; } // If no period yet, continue search when more data // is received else { startIndex = current.length; break; } } // end parse loop } }
Converts the given value to a length/string pair for use as an element in a Guacamole instruction. @private @param value The value to convert. @return {String} The converted value.
parseResponse
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Tunnel.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Tunnel.js
MIT
function makeRequest() { // Make request, increment request ID var xmlhttprequest = new XMLHttpRequest(); xmlhttprequest.open("GET", TUNNEL_READ + tunnel_uuid + ":" + (request_id++)); xmlhttprequest.send(null); return xmlhttprequest; }
Arbitrary integer, unique for each tunnel read request. @private
makeRequest
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Tunnel.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Tunnel.js
MIT
function reset_timeout() { // Get rid of old timeout (if any) window.clearTimeout(receive_timeout); // Set new timeout receive_timeout = window.setTimeout(function () { close_tunnel(new Guacamole.Status(Guacamole.Status.Code.UPSTREAM_TIMEOUT, "Server timeout.")); }, tunnel.receiveTimeout); }
Initiates a timeout which, if data is not received, causes the tunnel to close with an error. @private
reset_timeout
javascript
alibaba/f2etest
f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Tunnel.js
https://github.com/alibaba/f2etest/blob/master/f2etest-guacamole/guacamole-client-0.9.3/guacamole-common-js/src/main/webapp/modules/Tunnel.js
MIT