guacamole-common-js 1.4.0-a → 1.4.0-c
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{guacamole-common.js → cjs/guacamole-common.js} +1254 -434
- package/dist/cjs/guacamole-common.min.js +1 -0
- package/dist/cjs/package.json +3 -0
- package/dist/esm/.gitkeep +0 -0
- package/dist/esm/guacamole-common.js +16090 -0
- package/dist/esm/guacamole-common.min.js +1 -0
- package/package.json +22 -9
- package/NOTICE +0 -5
- package/dist/guacamole-common.min.js +0 -1
- /package/dist/{.gitkeep → cjs/.gitkeep} +0 -0
|
@@ -74,8 +74,7 @@ Guacamole.ArrayBufferReader = function(stream) {
|
|
|
74
74
|
*/
|
|
75
75
|
this.onend = null;
|
|
76
76
|
|
|
77
|
-
}
|
|
78
|
-
/*
|
|
77
|
+
};/*
|
|
79
78
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
80
79
|
* or more contributor license agreements. See the NOTICE file
|
|
81
80
|
* distributed with this work for additional information
|
|
@@ -203,7 +202,6 @@ Guacamole.ArrayBufferWriter = function(stream) {
|
|
|
203
202
|
* @type {!number}
|
|
204
203
|
*/
|
|
205
204
|
Guacamole.ArrayBufferWriter.DEFAULT_BLOB_LENGTH = 6048;
|
|
206
|
-
|
|
207
205
|
/*
|
|
208
206
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
209
207
|
* or more contributor license agreements. See the NOTICE file
|
|
@@ -283,7 +281,6 @@ Guacamole.AudioContextFactory = {
|
|
|
283
281
|
}
|
|
284
282
|
|
|
285
283
|
};
|
|
286
|
-
|
|
287
284
|
/*
|
|
288
285
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
289
286
|
* or more contributor license agreements. See the NOTICE file
|
|
@@ -790,7 +787,6 @@ Guacamole.RawAudioPlayer.getSupportedTypes = function getSupportedTypes() {
|
|
|
790
787
|
];
|
|
791
788
|
|
|
792
789
|
};
|
|
793
|
-
|
|
794
790
|
/*
|
|
795
791
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
796
792
|
* or more contributor license agreements. See the NOTICE file
|
|
@@ -1395,7 +1391,6 @@ Guacamole.RawAudioRecorder.getSupportedTypes = function getSupportedTypes() {
|
|
|
1395
1391
|
];
|
|
1396
1392
|
|
|
1397
1393
|
};
|
|
1398
|
-
|
|
1399
1394
|
/*
|
|
1400
1395
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
1401
1396
|
* or more contributor license agreements. See the NOTICE file
|
|
@@ -1534,8 +1529,7 @@ Guacamole.BlobReader = function(stream, mimetype) {
|
|
|
1534
1529
|
*/
|
|
1535
1530
|
this.onend = null;
|
|
1536
1531
|
|
|
1537
|
-
}
|
|
1538
|
-
/*
|
|
1532
|
+
};/*
|
|
1539
1533
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
1540
1534
|
* or more contributor license agreements. See the NOTICE file
|
|
1541
1535
|
* distributed with this work for additional information
|
|
@@ -1780,7 +1774,6 @@ Guacamole.BlobWriter = function BlobWriter(stream) {
|
|
|
1780
1774
|
this.oncomplete = null;
|
|
1781
1775
|
|
|
1782
1776
|
};
|
|
1783
|
-
|
|
1784
1777
|
/*
|
|
1785
1778
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
1786
1779
|
* or more contributor license agreements. See the NOTICE file
|
|
@@ -1825,7 +1818,36 @@ Guacamole.Client = function(tunnel) {
|
|
|
1825
1818
|
var currentState = STATE_IDLE;
|
|
1826
1819
|
|
|
1827
1820
|
var currentTimestamp = 0;
|
|
1828
|
-
|
|
1821
|
+
|
|
1822
|
+
/**
|
|
1823
|
+
* The rough number of milliseconds to wait between sending keep-alive
|
|
1824
|
+
* pings. This may vary depending on how frequently the browser allows
|
|
1825
|
+
* timers to run, as well as how frequently the client receives messages
|
|
1826
|
+
* from the server.
|
|
1827
|
+
*
|
|
1828
|
+
* @private
|
|
1829
|
+
* @constant
|
|
1830
|
+
* @type {!number}
|
|
1831
|
+
*/
|
|
1832
|
+
var KEEP_ALIVE_FREQUENCY = 5000;
|
|
1833
|
+
|
|
1834
|
+
/**
|
|
1835
|
+
* The current keep-alive ping timeout ID, if any. This will only be set
|
|
1836
|
+
* upon connecting.
|
|
1837
|
+
*
|
|
1838
|
+
* @private
|
|
1839
|
+
* @type {number}
|
|
1840
|
+
*/
|
|
1841
|
+
var keepAliveTimeout = null;
|
|
1842
|
+
|
|
1843
|
+
/**
|
|
1844
|
+
* The timestamp of the point in time that the last keep-live ping was
|
|
1845
|
+
* sent, in milliseconds elapsed since midnight of January 1, 1970 UTC.
|
|
1846
|
+
*
|
|
1847
|
+
* @private
|
|
1848
|
+
* @type {!number}
|
|
1849
|
+
*/
|
|
1850
|
+
var lastSentKeepAlive = 0;
|
|
1829
1851
|
|
|
1830
1852
|
/**
|
|
1831
1853
|
* Translation from Guacamole protocol line caps to Layer line caps.
|
|
@@ -2011,11 +2033,14 @@ Guacamole.Client = function(tunnel) {
|
|
|
2011
2033
|
currentState = state.currentState;
|
|
2012
2034
|
currentTimestamp = state.currentTimestamp;
|
|
2013
2035
|
|
|
2036
|
+
// Cancel any pending display operations/frames
|
|
2037
|
+
display.cancel();
|
|
2038
|
+
|
|
2014
2039
|
// Dispose of all layers
|
|
2015
2040
|
for (key in layers) {
|
|
2016
2041
|
index = parseInt(key);
|
|
2017
2042
|
if (index > 0)
|
|
2018
|
-
|
|
2043
|
+
layers[key].dispose();
|
|
2019
2044
|
}
|
|
2020
2045
|
|
|
2021
2046
|
layers = {};
|
|
@@ -2620,6 +2645,12 @@ Guacamole.Client = function(tunnel) {
|
|
|
2620
2645
|
* @event
|
|
2621
2646
|
* @param {!number} timestamp
|
|
2622
2647
|
* The timestamp associated with the sync instruction.
|
|
2648
|
+
*
|
|
2649
|
+
* @param {!number} frames
|
|
2650
|
+
* The number of frames that were considered or combined to produce the
|
|
2651
|
+
* frame associated with this sync instruction, or zero if this value
|
|
2652
|
+
* is not known or the remote desktop server provides no concept of
|
|
2653
|
+
* frames.
|
|
2623
2654
|
*/
|
|
2624
2655
|
this.onsync = null;
|
|
2625
2656
|
|
|
@@ -3310,6 +3341,7 @@ Guacamole.Client = function(tunnel) {
|
|
|
3310
3341
|
"sync": function(parameters) {
|
|
3311
3342
|
|
|
3312
3343
|
var timestamp = parseInt(parameters[0]);
|
|
3344
|
+
var frames = parameters[1] ? parseInt(parameters[1]) : 0;
|
|
3313
3345
|
|
|
3314
3346
|
// Flush display, send sync when done
|
|
3315
3347
|
display.flush(function displaySyncComplete() {
|
|
@@ -3327,7 +3359,7 @@ Guacamole.Client = function(tunnel) {
|
|
|
3327
3359
|
currentTimestamp = timestamp;
|
|
3328
3360
|
}
|
|
3329
3361
|
|
|
3330
|
-
});
|
|
3362
|
+
}, timestamp, frames);
|
|
3331
3363
|
|
|
3332
3364
|
// If received first update, no longer waiting.
|
|
3333
3365
|
if (currentState === STATE_WAITING)
|
|
@@ -3335,7 +3367,7 @@ Guacamole.Client = function(tunnel) {
|
|
|
3335
3367
|
|
|
3336
3368
|
// Call sync handler if defined
|
|
3337
3369
|
if (guac_client.onsync)
|
|
3338
|
-
guac_client.onsync(timestamp);
|
|
3370
|
+
guac_client.onsync(timestamp, frames);
|
|
3339
3371
|
|
|
3340
3372
|
},
|
|
3341
3373
|
|
|
@@ -3422,12 +3454,63 @@ Guacamole.Client = function(tunnel) {
|
|
|
3422
3454
|
|
|
3423
3455
|
};
|
|
3424
3456
|
|
|
3457
|
+
/**
|
|
3458
|
+
* Sends a keep-alive ping to the Guacamole server, advising the server
|
|
3459
|
+
* that the client is still connected and responding. The lastSentKeepAlive
|
|
3460
|
+
* timestamp is automatically updated as a result of calling this function.
|
|
3461
|
+
*
|
|
3462
|
+
* @private
|
|
3463
|
+
*/
|
|
3464
|
+
var sendKeepAlive = function sendKeepAlive() {
|
|
3465
|
+
tunnel.sendMessage('nop');
|
|
3466
|
+
lastSentKeepAlive = new Date().getTime();
|
|
3467
|
+
};
|
|
3468
|
+
|
|
3469
|
+
/**
|
|
3470
|
+
* Schedules the next keep-alive ping based on the KEEP_ALIVE_FREQUENCY and
|
|
3471
|
+
* the time that the last ping was sent, if ever. If enough time has
|
|
3472
|
+
* elapsed that a ping should have already been sent, calling this function
|
|
3473
|
+
* will send that ping immediately.
|
|
3474
|
+
*
|
|
3475
|
+
* @private
|
|
3476
|
+
*/
|
|
3477
|
+
var scheduleKeepAlive = function scheduleKeepAlive() {
|
|
3478
|
+
|
|
3479
|
+
window.clearTimeout(keepAliveTimeout);
|
|
3480
|
+
|
|
3481
|
+
var currentTime = new Date().getTime();
|
|
3482
|
+
var keepAliveDelay = Math.max(lastSentKeepAlive + KEEP_ALIVE_FREQUENCY - currentTime, 0);
|
|
3483
|
+
|
|
3484
|
+
// Ping server regularly to keep connection alive, but send the ping
|
|
3485
|
+
// immediately if enough time has elapsed that it should have already
|
|
3486
|
+
// been sent
|
|
3487
|
+
if (keepAliveDelay > 0)
|
|
3488
|
+
keepAliveTimeout = window.setTimeout(sendKeepAlive, keepAliveDelay);
|
|
3489
|
+
else
|
|
3490
|
+
sendKeepAlive();
|
|
3491
|
+
|
|
3492
|
+
};
|
|
3493
|
+
|
|
3494
|
+
/**
|
|
3495
|
+
* Stops sending any further keep-alive pings. If a keep-alive ping was
|
|
3496
|
+
* scheduled to be sent, that ping is cancelled.
|
|
3497
|
+
*
|
|
3498
|
+
* @private
|
|
3499
|
+
*/
|
|
3500
|
+
var stopKeepAlive = function stopKeepAlive() {
|
|
3501
|
+
window.clearTimeout(keepAliveTimeout);
|
|
3502
|
+
};
|
|
3503
|
+
|
|
3425
3504
|
tunnel.oninstruction = function(opcode, parameters) {
|
|
3426
3505
|
|
|
3427
3506
|
var handler = instructionHandlers[opcode];
|
|
3428
3507
|
if (handler)
|
|
3429
3508
|
handler(parameters);
|
|
3430
3509
|
|
|
3510
|
+
// Leverage network activity to ensure the next keep-alive ping is
|
|
3511
|
+
// sent, even if the browser is currently throttling timers
|
|
3512
|
+
scheduleKeepAlive();
|
|
3513
|
+
|
|
3431
3514
|
};
|
|
3432
3515
|
|
|
3433
3516
|
/**
|
|
@@ -3441,9 +3524,8 @@ Guacamole.Client = function(tunnel) {
|
|
|
3441
3524
|
|
|
3442
3525
|
setState(STATE_DISCONNECTING);
|
|
3443
3526
|
|
|
3444
|
-
// Stop
|
|
3445
|
-
|
|
3446
|
-
window.clearInterval(pingInterval);
|
|
3527
|
+
// Stop sending keep-alive messages
|
|
3528
|
+
stopKeepAlive();
|
|
3447
3529
|
|
|
3448
3530
|
// Send disconnect message and disconnect
|
|
3449
3531
|
tunnel.sendMessage("disconnect");
|
|
@@ -3477,10 +3559,9 @@ Guacamole.Client = function(tunnel) {
|
|
|
3477
3559
|
throw status;
|
|
3478
3560
|
}
|
|
3479
3561
|
|
|
3480
|
-
//
|
|
3481
|
-
|
|
3482
|
-
|
|
3483
|
-
}, 5000);
|
|
3562
|
+
// Regularly send keep-alive ping to ensure the server knows we're
|
|
3563
|
+
// still here, even if not active
|
|
3564
|
+
scheduleKeepAlive();
|
|
3484
3565
|
|
|
3485
3566
|
setState(STATE_WAITING);
|
|
3486
3567
|
};
|
|
@@ -3604,7 +3685,6 @@ Guacamole.Client.DefaultTransferFunction = {
|
|
|
3604
3685
|
}
|
|
3605
3686
|
|
|
3606
3687
|
};
|
|
3607
|
-
|
|
3608
3688
|
/*
|
|
3609
3689
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
3610
3690
|
* or more contributor license agreements. See the NOTICE file
|
|
@@ -3693,8 +3773,7 @@ Guacamole.DataURIReader = function(stream, mimetype) {
|
|
|
3693
3773
|
*/
|
|
3694
3774
|
this.onend = null;
|
|
3695
3775
|
|
|
3696
|
-
}
|
|
3697
|
-
/*
|
|
3776
|
+
};/*
|
|
3698
3777
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
3699
3778
|
* or more contributor license agreements. See the NOTICE file
|
|
3700
3779
|
* distributed with this work for additional information
|
|
@@ -3808,6 +3887,17 @@ Guacamole.Display = function() {
|
|
|
3808
3887
|
*/
|
|
3809
3888
|
this.cursorY = 0;
|
|
3810
3889
|
|
|
3890
|
+
/**
|
|
3891
|
+
* The number of milliseconds over which display rendering statistics
|
|
3892
|
+
* should be gathered, dispatching {@link #onstatistics} events as those
|
|
3893
|
+
* statistics are available. If set to zero, no statistics will be
|
|
3894
|
+
* gathered.
|
|
3895
|
+
*
|
|
3896
|
+
* @default 0
|
|
3897
|
+
* @type {!number}
|
|
3898
|
+
*/
|
|
3899
|
+
this.statisticWindow = 0;
|
|
3900
|
+
|
|
3811
3901
|
/**
|
|
3812
3902
|
* Fired when the default layer (and thus the entire Guacamole display)
|
|
3813
3903
|
* is resized.
|
|
@@ -3838,6 +3928,18 @@ Guacamole.Display = function() {
|
|
|
3838
3928
|
*/
|
|
3839
3929
|
this.oncursor = null;
|
|
3840
3930
|
|
|
3931
|
+
/**
|
|
3932
|
+
* Fired whenever performance statistics are available for recently-
|
|
3933
|
+
* rendered frames. This event will fire only if {@link #statisticWindow}
|
|
3934
|
+
* is non-zero.
|
|
3935
|
+
*
|
|
3936
|
+
* @event
|
|
3937
|
+
* @param {!Guacamole.Display.Statistics} stats
|
|
3938
|
+
* An object containing general rendering performance statistics for
|
|
3939
|
+
* the remote desktop, Guacamole server, and Guacamole client.
|
|
3940
|
+
*/
|
|
3941
|
+
this.onstatistics = null;
|
|
3942
|
+
|
|
3841
3943
|
/**
|
|
3842
3944
|
* The queue of all pending Tasks. Tasks will be run in order, with new
|
|
3843
3945
|
* tasks added at the end of the queue and old tasks removed from the
|
|
@@ -3859,11 +3961,33 @@ Guacamole.Display = function() {
|
|
|
3859
3961
|
var frames = [];
|
|
3860
3962
|
|
|
3861
3963
|
/**
|
|
3862
|
-
*
|
|
3964
|
+
* The ID of the animation frame request returned by the last call to
|
|
3965
|
+
* requestAnimationFrame(). This value will only be set if the browser
|
|
3966
|
+
* supports requestAnimationFrame(), if a frame render is currently
|
|
3967
|
+
* pending, and if the current browser tab is currently focused (likely to
|
|
3968
|
+
* handle requests for animation frames). In all other cases, this will be
|
|
3969
|
+
* null.
|
|
3970
|
+
*
|
|
3863
3971
|
* @private
|
|
3972
|
+
* @type {number}
|
|
3864
3973
|
*/
|
|
3865
|
-
|
|
3974
|
+
var inProgressFrame = null;
|
|
3975
|
+
|
|
3976
|
+
/**
|
|
3977
|
+
* Flushes all pending frames synchronously. This function will block until
|
|
3978
|
+
* all pending frames have rendered. If a frame is currently blocked by an
|
|
3979
|
+
* asynchronous operation like an image load, this function will return
|
|
3980
|
+
* after reaching that operation and the flush operation will
|
|
3981
|
+
* automamtically resume after that operation completes.
|
|
3982
|
+
*
|
|
3983
|
+
* @private
|
|
3984
|
+
*/
|
|
3985
|
+
var syncFlush = function syncFlush() {
|
|
3986
|
+
|
|
3987
|
+
var localTimestamp = 0;
|
|
3988
|
+
var remoteTimestamp = 0;
|
|
3866
3989
|
|
|
3990
|
+
var renderedLogicalFrames = 0;
|
|
3867
3991
|
var rendered_frames = 0;
|
|
3868
3992
|
|
|
3869
3993
|
// Draw all pending frames, if ready
|
|
@@ -3874,6 +3998,10 @@ Guacamole.Display = function() {
|
|
|
3874
3998
|
break;
|
|
3875
3999
|
|
|
3876
4000
|
frame.flush();
|
|
4001
|
+
|
|
4002
|
+
localTimestamp = frame.localTimestamp;
|
|
4003
|
+
remoteTimestamp = frame.remoteTimestamp;
|
|
4004
|
+
renderedLogicalFrames += frame.logicalFrames;
|
|
3877
4005
|
rendered_frames++;
|
|
3878
4006
|
|
|
3879
4007
|
}
|
|
@@ -3881,6 +4009,172 @@ Guacamole.Display = function() {
|
|
|
3881
4009
|
// Remove rendered frames from array
|
|
3882
4010
|
frames.splice(0, rendered_frames);
|
|
3883
4011
|
|
|
4012
|
+
if (rendered_frames)
|
|
4013
|
+
notifyFlushed(localTimestamp, remoteTimestamp, renderedLogicalFrames);
|
|
4014
|
+
|
|
4015
|
+
};
|
|
4016
|
+
|
|
4017
|
+
/**
|
|
4018
|
+
* Flushes all pending frames asynchronously. This function returns
|
|
4019
|
+
* immediately, relying on requestAnimationFrame() to dictate when each
|
|
4020
|
+
* frame should be flushed.
|
|
4021
|
+
*
|
|
4022
|
+
* @private
|
|
4023
|
+
*/
|
|
4024
|
+
var asyncFlush = function asyncFlush() {
|
|
4025
|
+
|
|
4026
|
+
var continueFlush = function continueFlush() {
|
|
4027
|
+
|
|
4028
|
+
// We're no longer waiting to render a frame
|
|
4029
|
+
inProgressFrame = null;
|
|
4030
|
+
|
|
4031
|
+
// Nothing to do if there are no frames remaining
|
|
4032
|
+
if (!frames.length)
|
|
4033
|
+
return;
|
|
4034
|
+
|
|
4035
|
+
// Flush the next frame only if it is ready (not awaiting
|
|
4036
|
+
// completion of some asynchronous operation like an image load)
|
|
4037
|
+
if (frames[0].isReady()) {
|
|
4038
|
+
var frame = frames.shift();
|
|
4039
|
+
frame.flush();
|
|
4040
|
+
notifyFlushed(frame.localTimestamp, frame.remoteTimestamp, frame.logicalFrames);
|
|
4041
|
+
}
|
|
4042
|
+
|
|
4043
|
+
// Request yet another animation frame if frames remain to be
|
|
4044
|
+
// flushed
|
|
4045
|
+
if (frames.length)
|
|
4046
|
+
inProgressFrame = window.requestAnimationFrame(continueFlush);
|
|
4047
|
+
|
|
4048
|
+
};
|
|
4049
|
+
|
|
4050
|
+
// Begin flushing frames if not already waiting to render a frame
|
|
4051
|
+
if (!inProgressFrame)
|
|
4052
|
+
inProgressFrame = window.requestAnimationFrame(continueFlush);
|
|
4053
|
+
|
|
4054
|
+
};
|
|
4055
|
+
|
|
4056
|
+
/**
|
|
4057
|
+
* Recently-gathered display render statistics, as made available by calls
|
|
4058
|
+
* to notifyFlushed(). The contents of this array will be trimmed to
|
|
4059
|
+
* contain only up to {@link #statisticWindow} milliseconds of statistics.
|
|
4060
|
+
*
|
|
4061
|
+
* @private
|
|
4062
|
+
* @type {Guacamole.Display.Statistics[]}
|
|
4063
|
+
*/
|
|
4064
|
+
var statistics = [];
|
|
4065
|
+
|
|
4066
|
+
/**
|
|
4067
|
+
* Notifies that one or more frames have been successfully rendered
|
|
4068
|
+
* (flushed) to the display.
|
|
4069
|
+
*
|
|
4070
|
+
* @private
|
|
4071
|
+
* @param {!number} localTimestamp
|
|
4072
|
+
* The local timestamp of the point in time at which the most recent,
|
|
4073
|
+
* flushed frame was received by the display, in milliseconds since the
|
|
4074
|
+
* Unix Epoch.
|
|
4075
|
+
*
|
|
4076
|
+
* @param {!number} remoteTimestamp
|
|
4077
|
+
* The remote timestamp of sync instruction associated with the most
|
|
4078
|
+
* recent, flushed frame received by the display. This timestamp is in
|
|
4079
|
+
* milliseconds, but is arbitrary, having meaning only relative to
|
|
4080
|
+
* other timestamps in the same connection.
|
|
4081
|
+
*
|
|
4082
|
+
* @param {!number} logicalFrames
|
|
4083
|
+
* The number of remote desktop frames that were flushed.
|
|
4084
|
+
*/
|
|
4085
|
+
var notifyFlushed = function notifyFlushed(localTimestamp, remoteTimestamp, logicalFrames) {
|
|
4086
|
+
|
|
4087
|
+
// Ignore if statistics are not being gathered
|
|
4088
|
+
if (!guac_display.statisticWindow)
|
|
4089
|
+
return;
|
|
4090
|
+
|
|
4091
|
+
var current = new Date().getTime();
|
|
4092
|
+
|
|
4093
|
+
// Find the first statistic that is still within the configured time
|
|
4094
|
+
// window
|
|
4095
|
+
for (var first = 0; first < statistics.length; first++) {
|
|
4096
|
+
if (current - statistics[first].timestamp <= guac_display.statisticWindow)
|
|
4097
|
+
break;
|
|
4098
|
+
}
|
|
4099
|
+
|
|
4100
|
+
// Remove all statistics except those within the time window
|
|
4101
|
+
statistics.splice(0, first - 1);
|
|
4102
|
+
|
|
4103
|
+
// Record statistics for latest frame
|
|
4104
|
+
statistics.push({
|
|
4105
|
+
localTimestamp : localTimestamp,
|
|
4106
|
+
remoteTimestamp : remoteTimestamp,
|
|
4107
|
+
timestamp : current,
|
|
4108
|
+
frames : logicalFrames
|
|
4109
|
+
});
|
|
4110
|
+
|
|
4111
|
+
// Determine the actual time interval of the available statistics (this
|
|
4112
|
+
// will not perfectly match the configured interval, which is an upper
|
|
4113
|
+
// bound)
|
|
4114
|
+
var statDuration = (statistics[statistics.length - 1].timestamp - statistics[0].timestamp) / 1000;
|
|
4115
|
+
|
|
4116
|
+
// Determine the amount of time that elapsed remotely (within the
|
|
4117
|
+
// remote desktop)
|
|
4118
|
+
var remoteDuration = (statistics[statistics.length - 1].remoteTimestamp - statistics[0].remoteTimestamp) / 1000;
|
|
4119
|
+
|
|
4120
|
+
// Calculate the number of frames that have been rendered locally
|
|
4121
|
+
// within the configured time interval
|
|
4122
|
+
var localFrames = statistics.length;
|
|
4123
|
+
|
|
4124
|
+
// Calculate the number of frames actually received from the remote
|
|
4125
|
+
// desktop by the Guacamole server
|
|
4126
|
+
var remoteFrames = statistics.reduce(function sumFrames(prev, stat) {
|
|
4127
|
+
return prev + stat.frames;
|
|
4128
|
+
}, 0);
|
|
4129
|
+
|
|
4130
|
+
// Calculate the number of frames that the Guacamole server had to
|
|
4131
|
+
// drop or combine with other frames
|
|
4132
|
+
var drops = statistics.reduce(function sumDrops(prev, stat) {
|
|
4133
|
+
return prev + Math.max(0, stat.frames - 1);
|
|
4134
|
+
}, 0);
|
|
4135
|
+
|
|
4136
|
+
// Produce lag and FPS statistics from above raw measurements
|
|
4137
|
+
var stats = new Guacamole.Display.Statistics({
|
|
4138
|
+
processingLag : current - localTimestamp,
|
|
4139
|
+
desktopFps : (remoteDuration && remoteFrames) ? remoteFrames / remoteDuration : null,
|
|
4140
|
+
clientFps : statDuration ? localFrames / statDuration : null,
|
|
4141
|
+
serverFps : remoteDuration ? localFrames / remoteDuration : null,
|
|
4142
|
+
dropRate : remoteDuration ? drops / remoteDuration : null
|
|
4143
|
+
});
|
|
4144
|
+
|
|
4145
|
+
// Notify of availability of new statistics
|
|
4146
|
+
if (guac_display.onstatistics)
|
|
4147
|
+
guac_display.onstatistics(stats);
|
|
4148
|
+
|
|
4149
|
+
};
|
|
4150
|
+
|
|
4151
|
+
// Switch from asynchronous frame handling to synchronous frame handling if
|
|
4152
|
+
// requestAnimationFrame() is unlikely to be usable (browsers may not
|
|
4153
|
+
// invoke the animation frame callback if the relevant tab is not focused)
|
|
4154
|
+
window.addEventListener('blur', function switchToSyncFlush() {
|
|
4155
|
+
if (inProgressFrame && !document.hasFocus()) {
|
|
4156
|
+
|
|
4157
|
+
// Cancel pending asynchronous processing of frame ...
|
|
4158
|
+
window.cancelAnimationFrame(inProgressFrame);
|
|
4159
|
+
inProgressFrame = null;
|
|
4160
|
+
|
|
4161
|
+
// ... and instead process it synchronously
|
|
4162
|
+
syncFlush();
|
|
4163
|
+
|
|
4164
|
+
}
|
|
4165
|
+
}, true);
|
|
4166
|
+
|
|
4167
|
+
/**
|
|
4168
|
+
* Flushes all pending frames.
|
|
4169
|
+
* @private
|
|
4170
|
+
*/
|
|
4171
|
+
function __flush_frames() {
|
|
4172
|
+
|
|
4173
|
+
if (window.requestAnimationFrame && document.hasFocus())
|
|
4174
|
+
asyncFlush();
|
|
4175
|
+
else
|
|
4176
|
+
syncFlush();
|
|
4177
|
+
|
|
3884
4178
|
}
|
|
3885
4179
|
|
|
3886
4180
|
/**
|
|
@@ -3894,8 +4188,59 @@ Guacamole.Display = function() {
|
|
|
3894
4188
|
*
|
|
3895
4189
|
* @param {!Task[]} tasks
|
|
3896
4190
|
* The set of tasks which must be executed to render this frame.
|
|
4191
|
+
*
|
|
4192
|
+
* @param {number} [timestamp]
|
|
4193
|
+
* The remote timestamp of sync instruction associated with this frame.
|
|
4194
|
+
* This timestamp is in milliseconds, but is arbitrary, having meaning
|
|
4195
|
+
* only relative to other remote timestamps in the same connection. If
|
|
4196
|
+
* omitted, a compatible but local timestamp will be used instead.
|
|
4197
|
+
*
|
|
4198
|
+
* @param {number} [logicalFrames=0]
|
|
4199
|
+
* The number of remote desktop frames that were combined to produce
|
|
4200
|
+
* this frame, or zero if this value is unknown or inapplicable.
|
|
3897
4201
|
*/
|
|
3898
|
-
function Frame(callback, tasks) {
|
|
4202
|
+
var Frame = function Frame(callback, tasks, timestamp, logicalFrames) {
|
|
4203
|
+
|
|
4204
|
+
/**
|
|
4205
|
+
* The local timestamp of the point in time at which this frame was
|
|
4206
|
+
* received by the display, in milliseconds since the Unix Epoch.
|
|
4207
|
+
*
|
|
4208
|
+
* @type {!number}
|
|
4209
|
+
*/
|
|
4210
|
+
this.localTimestamp = new Date().getTime();
|
|
4211
|
+
|
|
4212
|
+
/**
|
|
4213
|
+
* The remote timestamp of sync instruction associated with this frame.
|
|
4214
|
+
* This timestamp is in milliseconds, but is arbitrary, having meaning
|
|
4215
|
+
* only relative to other remote timestamps in the same connection.
|
|
4216
|
+
*
|
|
4217
|
+
* @type {!number}
|
|
4218
|
+
*/
|
|
4219
|
+
this.remoteTimestamp = timestamp || this.localTimestamp;
|
|
4220
|
+
|
|
4221
|
+
/**
|
|
4222
|
+
* The number of remote desktop frames that were combined to produce
|
|
4223
|
+
* this frame. If unknown or not applicable, this will be zero.
|
|
4224
|
+
*
|
|
4225
|
+
* @type {!number}
|
|
4226
|
+
*/
|
|
4227
|
+
this.logicalFrames = logicalFrames || 0;
|
|
4228
|
+
|
|
4229
|
+
/**
|
|
4230
|
+
* Cancels rendering of this frame and all associated tasks. The
|
|
4231
|
+
* callback provided at construction time, if any, is not invoked.
|
|
4232
|
+
*/
|
|
4233
|
+
this.cancel = function cancel() {
|
|
4234
|
+
|
|
4235
|
+
callback = null;
|
|
4236
|
+
|
|
4237
|
+
tasks.forEach(function cancelTask(task) {
|
|
4238
|
+
task.cancel();
|
|
4239
|
+
});
|
|
4240
|
+
|
|
4241
|
+
tasks = [];
|
|
4242
|
+
|
|
4243
|
+
};
|
|
3899
4244
|
|
|
3900
4245
|
/**
|
|
3901
4246
|
* Returns whether this frame is ready to be rendered. This function
|
|
@@ -3934,7 +4279,7 @@ Guacamole.Display = function() {
|
|
|
3934
4279
|
|
|
3935
4280
|
};
|
|
3936
4281
|
|
|
3937
|
-
}
|
|
4282
|
+
};
|
|
3938
4283
|
|
|
3939
4284
|
/**
|
|
3940
4285
|
* A container for an task handler. Each operation which must be ordered
|
|
@@ -3967,6 +4312,16 @@ Guacamole.Display = function() {
|
|
|
3967
4312
|
*/
|
|
3968
4313
|
this.blocked = blocked;
|
|
3969
4314
|
|
|
4315
|
+
/**
|
|
4316
|
+
* Cancels this task such that it will not run. The task handler
|
|
4317
|
+
* provided at construction time, if any, is not invoked. Calling
|
|
4318
|
+
* execute() after calling this function has no effect.
|
|
4319
|
+
*/
|
|
4320
|
+
this.cancel = function cancel() {
|
|
4321
|
+
task.blocked = false;
|
|
4322
|
+
taskHandler = null;
|
|
4323
|
+
};
|
|
4324
|
+
|
|
3970
4325
|
/**
|
|
3971
4326
|
* Unblocks this Task, allowing it to run.
|
|
3972
4327
|
*/
|
|
@@ -4101,11 +4456,20 @@ Guacamole.Display = function() {
|
|
|
4101
4456
|
* @param {function} [callback]
|
|
4102
4457
|
* The function to call when this frame is flushed. This may happen
|
|
4103
4458
|
* immediately, or later when blocked tasks become unblocked.
|
|
4459
|
+
*
|
|
4460
|
+
* @param {number} timestamp
|
|
4461
|
+
* The remote timestamp of sync instruction associated with this frame.
|
|
4462
|
+
* This timestamp is in milliseconds, but is arbitrary, having meaning
|
|
4463
|
+
* only relative to other remote timestamps in the same connection.
|
|
4464
|
+
*
|
|
4465
|
+
* @param {number} logicalFrames
|
|
4466
|
+
* The number of remote desktop frames that were combined to produce
|
|
4467
|
+
* this frame.
|
|
4104
4468
|
*/
|
|
4105
|
-
this.flush = function(callback) {
|
|
4469
|
+
this.flush = function(callback, timestamp, logicalFrames) {
|
|
4106
4470
|
|
|
4107
4471
|
// Add frame, reset tasks
|
|
4108
|
-
frames.push(new Frame(callback, tasks));
|
|
4472
|
+
frames.push(new Frame(callback, tasks, timestamp, logicalFrames));
|
|
4109
4473
|
tasks = [];
|
|
4110
4474
|
|
|
4111
4475
|
// Attempt flush
|
|
@@ -4113,6 +4477,27 @@ Guacamole.Display = function() {
|
|
|
4113
4477
|
|
|
4114
4478
|
};
|
|
4115
4479
|
|
|
4480
|
+
/**
|
|
4481
|
+
* Cancels rendering of all pending frames and associated rendering
|
|
4482
|
+
* operations. The callbacks provided to outstanding past calls to flush(),
|
|
4483
|
+
* if any, are not invoked.
|
|
4484
|
+
*/
|
|
4485
|
+
this.cancel = function cancel() {
|
|
4486
|
+
|
|
4487
|
+
frames.forEach(function cancelFrame(frame) {
|
|
4488
|
+
frame.cancel();
|
|
4489
|
+
});
|
|
4490
|
+
|
|
4491
|
+
frames = [];
|
|
4492
|
+
|
|
4493
|
+
tasks.forEach(function cancelTask(task) {
|
|
4494
|
+
task.cancel();
|
|
4495
|
+
});
|
|
4496
|
+
|
|
4497
|
+
tasks = [];
|
|
4498
|
+
|
|
4499
|
+
};
|
|
4500
|
+
|
|
4116
4501
|
/**
|
|
4117
4502
|
* Sets the hotspot and image of the mouse cursor displayed within the
|
|
4118
4503
|
* Guacamole display.
|
|
@@ -5505,6 +5890,81 @@ Guacamole.Display.VisibleLayer = function(width, height) {
|
|
|
5505
5890
|
*/
|
|
5506
5891
|
Guacamole.Display.VisibleLayer.__next_id = 0;
|
|
5507
5892
|
|
|
5893
|
+
/**
|
|
5894
|
+
* A set of Guacamole display performance statistics, describing the speed at
|
|
5895
|
+
* which the remote desktop, Guacamole server, and Guacamole client are
|
|
5896
|
+
* rendering frames.
|
|
5897
|
+
*
|
|
5898
|
+
* @constructor
|
|
5899
|
+
* @param {Guacamole.Display.Statistics|Object} [template={}]
|
|
5900
|
+
* The object whose properties should be copied within the new
|
|
5901
|
+
* Guacamole.Display.Statistics.
|
|
5902
|
+
*/
|
|
5903
|
+
Guacamole.Display.Statistics = function Statistics(template) {
|
|
5904
|
+
|
|
5905
|
+
template = template || {};
|
|
5906
|
+
|
|
5907
|
+
/**
|
|
5908
|
+
* The amount of time that the Guacamole client is taking to render
|
|
5909
|
+
* individual frames, in milliseconds, if known. If this value is unknown,
|
|
5910
|
+
* such as if the there are insufficient frame statistics recorded to
|
|
5911
|
+
* calculate this value, this will be null.
|
|
5912
|
+
*
|
|
5913
|
+
* @type {?number}
|
|
5914
|
+
*/
|
|
5915
|
+
this.processingLag = template.processingLag;
|
|
5916
|
+
|
|
5917
|
+
/**
|
|
5918
|
+
* The framerate of the remote desktop currently being viewed within the
|
|
5919
|
+
* relevant Gucamole.Display, independent of Guacamole, in frames per
|
|
5920
|
+
* second. This represents the speed at which the remote desktop is
|
|
5921
|
+
* producing frame data for the Guacamole server to consume. If this
|
|
5922
|
+
* value is unknown, such as if the remote desktop server does not actually
|
|
5923
|
+
* define frame boundaries, this will be null.
|
|
5924
|
+
*
|
|
5925
|
+
* @type {?number}
|
|
5926
|
+
*/
|
|
5927
|
+
this.desktopFps = template.desktopFps;
|
|
5928
|
+
|
|
5929
|
+
/**
|
|
5930
|
+
* The rate at which the Guacamole server is generating frames for the
|
|
5931
|
+
* Guacamole client to consume, in frames per second. If the Guacamole
|
|
5932
|
+
* server is correctly adjusting for variance in client/browser processing
|
|
5933
|
+
* power, this rate should closely match the client rate, and should remain
|
|
5934
|
+
* independent of any network latency. If this value is unknown, such as if
|
|
5935
|
+
* the there are insufficient frame statistics recorded to calculate this
|
|
5936
|
+
* value, this will be null.
|
|
5937
|
+
*
|
|
5938
|
+
* @type {?number}
|
|
5939
|
+
*/
|
|
5940
|
+
this.serverFps = template.serverFps;
|
|
5941
|
+
|
|
5942
|
+
/**
|
|
5943
|
+
* The rate at which the Guacamole client is consuming frames generated by
|
|
5944
|
+
* the Guacamole server, in frames per second. If the Guacamole server is
|
|
5945
|
+
* correctly adjusting for variance in client/browser processing power,
|
|
5946
|
+
* this rate should closely match the server rate, regardless of any
|
|
5947
|
+
* latency on the network between the server and client. If this value is
|
|
5948
|
+
* unknown, such as if the there are insufficient frame statistics recorded
|
|
5949
|
+
* to calculate this value, this will be null.
|
|
5950
|
+
*
|
|
5951
|
+
* @type {?number}
|
|
5952
|
+
*/
|
|
5953
|
+
this.clientFps = template.clientFps;
|
|
5954
|
+
|
|
5955
|
+
/**
|
|
5956
|
+
* The rate at which the Guacamole server is dropping or combining frames
|
|
5957
|
+
* received from the remote desktop server to compensate for variance in
|
|
5958
|
+
* client/browser processing power, in frames per second. This value may
|
|
5959
|
+
* also be non-zero if the server is compensating for variances in its own
|
|
5960
|
+
* processing power, or relative slowness in image compression vs. the rate
|
|
5961
|
+
* that inbound frames are received. If this value is unknown, such as if
|
|
5962
|
+
* the remote desktop server does not actually define frame boundaries,
|
|
5963
|
+
* this will be null.
|
|
5964
|
+
*/
|
|
5965
|
+
this.dropRate = template.dropRate;
|
|
5966
|
+
|
|
5967
|
+
};
|
|
5508
5968
|
/*
|
|
5509
5969
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
5510
5970
|
* or more contributor license agreements. See the NOTICE file
|
|
@@ -5831,7 +6291,6 @@ Guacamole.Event.Target = function Target() {
|
|
|
5831
6291
|
};
|
|
5832
6292
|
|
|
5833
6293
|
};
|
|
5834
|
-
|
|
5835
6294
|
/*
|
|
5836
6295
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
5837
6296
|
* or more contributor license agreements. See the NOTICE file
|
|
@@ -5961,7 +6420,6 @@ Guacamole.InputSink = function InputSink() {
|
|
|
5961
6420
|
}, true);
|
|
5962
6421
|
|
|
5963
6422
|
};
|
|
5964
|
-
|
|
5965
6423
|
/*
|
|
5966
6424
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
5967
6425
|
* or more contributor license agreements. See the NOTICE file
|
|
@@ -6041,7 +6499,6 @@ Guacamole.InputStream = function(client, index) {
|
|
|
6041
6499
|
};
|
|
6042
6500
|
|
|
6043
6501
|
};
|
|
6044
|
-
|
|
6045
6502
|
/*
|
|
6046
6503
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
6047
6504
|
* or more contributor license agreements. See the NOTICE file
|
|
@@ -6121,7 +6578,6 @@ Guacamole.IntegerPool = function() {
|
|
|
6121
6578
|
};
|
|
6122
6579
|
|
|
6123
6580
|
};
|
|
6124
|
-
|
|
6125
6581
|
/*
|
|
6126
6582
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
6127
6583
|
* or more contributor license agreements. See the NOTICE file
|
|
@@ -6236,7 +6692,6 @@ Guacamole.JSONReader = function guacamoleJSONReader(stream) {
|
|
|
6236
6692
|
this.onend = null;
|
|
6237
6693
|
|
|
6238
6694
|
};
|
|
6239
|
-
|
|
6240
6695
|
/*
|
|
6241
6696
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
6242
6697
|
* or more contributor license agreements. See the NOTICE file
|
|
@@ -7747,7 +8202,6 @@ Guacamole.Keyboard.ModifierState.fromKeyboardEvent = function(e) {
|
|
|
7747
8202
|
return state;
|
|
7748
8203
|
|
|
7749
8204
|
};
|
|
7750
|
-
|
|
7751
8205
|
/*
|
|
7752
8206
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
7753
8207
|
* or more contributor license agreements. See the NOTICE file
|
|
@@ -8900,7 +9354,6 @@ Guacamole.Layer.Pixel = function(r, g, b, a) {
|
|
|
8900
9354
|
this.alpha = a;
|
|
8901
9355
|
|
|
8902
9356
|
};
|
|
8903
|
-
|
|
8904
9357
|
/*
|
|
8905
9358
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
8906
9359
|
* or more contributor license agreements. See the NOTICE file
|
|
@@ -10166,7 +10619,6 @@ Guacamole.Mouse.Touchscreen = function Touchscreen(element) {
|
|
|
10166
10619
|
}, false);
|
|
10167
10620
|
|
|
10168
10621
|
};
|
|
10169
|
-
|
|
10170
10622
|
/*
|
|
10171
10623
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
10172
10624
|
* or more contributor license agreements. See the NOTICE file
|
|
@@ -10193,7 +10645,6 @@ Guacamole.Mouse.Touchscreen = function Touchscreen(element) {
|
|
|
10193
10645
|
* @namespace
|
|
10194
10646
|
*/
|
|
10195
10647
|
var Guacamole = Guacamole || {};
|
|
10196
|
-
|
|
10197
10648
|
/*
|
|
10198
10649
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
10199
10650
|
* or more contributor license agreements. See the NOTICE file
|
|
@@ -10404,7 +10855,6 @@ Guacamole.Object.ROOT_STREAM = '/';
|
|
|
10404
10855
|
* @type {!string}
|
|
10405
10856
|
*/
|
|
10406
10857
|
Guacamole.Object.STREAM_INDEX_MIMETYPE = 'application/vnd.glyptodon.guacamole.stream-index+json';
|
|
10407
|
-
|
|
10408
10858
|
/*
|
|
10409
10859
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
10410
10860
|
* or more contributor license agreements. See the NOTICE file
|
|
@@ -11352,7 +11802,6 @@ Guacamole.OnScreenKeyboard.Key = function(template, name) {
|
|
|
11352
11802
|
this.requires = template.requires || [];
|
|
11353
11803
|
|
|
11354
11804
|
};
|
|
11355
|
-
|
|
11356
11805
|
/*
|
|
11357
11806
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
11358
11807
|
* or more contributor license agreements. See the NOTICE file
|
|
@@ -11428,7 +11877,6 @@ Guacamole.OutputStream = function(client, index) {
|
|
|
11428
11877
|
};
|
|
11429
11878
|
|
|
11430
11879
|
};
|
|
11431
|
-
|
|
11432
11880
|
/*
|
|
11433
11881
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
11434
11882
|
* or more contributor license agreements. See the NOTICE file
|
|
@@ -11588,7 +12036,6 @@ Guacamole.Parser = function() {
|
|
|
11588
12036
|
this.oninstruction = null;
|
|
11589
12037
|
|
|
11590
12038
|
};
|
|
11591
|
-
|
|
11592
12039
|
/*
|
|
11593
12040
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
11594
12041
|
* or more contributor license agreements. See the NOTICE file
|
|
@@ -11707,7 +12154,6 @@ Guacamole.Position.fromClientPosition = function fromClientPosition(element, cli
|
|
|
11707
12154
|
position.fromClientPosition(element, clientX, clientY);
|
|
11708
12155
|
return position;
|
|
11709
12156
|
};
|
|
11710
|
-
|
|
11711
12157
|
/*
|
|
11712
12158
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
11713
12159
|
* or more contributor license agreements. See the NOTICE file
|
|
@@ -11854,7 +12300,6 @@ Guacamole.RawAudioFormat.parse = function parseFormat(mimetype) {
|
|
|
11854
12300
|
});
|
|
11855
12301
|
|
|
11856
12302
|
};
|
|
11857
|
-
|
|
11858
12303
|
/*
|
|
11859
12304
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
11860
12305
|
* or more contributor license agreements. See the NOTICE file
|
|
@@ -11877,18 +12322,20 @@ Guacamole.RawAudioFormat.parse = function parseFormat(mimetype) {
|
|
|
11877
12322
|
var Guacamole = Guacamole || {};
|
|
11878
12323
|
|
|
11879
12324
|
/**
|
|
11880
|
-
* A recording of a Guacamole session. Given a {@link Guacamole.Tunnel},
|
|
11881
|
-
* Guacamole.SessionRecording automatically
|
|
11882
|
-
*
|
|
11883
|
-
* controlled through function calls to the
|
|
11884
|
-
* while the recording has not yet finished
|
|
12325
|
+
* A recording of a Guacamole session. Given a {@link Guacamole.Tunnel} or Blob,
|
|
12326
|
+
* the Guacamole.SessionRecording automatically parses Guacamole instructions
|
|
12327
|
+
* within the recording source as it plays back the recording. Playback of the
|
|
12328
|
+
* recording may be controlled through function calls to the
|
|
12329
|
+
* Guacamole.SessionRecording, even while the recording has not yet finished
|
|
12330
|
+
* being created or downloaded. Parsing of the contents of the recording will
|
|
12331
|
+
* begin immediately and automatically after this constructor is invoked.
|
|
11885
12332
|
*
|
|
11886
12333
|
* @constructor
|
|
11887
|
-
* @param {!Guacamole.Tunnel}
|
|
11888
|
-
* The
|
|
12334
|
+
* @param {!Blob|Guacamole.Tunnel} source
|
|
12335
|
+
* The Blob from which the instructions of the recording should
|
|
11889
12336
|
* be read.
|
|
11890
12337
|
*/
|
|
11891
|
-
Guacamole.SessionRecording = function SessionRecording(
|
|
12338
|
+
Guacamole.SessionRecording = function SessionRecording(source) {
|
|
11892
12339
|
|
|
11893
12340
|
/**
|
|
11894
12341
|
* Reference to this Guacamole.SessionRecording.
|
|
@@ -11899,60 +12346,63 @@ Guacamole.SessionRecording = function SessionRecording(tunnel) {
|
|
|
11899
12346
|
var recording = this;
|
|
11900
12347
|
|
|
11901
12348
|
/**
|
|
11902
|
-
* The
|
|
11903
|
-
*
|
|
12349
|
+
* The Blob from which the instructions of the recording should be read.
|
|
12350
|
+
* Note that this value is initialized far below.
|
|
11904
12351
|
*
|
|
11905
12352
|
* @private
|
|
11906
|
-
* @
|
|
11907
|
-
* @type {!number}
|
|
12353
|
+
* @type {!Blob}
|
|
11908
12354
|
*/
|
|
11909
|
-
var
|
|
12355
|
+
var recordingBlob;
|
|
11910
12356
|
|
|
11911
12357
|
/**
|
|
11912
|
-
* The
|
|
12358
|
+
* The tunnel from which the recording should be read, if the recording is
|
|
12359
|
+
* being read from a tunnel. If the recording was supplied as a Blob, this
|
|
12360
|
+
* will be null.
|
|
11913
12361
|
*
|
|
11914
12362
|
* @private
|
|
11915
|
-
* @
|
|
11916
|
-
* @type {!number}
|
|
12363
|
+
* @type {Guacamole.Tunnel}
|
|
11917
12364
|
*/
|
|
11918
|
-
var
|
|
12365
|
+
var tunnel = null;
|
|
11919
12366
|
|
|
11920
12367
|
/**
|
|
11921
|
-
* The
|
|
11922
|
-
*
|
|
11923
|
-
*
|
|
12368
|
+
* The number of bytes that this Guacamole.SessionRecording should attempt
|
|
12369
|
+
* to read from the given blob in each read operation. Larger blocks will
|
|
12370
|
+
* generally read the blob more quickly, but may result in excessive
|
|
12371
|
+
* time being spent within the parser, making the page unresponsive
|
|
12372
|
+
* while the recording is loading.
|
|
11924
12373
|
*
|
|
11925
12374
|
* @private
|
|
11926
12375
|
* @constant
|
|
11927
|
-
* @type {
|
|
12376
|
+
* @type {Number}
|
|
11928
12377
|
*/
|
|
11929
|
-
var
|
|
12378
|
+
var BLOCK_SIZE = 262144;
|
|
11930
12379
|
|
|
11931
12380
|
/**
|
|
11932
|
-
*
|
|
12381
|
+
* The minimum number of characters which must have been read between
|
|
12382
|
+
* keyframes.
|
|
11933
12383
|
*
|
|
11934
12384
|
* @private
|
|
11935
|
-
* @
|
|
12385
|
+
* @constant
|
|
12386
|
+
* @type {Number}
|
|
11936
12387
|
*/
|
|
11937
|
-
var
|
|
12388
|
+
var KEYFRAME_CHAR_INTERVAL = 16384;
|
|
11938
12389
|
|
|
11939
12390
|
/**
|
|
11940
|
-
*
|
|
11941
|
-
* the frames array.
|
|
12391
|
+
* The minimum number of milliseconds which must elapse between keyframes.
|
|
11942
12392
|
*
|
|
11943
12393
|
* @private
|
|
11944
|
-
* @
|
|
12394
|
+
* @constant
|
|
12395
|
+
* @type {Number}
|
|
11945
12396
|
*/
|
|
11946
|
-
var
|
|
12397
|
+
var KEYFRAME_TIME_INTERVAL = 5000;
|
|
11947
12398
|
|
|
11948
12399
|
/**
|
|
11949
|
-
*
|
|
11950
|
-
* provided tunnel since the last frame was flagged for use as a keyframe.
|
|
12400
|
+
* All frames parsed from the provided blob.
|
|
11951
12401
|
*
|
|
11952
12402
|
* @private
|
|
11953
|
-
* @type {!
|
|
12403
|
+
* @type {!Guacamole.SessionRecording._Frame[]}
|
|
11954
12404
|
*/
|
|
11955
|
-
var
|
|
12405
|
+
var frames = [];
|
|
11956
12406
|
|
|
11957
12407
|
/**
|
|
11958
12408
|
* The timestamp of the last frame which was flagged for use as a keyframe.
|
|
@@ -11961,7 +12411,7 @@ Guacamole.SessionRecording = function SessionRecording(tunnel) {
|
|
|
11961
12411
|
* @private
|
|
11962
12412
|
* @type {!number}
|
|
11963
12413
|
*/
|
|
11964
|
-
var
|
|
12414
|
+
var lastKeyframe = 0;
|
|
11965
12415
|
|
|
11966
12416
|
/**
|
|
11967
12417
|
* Tunnel which feeds arbitrary instructions to the client used by this
|
|
@@ -12009,14 +12459,180 @@ Guacamole.SessionRecording = function SessionRecording(tunnel) {
|
|
|
12009
12459
|
var startRealTimestamp = null;
|
|
12010
12460
|
|
|
12011
12461
|
/**
|
|
12012
|
-
*
|
|
12013
|
-
*
|
|
12014
|
-
*
|
|
12462
|
+
* An object containing a single "aborted" property which is set to
|
|
12463
|
+
* true if the in-progress seek operation should be aborted. If no seek
|
|
12464
|
+
* operation is in progress, this will be null.
|
|
12015
12465
|
*
|
|
12016
12466
|
* @private
|
|
12017
|
-
* @type {
|
|
12467
|
+
* @type {object}
|
|
12468
|
+
*/
|
|
12469
|
+
var activeSeek = null;
|
|
12470
|
+
|
|
12471
|
+
/**
|
|
12472
|
+
* The byte offset within the recording blob of the first character of
|
|
12473
|
+
* the first instruction of the current frame. Here, "current frame"
|
|
12474
|
+
* refers to the frame currently being parsed when the provided
|
|
12475
|
+
* recording is initially loading. If the recording is not being
|
|
12476
|
+
* loaded, this value has no meaning.
|
|
12477
|
+
*
|
|
12478
|
+
* @private
|
|
12479
|
+
* @type {!number}
|
|
12480
|
+
*/
|
|
12481
|
+
var frameStart = 0;
|
|
12482
|
+
|
|
12483
|
+
/**
|
|
12484
|
+
* The byte offset within the recording blob of the character which
|
|
12485
|
+
* follows the last character of the most recently parsed instruction
|
|
12486
|
+
* of the current frame. Here, "current frame" refers to the frame
|
|
12487
|
+
* currently being parsed when the provided recording is initially
|
|
12488
|
+
* loading. If the recording is not being loaded, this value has no
|
|
12489
|
+
* meaning.
|
|
12490
|
+
*
|
|
12491
|
+
* @private
|
|
12492
|
+
* @type {!number}
|
|
12493
|
+
*/
|
|
12494
|
+
var frameEnd = 0;
|
|
12495
|
+
|
|
12496
|
+
/**
|
|
12497
|
+
* Whether the initial loading process has been aborted. If the loading
|
|
12498
|
+
* process has been aborted, no further blocks of data should be read
|
|
12499
|
+
* from the recording.
|
|
12500
|
+
*
|
|
12501
|
+
* @private
|
|
12502
|
+
* @type {!boolean}
|
|
12503
|
+
*/
|
|
12504
|
+
var aborted = false;
|
|
12505
|
+
|
|
12506
|
+
/**
|
|
12507
|
+
* The function to invoke when the seek operation initiated by a call
|
|
12508
|
+
* to seek() is cancelled or successfully completed. If no seek
|
|
12509
|
+
* operation is in progress, this will be null.
|
|
12510
|
+
*
|
|
12511
|
+
* @private
|
|
12512
|
+
* @type {function}
|
|
12513
|
+
*/
|
|
12514
|
+
var seekCallback = null;
|
|
12515
|
+
|
|
12516
|
+
/**
|
|
12517
|
+
* Parses all Guacamole instructions within the given blob, invoking
|
|
12518
|
+
* the provided instruction callback for each such instruction. Once
|
|
12519
|
+
* the end of the blob has been reached (no instructions remain to be
|
|
12520
|
+
* parsed), the provided completion callback is invoked. If a parse
|
|
12521
|
+
* error prevents reading instructions from the blob, the onerror
|
|
12522
|
+
* callback of the Guacamole.SessionRecording is invoked, and no further
|
|
12523
|
+
* data is handled within the blob.
|
|
12524
|
+
*
|
|
12525
|
+
* @private
|
|
12526
|
+
* @param {!Blob} blob
|
|
12527
|
+
* The blob to parse Guacamole instructions from.
|
|
12528
|
+
*
|
|
12529
|
+
* @param {function} [instructionCallback]
|
|
12530
|
+
* The callback to invoke for each Guacamole instruction read from
|
|
12531
|
+
* the given blob. This function must accept the same arguments
|
|
12532
|
+
* as the oninstruction handler of Guacamole.Parser.
|
|
12533
|
+
*
|
|
12534
|
+
* @param {function} [completionCallback]
|
|
12535
|
+
* The callback to invoke once all instructions have been read from
|
|
12536
|
+
* the given blob.
|
|
12537
|
+
*/
|
|
12538
|
+
var parseBlob = function parseBlob(blob, instructionCallback, completionCallback) {
|
|
12539
|
+
|
|
12540
|
+
// Do not read any further blocks if loading has been aborted
|
|
12541
|
+
if (aborted && blob === recordingBlob)
|
|
12542
|
+
return;
|
|
12543
|
+
|
|
12544
|
+
// Prepare a parser to handle all instruction data within the blob,
|
|
12545
|
+
// automatically invoking the provided instruction callback for all
|
|
12546
|
+
// parsed instructions
|
|
12547
|
+
var parser = new Guacamole.Parser();
|
|
12548
|
+
parser.oninstruction = instructionCallback;
|
|
12549
|
+
|
|
12550
|
+
var offset = 0;
|
|
12551
|
+
var reader = new FileReader();
|
|
12552
|
+
|
|
12553
|
+
/**
|
|
12554
|
+
* Reads the block of data at offset bytes within the blob. If no
|
|
12555
|
+
* such block exists, then the completion callback provided to
|
|
12556
|
+
* parseBlob() is invoked as all data has been read.
|
|
12557
|
+
*
|
|
12558
|
+
* @private
|
|
12559
|
+
*/
|
|
12560
|
+
var readNextBlock = function readNextBlock() {
|
|
12561
|
+
|
|
12562
|
+
// Do not read any further blocks if loading has been aborted
|
|
12563
|
+
if (aborted && blob === recordingBlob)
|
|
12564
|
+
return;
|
|
12565
|
+
|
|
12566
|
+
// Parse all instructions within the block, invoking the
|
|
12567
|
+
// onerror handler if a parse error occurs
|
|
12568
|
+
if (reader.readyState === 2 /* DONE */) {
|
|
12569
|
+
try {
|
|
12570
|
+
parser.receive(reader.result);
|
|
12571
|
+
}
|
|
12572
|
+
catch (parseError) {
|
|
12573
|
+
if (recording.onerror) {
|
|
12574
|
+
recording.onerror(parseError.message);
|
|
12575
|
+
}
|
|
12576
|
+
return;
|
|
12577
|
+
}
|
|
12578
|
+
}
|
|
12579
|
+
|
|
12580
|
+
// If no data remains, the read operation is complete and no
|
|
12581
|
+
// further blocks need to be read
|
|
12582
|
+
if (offset >= blob.size) {
|
|
12583
|
+
if (completionCallback)
|
|
12584
|
+
completionCallback();
|
|
12585
|
+
}
|
|
12586
|
+
|
|
12587
|
+
// Otherwise, read the next block
|
|
12588
|
+
else {
|
|
12589
|
+
var block = blob.slice(offset, offset + BLOCK_SIZE);
|
|
12590
|
+
offset += block.size;
|
|
12591
|
+
reader.readAsText(block);
|
|
12592
|
+
}
|
|
12593
|
+
|
|
12594
|
+
};
|
|
12595
|
+
|
|
12596
|
+
// Read blocks until the end of the given blob is reached
|
|
12597
|
+
reader.onload = readNextBlock;
|
|
12598
|
+
readNextBlock();
|
|
12599
|
+
|
|
12600
|
+
};
|
|
12601
|
+
|
|
12602
|
+
/**
|
|
12603
|
+
* Calculates the size of the given Guacamole instruction element, in
|
|
12604
|
+
* Unicode characters. The size returned includes the characters which
|
|
12605
|
+
* make up the length, the "." separator between the length and the
|
|
12606
|
+
* element itself, and the "," or ";" terminator which follows the
|
|
12607
|
+
* element.
|
|
12608
|
+
*
|
|
12609
|
+
* @private
|
|
12610
|
+
* @param {!string} value
|
|
12611
|
+
* The value of the element which has already been parsed (lacks
|
|
12612
|
+
* the initial length, "." separator, and "," or ";" terminator).
|
|
12613
|
+
*
|
|
12614
|
+
* @returns {!number}
|
|
12615
|
+
* The number of Unicode characters which would make up the given
|
|
12616
|
+
* element within a Guacamole instruction.
|
|
12018
12617
|
*/
|
|
12019
|
-
var
|
|
12618
|
+
var getElementSize = function getElementSize(value) {
|
|
12619
|
+
|
|
12620
|
+
var valueLength = value.length;
|
|
12621
|
+
|
|
12622
|
+
// Calculate base size, assuming at least one digit, the "."
|
|
12623
|
+
// separator, and the "," or ";" terminator
|
|
12624
|
+
var protocolSize = valueLength + 3;
|
|
12625
|
+
|
|
12626
|
+
// Add one character for each additional digit that would occur
|
|
12627
|
+
// in the element length prefix
|
|
12628
|
+
while (valueLength >= 10) {
|
|
12629
|
+
protocolSize++;
|
|
12630
|
+
valueLength = Math.floor(valueLength / 10);
|
|
12631
|
+
}
|
|
12632
|
+
|
|
12633
|
+
return protocolSize;
|
|
12634
|
+
|
|
12635
|
+
};
|
|
12020
12636
|
|
|
12021
12637
|
// Start playback client connected
|
|
12022
12638
|
playbackClient.connect();
|
|
@@ -12024,13 +12640,24 @@ Guacamole.SessionRecording = function SessionRecording(tunnel) {
|
|
|
12024
12640
|
// Hide cursor unless mouse position is received
|
|
12025
12641
|
playbackClient.getDisplay().showCursor(false);
|
|
12026
12642
|
|
|
12027
|
-
|
|
12028
|
-
|
|
12643
|
+
/**
|
|
12644
|
+
* Handles a newly-received instruction, whether from the main Blob or a
|
|
12645
|
+
* tunnel, adding new frames and keyframes as necessary. Load progress is
|
|
12646
|
+
* reported via onprogress automatically.
|
|
12647
|
+
*
|
|
12648
|
+
* @private
|
|
12649
|
+
* @param {!string} opcode
|
|
12650
|
+
* The opcode of the instruction to handle.
|
|
12651
|
+
*
|
|
12652
|
+
* @param {!string[]} args
|
|
12653
|
+
* The arguments of the received instruction, if any.
|
|
12654
|
+
*/
|
|
12655
|
+
var loadInstruction = function loadInstruction(opcode, args) {
|
|
12029
12656
|
|
|
12030
|
-
//
|
|
12031
|
-
|
|
12032
|
-
|
|
12033
|
-
|
|
12657
|
+
// Advance end of frame by overall length of parsed instruction
|
|
12658
|
+
frameEnd += getElementSize(opcode);
|
|
12659
|
+
for (var i = 0; i < args.length; i++)
|
|
12660
|
+
frameEnd += getElementSize(args[i]);
|
|
12034
12661
|
|
|
12035
12662
|
// Once a sync is received, store all instructions since the last
|
|
12036
12663
|
// frame as a new frame
|
|
@@ -12040,30 +12667,97 @@ Guacamole.SessionRecording = function SessionRecording(tunnel) {
|
|
|
12040
12667
|
var timestamp = parseInt(args[0]);
|
|
12041
12668
|
|
|
12042
12669
|
// Add a new frame containing the instructions read since last frame
|
|
12043
|
-
var frame = new Guacamole.SessionRecording._Frame(timestamp,
|
|
12670
|
+
var frame = new Guacamole.SessionRecording._Frame(timestamp, frameStart, frameEnd);
|
|
12044
12671
|
frames.push(frame);
|
|
12672
|
+
frameStart = frameEnd;
|
|
12045
12673
|
|
|
12046
12674
|
// This frame should eventually become a keyframe if enough data
|
|
12047
12675
|
// has been processed and enough recording time has elapsed, or if
|
|
12048
12676
|
// this is the absolute first frame
|
|
12049
|
-
if (frames.length === 1 || (
|
|
12050
|
-
&& timestamp -
|
|
12677
|
+
if (frames.length === 1 || (frameEnd - frames[lastKeyframe].start >= KEYFRAME_CHAR_INTERVAL
|
|
12678
|
+
&& timestamp - frames[lastKeyframe].timestamp >= KEYFRAME_TIME_INTERVAL)) {
|
|
12051
12679
|
frame.keyframe = true;
|
|
12052
|
-
|
|
12053
|
-
charactersSinceLastKeyframe = 0;
|
|
12680
|
+
lastKeyframe = frames.length - 1;
|
|
12054
12681
|
}
|
|
12055
12682
|
|
|
12056
|
-
// Clear set of instructions in preparation for next frame
|
|
12057
|
-
instructions = [];
|
|
12058
|
-
|
|
12059
12683
|
// Notify that additional content is available
|
|
12060
12684
|
if (recording.onprogress)
|
|
12061
|
-
recording.onprogress(recording.getDuration());
|
|
12685
|
+
recording.onprogress(recording.getDuration(), frameEnd);
|
|
12062
12686
|
|
|
12063
12687
|
}
|
|
12064
12688
|
|
|
12065
12689
|
};
|
|
12066
12690
|
|
|
12691
|
+
/**
|
|
12692
|
+
* Notifies that the session recording has been fully loaded. If the onload
|
|
12693
|
+
* handler has not been defined, this function has no effect.
|
|
12694
|
+
*
|
|
12695
|
+
* @private
|
|
12696
|
+
*/
|
|
12697
|
+
var notifyLoaded = function notifyLoaded() {
|
|
12698
|
+
if (recording.onload)
|
|
12699
|
+
recording.onload();
|
|
12700
|
+
};
|
|
12701
|
+
|
|
12702
|
+
// Read instructions from provided blob, extracting each frame
|
|
12703
|
+
if (source instanceof Blob)
|
|
12704
|
+
parseBlob(recordingBlob, loadInstruction, notifyLoaded);
|
|
12705
|
+
|
|
12706
|
+
// If tunnel provided instead of Blob, extract frames, etc. as instructions
|
|
12707
|
+
// are received, buffering things into a Blob for future seeks
|
|
12708
|
+
else {
|
|
12709
|
+
|
|
12710
|
+
tunnel = source;
|
|
12711
|
+
recordingBlob = new Blob();
|
|
12712
|
+
|
|
12713
|
+
var errorEncountered = false;
|
|
12714
|
+
var instructionBuffer = '';
|
|
12715
|
+
|
|
12716
|
+
// Read instructions from provided tunnel, extracting each frame
|
|
12717
|
+
tunnel.oninstruction = function handleInstruction(opcode, args) {
|
|
12718
|
+
|
|
12719
|
+
// Reconstitute received instruction
|
|
12720
|
+
instructionBuffer += opcode.length + '.' + opcode;
|
|
12721
|
+
args.forEach(function appendArg(arg) {
|
|
12722
|
+
instructionBuffer += ',' + arg.length + '.' + arg;
|
|
12723
|
+
});
|
|
12724
|
+
instructionBuffer += ';';
|
|
12725
|
+
|
|
12726
|
+
// Append to Blob (creating a new Blob in the process)
|
|
12727
|
+
if (instructionBuffer.length >= BLOCK_SIZE) {
|
|
12728
|
+
recordingBlob = new Blob([recordingBlob, instructionBuffer]);
|
|
12729
|
+
instructionBuffer = '';
|
|
12730
|
+
}
|
|
12731
|
+
|
|
12732
|
+
// Load parsed instruction into recording
|
|
12733
|
+
loadInstruction(opcode, args);
|
|
12734
|
+
|
|
12735
|
+
};
|
|
12736
|
+
|
|
12737
|
+
// Report any errors encountered
|
|
12738
|
+
tunnel.onerror = function tunnelError(status) {
|
|
12739
|
+
errorEncountered = true;
|
|
12740
|
+
if (recording.onerror)
|
|
12741
|
+
recording.onerror(status.message);
|
|
12742
|
+
};
|
|
12743
|
+
|
|
12744
|
+
tunnel.onstatechange = function tunnelStateChanged(state) {
|
|
12745
|
+
if (state === Guacamole.Tunnel.State.CLOSED) {
|
|
12746
|
+
|
|
12747
|
+
// Append any remaining instructions
|
|
12748
|
+
if (instructionBuffer.length) {
|
|
12749
|
+
recordingBlob = new Blob([recordingBlob, instructionBuffer]);
|
|
12750
|
+
instructionBuffer = '';
|
|
12751
|
+
}
|
|
12752
|
+
|
|
12753
|
+
// Consider recording loaded if tunnel has closed without errors
|
|
12754
|
+
if (!errorEncountered)
|
|
12755
|
+
notifyLoaded();
|
|
12756
|
+
}
|
|
12757
|
+
};
|
|
12758
|
+
|
|
12759
|
+
}
|
|
12760
|
+
|
|
12067
12761
|
/**
|
|
12068
12762
|
* Converts the given absolute timestamp to a timestamp which is relative
|
|
12069
12763
|
* to the first frame in the recording.
|
|
@@ -12140,23 +12834,33 @@ Guacamole.SessionRecording = function SessionRecording(tunnel) {
|
|
|
12140
12834
|
* @param {!number} index
|
|
12141
12835
|
* The index of the frame within the frames array which should be
|
|
12142
12836
|
* replayed.
|
|
12837
|
+
*
|
|
12838
|
+
* @param {function} callback
|
|
12839
|
+
* The callback to invoke once replay of the frame has completed.
|
|
12143
12840
|
*/
|
|
12144
|
-
var replayFrame = function replayFrame(index) {
|
|
12841
|
+
var replayFrame = function replayFrame(index, callback) {
|
|
12145
12842
|
|
|
12146
12843
|
var frame = frames[index];
|
|
12147
12844
|
|
|
12148
12845
|
// Replay all instructions within the retrieved frame
|
|
12149
|
-
|
|
12150
|
-
|
|
12151
|
-
|
|
12152
|
-
|
|
12846
|
+
parseBlob(recordingBlob.slice(frame.start, frame.end), function handleInstruction(opcode, args) {
|
|
12847
|
+
playbackTunnel.receiveInstruction(opcode, args);
|
|
12848
|
+
}, function replayCompleted() {
|
|
12849
|
+
|
|
12850
|
+
// Store client state if frame is flagged as a keyframe
|
|
12851
|
+
if (frame.keyframe && !frame.clientState) {
|
|
12852
|
+
playbackClient.exportState(function storeClientState(state) {
|
|
12853
|
+
frame.clientState = new Blob([JSON.stringify(state)]);
|
|
12854
|
+
});
|
|
12855
|
+
}
|
|
12153
12856
|
|
|
12154
|
-
|
|
12155
|
-
|
|
12156
|
-
|
|
12157
|
-
|
|
12158
|
-
|
|
12159
|
-
|
|
12857
|
+
// Update state to correctly represent the current frame
|
|
12858
|
+
currentFrame = index;
|
|
12859
|
+
|
|
12860
|
+
if (callback)
|
|
12861
|
+
callback();
|
|
12862
|
+
|
|
12863
|
+
});
|
|
12160
12864
|
|
|
12161
12865
|
};
|
|
12162
12866
|
|
|
@@ -12172,76 +12876,84 @@ Guacamole.SessionRecording = function SessionRecording(tunnel) {
|
|
|
12172
12876
|
* The index of the frame which should become the new playback
|
|
12173
12877
|
* position.
|
|
12174
12878
|
*
|
|
12175
|
-
* @param {
|
|
12879
|
+
* @param {function} callback
|
|
12176
12880
|
* The callback to invoke once the seek operation has completed.
|
|
12177
12881
|
*
|
|
12178
|
-
* @param {number} [
|
|
12179
|
-
* The
|
|
12180
|
-
*
|
|
12882
|
+
* @param {number} [nextRealTimestamp]
|
|
12883
|
+
* The timestamp of the point in time that the given frame should be
|
|
12884
|
+
* displayed, as would be returned by new Date().getTime(). If omitted,
|
|
12885
|
+
* the frame will be displayed as soon as possible.
|
|
12181
12886
|
*/
|
|
12182
|
-
var seekToFrame = function seekToFrame(index, callback,
|
|
12887
|
+
var seekToFrame = function seekToFrame(index, callback, nextRealTimestamp) {
|
|
12183
12888
|
|
|
12184
12889
|
// Abort any in-progress seek
|
|
12185
12890
|
abortSeek();
|
|
12186
12891
|
|
|
12187
|
-
//
|
|
12188
|
-
|
|
12189
|
-
|
|
12190
|
-
|
|
12191
|
-
|
|
12192
|
-
// Back up until startIndex represents current state
|
|
12193
|
-
for (startIndex = index; startIndex >= 0; startIndex--) {
|
|
12194
|
-
|
|
12195
|
-
var frame = frames[startIndex];
|
|
12892
|
+
// Note that a new seek operation is in progress
|
|
12893
|
+
var thisSeek = activeSeek = {
|
|
12894
|
+
aborted : false
|
|
12895
|
+
};
|
|
12196
12896
|
|
|
12197
|
-
|
|
12198
|
-
// current state by definition
|
|
12199
|
-
if (startIndex === currentFrame)
|
|
12200
|
-
break;
|
|
12897
|
+
var startIndex = index;
|
|
12201
12898
|
|
|
12202
|
-
|
|
12203
|
-
|
|
12204
|
-
if (frame.clientState) {
|
|
12205
|
-
playbackClient.importState(frame.clientState);
|
|
12206
|
-
break;
|
|
12207
|
-
}
|
|
12899
|
+
// Replay any applicable incremental frames
|
|
12900
|
+
var continueReplay = function continueReplay() {
|
|
12208
12901
|
|
|
12902
|
+
// Notify of changes in position
|
|
12903
|
+
if (recording.onseek && currentFrame > startIndex) {
|
|
12904
|
+
recording.onseek(toRelativeTimestamp(frames[currentFrame].timestamp),
|
|
12905
|
+
currentFrame - startIndex, index - startIndex);
|
|
12209
12906
|
}
|
|
12210
12907
|
|
|
12211
|
-
//
|
|
12212
|
-
|
|
12908
|
+
// Cancel seek if aborted
|
|
12909
|
+
if (thisSeek.aborted)
|
|
12910
|
+
return;
|
|
12213
12911
|
|
|
12214
|
-
|
|
12912
|
+
// If frames remain, replay the next frame
|
|
12913
|
+
if (currentFrame < index)
|
|
12914
|
+
replayFrame(currentFrame + 1, continueReplay);
|
|
12215
12915
|
|
|
12216
|
-
//
|
|
12217
|
-
|
|
12916
|
+
// Otherwise, the seek operation is completed
|
|
12917
|
+
else
|
|
12918
|
+
callback();
|
|
12218
12919
|
|
|
12219
|
-
|
|
12220
|
-
var currentTime = new Date().getTime();
|
|
12221
|
-
if (currentTime - startTime >= MAXIMUM_SEEK_TIME)
|
|
12222
|
-
break;
|
|
12920
|
+
};
|
|
12223
12921
|
|
|
12224
|
-
|
|
12225
|
-
|
|
12922
|
+
// Continue replay after requested delay has elapsed, or
|
|
12923
|
+
// immediately if no delay was requested
|
|
12924
|
+
var continueAfterRequiredDelay = function continueAfterRequiredDelay() {
|
|
12925
|
+
var delay = nextRealTimestamp ? Math.max(nextRealTimestamp - new Date().getTime(), 0) : 0;
|
|
12926
|
+
if (delay)
|
|
12927
|
+
window.setTimeout(continueReplay, delay);
|
|
12928
|
+
else
|
|
12929
|
+
continueReplay();
|
|
12930
|
+
};
|
|
12226
12931
|
|
|
12227
|
-
|
|
12228
|
-
|
|
12932
|
+
// Back up until startIndex represents current state
|
|
12933
|
+
for (; startIndex >= 0; startIndex--) {
|
|
12229
12934
|
|
|
12230
|
-
|
|
12231
|
-
if (recording.onseek)
|
|
12232
|
-
recording.onseek(recording.getPosition());
|
|
12935
|
+
var frame = frames[startIndex];
|
|
12233
12936
|
|
|
12234
|
-
// If
|
|
12235
|
-
|
|
12236
|
-
|
|
12237
|
-
|
|
12937
|
+
// If we've reached the current frame, startIndex represents
|
|
12938
|
+
// current state by definition
|
|
12939
|
+
if (startIndex === currentFrame)
|
|
12940
|
+
break;
|
|
12238
12941
|
|
|
12239
|
-
//
|
|
12240
|
-
|
|
12241
|
-
|
|
12942
|
+
// If frame has associated absolute state, make that frame the
|
|
12943
|
+
// current state
|
|
12944
|
+
if (frame.clientState) {
|
|
12945
|
+
frame.clientState.text().then(function textReady(text) {
|
|
12946
|
+
playbackClient.importState(JSON.parse(text));
|
|
12947
|
+
currentFrame = startIndex;
|
|
12948
|
+
continueAfterRequiredDelay();
|
|
12949
|
+
});
|
|
12950
|
+
return;
|
|
12951
|
+
}
|
|
12242
12952
|
|
|
12243
|
-
}
|
|
12953
|
+
}
|
|
12244
12954
|
|
|
12955
|
+
continueAfterRequiredDelay();
|
|
12956
|
+
|
|
12245
12957
|
};
|
|
12246
12958
|
|
|
12247
12959
|
/**
|
|
@@ -12251,7 +12963,10 @@ Guacamole.SessionRecording = function SessionRecording(tunnel) {
|
|
|
12251
12963
|
* @private
|
|
12252
12964
|
*/
|
|
12253
12965
|
var abortSeek = function abortSeek() {
|
|
12254
|
-
|
|
12966
|
+
if (activeSeek) {
|
|
12967
|
+
activeSeek.aborted = true;
|
|
12968
|
+
activeSeek = null;
|
|
12969
|
+
}
|
|
12255
12970
|
};
|
|
12256
12971
|
|
|
12257
12972
|
/**
|
|
@@ -12273,14 +12988,10 @@ Guacamole.SessionRecording = function SessionRecording(tunnel) {
|
|
|
12273
12988
|
// frame begins
|
|
12274
12989
|
var nextRealTimestamp = next.timestamp - startVideoTimestamp + startRealTimestamp;
|
|
12275
12990
|
|
|
12276
|
-
// Calculate the relative delay between the current time and
|
|
12277
|
-
// the next frame start
|
|
12278
|
-
var delay = Math.max(nextRealTimestamp - new Date().getTime(), 0);
|
|
12279
|
-
|
|
12280
12991
|
// Advance to next frame after enough time has elapsed
|
|
12281
12992
|
seekToFrame(currentFrame + 1, function frameDelayElapsed() {
|
|
12282
12993
|
continuePlayback();
|
|
12283
|
-
},
|
|
12994
|
+
}, nextRealTimestamp);
|
|
12284
12995
|
|
|
12285
12996
|
}
|
|
12286
12997
|
|
|
@@ -12290,6 +13001,32 @@ Guacamole.SessionRecording = function SessionRecording(tunnel) {
|
|
|
12290
13001
|
|
|
12291
13002
|
};
|
|
12292
13003
|
|
|
13004
|
+
/**
|
|
13005
|
+
* Fired when loading of this recording has completed and all frames
|
|
13006
|
+
* are available.
|
|
13007
|
+
*
|
|
13008
|
+
* @event
|
|
13009
|
+
*/
|
|
13010
|
+
this.onload = null;
|
|
13011
|
+
|
|
13012
|
+
/**
|
|
13013
|
+
* Fired when an error occurs which prevents the recording from being
|
|
13014
|
+
* played back.
|
|
13015
|
+
*
|
|
13016
|
+
* @event
|
|
13017
|
+
* @param {!string} message
|
|
13018
|
+
* A human-readable message describing the error that occurred.
|
|
13019
|
+
*/
|
|
13020
|
+
this.onerror = null;
|
|
13021
|
+
|
|
13022
|
+
/**
|
|
13023
|
+
* Fired when further loading of this recording has been explicitly
|
|
13024
|
+
* aborted through a call to abort().
|
|
13025
|
+
*
|
|
13026
|
+
* @event
|
|
13027
|
+
*/
|
|
13028
|
+
this.onabort = null;
|
|
13029
|
+
|
|
12293
13030
|
/**
|
|
12294
13031
|
* Fired when new frames have become available while the recording is
|
|
12295
13032
|
* being downloaded.
|
|
@@ -12297,6 +13034,9 @@ Guacamole.SessionRecording = function SessionRecording(tunnel) {
|
|
|
12297
13034
|
* @event
|
|
12298
13035
|
* @param {!number} duration
|
|
12299
13036
|
* The new duration of the recording, in milliseconds.
|
|
13037
|
+
*
|
|
13038
|
+
* @param {!number} parsedSize
|
|
13039
|
+
* The number of bytes that have been loaded/parsed.
|
|
12300
13040
|
*/
|
|
12301
13041
|
this.onprogress = null;
|
|
12302
13042
|
|
|
@@ -12323,27 +13063,59 @@ Guacamole.SessionRecording = function SessionRecording(tunnel) {
|
|
|
12323
13063
|
* @event
|
|
12324
13064
|
* @param {!number} position
|
|
12325
13065
|
* The new position within the recording, in milliseconds.
|
|
13066
|
+
*
|
|
13067
|
+
* @param {!number} current
|
|
13068
|
+
* The number of frames that have been seeked through. If not
|
|
13069
|
+
* seeking through multiple frames due to a call to seek(), this
|
|
13070
|
+
* will be 1.
|
|
13071
|
+
*
|
|
13072
|
+
* @param {!number} total
|
|
13073
|
+
* The number of frames that are being seeked through in the
|
|
13074
|
+
* current seek operation. If not seeking through multiple frames
|
|
13075
|
+
* due to a call to seek(), this will be 1.
|
|
12326
13076
|
*/
|
|
12327
13077
|
this.onseek = null;
|
|
12328
13078
|
|
|
12329
13079
|
/**
|
|
12330
13080
|
* Connects the underlying tunnel, beginning download of the Guacamole
|
|
12331
13081
|
* session. Playback of the Guacamole session cannot occur until at least
|
|
12332
|
-
* one frame worth of instructions has been downloaded.
|
|
13082
|
+
* one frame worth of instructions has been downloaded. If the underlying
|
|
13083
|
+
* recording source is a Blob, this function has no effect.
|
|
12333
13084
|
*
|
|
12334
13085
|
* @param {string} [data]
|
|
12335
13086
|
* The data to send to the tunnel when connecting.
|
|
12336
13087
|
*/
|
|
12337
13088
|
this.connect = function connect(data) {
|
|
12338
|
-
tunnel
|
|
13089
|
+
if (tunnel)
|
|
13090
|
+
tunnel.connect(data);
|
|
12339
13091
|
};
|
|
12340
13092
|
|
|
12341
13093
|
/**
|
|
12342
13094
|
* Disconnects the underlying tunnel, stopping further download of the
|
|
12343
|
-
* Guacamole session.
|
|
13095
|
+
* Guacamole session. If the underlying recording source is a Blob, this
|
|
13096
|
+
* function has no effect.
|
|
12344
13097
|
*/
|
|
12345
13098
|
this.disconnect = function disconnect() {
|
|
12346
|
-
tunnel
|
|
13099
|
+
if (tunnel)
|
|
13100
|
+
tunnel.disconnect();
|
|
13101
|
+
};
|
|
13102
|
+
|
|
13103
|
+
/**
|
|
13104
|
+
* Aborts the loading process, stopping further processing of the
|
|
13105
|
+
* provided data. If the underlying recording source is a Guacamole tunnel,
|
|
13106
|
+
* it will be disconnected.
|
|
13107
|
+
*/
|
|
13108
|
+
this.abort = function abort() {
|
|
13109
|
+
if (!aborted) {
|
|
13110
|
+
|
|
13111
|
+
aborted = true;
|
|
13112
|
+
if (recording.onabort)
|
|
13113
|
+
recording.onabort();
|
|
13114
|
+
|
|
13115
|
+
if (tunnel)
|
|
13116
|
+
tunnel.disconnect();
|
|
13117
|
+
|
|
13118
|
+
}
|
|
12347
13119
|
};
|
|
12348
13120
|
|
|
12349
13121
|
/**
|
|
@@ -12460,23 +13232,48 @@ Guacamole.SessionRecording = function SessionRecording(tunnel) {
|
|
|
12460
13232
|
if (frames.length === 0)
|
|
12461
13233
|
return;
|
|
12462
13234
|
|
|
13235
|
+
// Abort active seek operation, if any
|
|
13236
|
+
recording.cancel();
|
|
13237
|
+
|
|
12463
13238
|
// Pause playback, preserving playback state
|
|
12464
13239
|
var originallyPlaying = recording.isPlaying();
|
|
12465
13240
|
recording.pause();
|
|
12466
13241
|
|
|
12467
|
-
//
|
|
12468
|
-
|
|
13242
|
+
// Restore playback when seek is completed or cancelled
|
|
13243
|
+
seekCallback = function restorePlaybackState() {
|
|
13244
|
+
|
|
13245
|
+
// Seek is no longer in progress
|
|
13246
|
+
seekCallback = null;
|
|
12469
13247
|
|
|
12470
13248
|
// Restore playback state
|
|
12471
|
-
if (originallyPlaying)
|
|
13249
|
+
if (originallyPlaying) {
|
|
12472
13250
|
recording.play();
|
|
13251
|
+
originallyPlaying = null;
|
|
13252
|
+
}
|
|
12473
13253
|
|
|
12474
13254
|
// Notify that seek has completed
|
|
12475
13255
|
if (callback)
|
|
12476
13256
|
callback();
|
|
12477
13257
|
|
|
12478
|
-
}
|
|
13258
|
+
};
|
|
13259
|
+
|
|
13260
|
+
// Perform seek
|
|
13261
|
+
seekToFrame(findFrame(0, frames.length - 1, position), seekCallback);
|
|
13262
|
+
|
|
13263
|
+
};
|
|
12479
13264
|
|
|
13265
|
+
/**
|
|
13266
|
+
* Cancels the current seek operation, setting the current frame of the
|
|
13267
|
+
* recording to wherever the seek operation was able to reach prior to
|
|
13268
|
+
* being cancelled. If a callback was provided to seek(), that callback
|
|
13269
|
+
* is invoked. If a seek operation is not currently underway, this
|
|
13270
|
+
* function has no effect.
|
|
13271
|
+
*/
|
|
13272
|
+
this.cancel = function cancel() {
|
|
13273
|
+
if (seekCallback) {
|
|
13274
|
+
abortSeek();
|
|
13275
|
+
seekCallback();
|
|
13276
|
+
}
|
|
12480
13277
|
};
|
|
12481
13278
|
|
|
12482
13279
|
/**
|
|
@@ -12521,11 +13318,15 @@ Guacamole.SessionRecording = function SessionRecording(tunnel) {
|
|
|
12521
13318
|
* The timestamp of this frame, as dictated by the "sync" instruction which
|
|
12522
13319
|
* terminates the frame.
|
|
12523
13320
|
*
|
|
12524
|
-
* @param {!
|
|
12525
|
-
*
|
|
12526
|
-
*
|
|
13321
|
+
* @param {!number} start
|
|
13322
|
+
* The byte offset within the blob of the first character of the first
|
|
13323
|
+
* instruction of this frame.
|
|
13324
|
+
*
|
|
13325
|
+
* @param {!number} end
|
|
13326
|
+
* The byte offset within the blob of character which follows the last
|
|
13327
|
+
* character of the last instruction of this frame.
|
|
12527
13328
|
*/
|
|
12528
|
-
Guacamole.SessionRecording._Frame = function _Frame(timestamp,
|
|
13329
|
+
Guacamole.SessionRecording._Frame = function _Frame(timestamp, start, end) {
|
|
12529
13330
|
|
|
12530
13331
|
/**
|
|
12531
13332
|
* Whether this frame should be used as a keyframe if possible. This value
|
|
@@ -12547,82 +13348,32 @@ Guacamole.SessionRecording._Frame = function _Frame(timestamp, instructions) {
|
|
|
12547
13348
|
this.timestamp = timestamp;
|
|
12548
13349
|
|
|
12549
13350
|
/**
|
|
12550
|
-
*
|
|
12551
|
-
*
|
|
12552
|
-
*
|
|
12553
|
-
* @type {!Guacamole.SessionRecording._Frame.Instruction[]}
|
|
12554
|
-
*/
|
|
12555
|
-
this.instructions = instructions;
|
|
12556
|
-
|
|
12557
|
-
/**
|
|
12558
|
-
* A snapshot of client state after this frame was rendered, as returned by
|
|
12559
|
-
* a call to exportState(). If no such snapshot has been taken, this will
|
|
12560
|
-
* be null.
|
|
13351
|
+
* The byte offset within the blob of the first character of the first
|
|
13352
|
+
* instruction of this frame.
|
|
12561
13353
|
*
|
|
12562
|
-
* @type {
|
|
12563
|
-
* @default null
|
|
12564
|
-
*/
|
|
12565
|
-
this.clientState = null;
|
|
12566
|
-
|
|
12567
|
-
};
|
|
12568
|
-
|
|
12569
|
-
/**
|
|
12570
|
-
* A Guacamole protocol instruction. Each Guacamole protocol instruction is
|
|
12571
|
-
* made up of an opcode and set of arguments.
|
|
12572
|
-
*
|
|
12573
|
-
* @private
|
|
12574
|
-
* @constructor
|
|
12575
|
-
* @param {!string} opcode
|
|
12576
|
-
* The opcode of this Guacamole instruction.
|
|
12577
|
-
*
|
|
12578
|
-
* @param {!string[]} args
|
|
12579
|
-
* All arguments associated with this Guacamole instruction.
|
|
12580
|
-
*/
|
|
12581
|
-
Guacamole.SessionRecording._Frame.Instruction = function Instruction(opcode, args) {
|
|
12582
|
-
|
|
12583
|
-
/**
|
|
12584
|
-
* Reference to this Guacamole.SessionRecording._Frame.Instruction.
|
|
12585
|
-
*
|
|
12586
|
-
* @private
|
|
12587
|
-
* @type {!Guacamole.SessionRecording._Frame.Instruction}
|
|
12588
|
-
*/
|
|
12589
|
-
var instruction = this;
|
|
12590
|
-
|
|
12591
|
-
/**
|
|
12592
|
-
* The opcode of this Guacamole instruction.
|
|
12593
|
-
*
|
|
12594
|
-
* @type {!string}
|
|
13354
|
+
* @type {!number}
|
|
12595
13355
|
*/
|
|
12596
|
-
this.
|
|
13356
|
+
this.start = start;
|
|
12597
13357
|
|
|
12598
13358
|
/**
|
|
12599
|
-
*
|
|
13359
|
+
* The byte offset within the blob of character which follows the last
|
|
13360
|
+
* character of the last instruction of this frame.
|
|
12600
13361
|
*
|
|
12601
|
-
* @type {!
|
|
13362
|
+
* @type {!number}
|
|
12602
13363
|
*/
|
|
12603
|
-
this.
|
|
13364
|
+
this.end = end;
|
|
12604
13365
|
|
|
12605
13366
|
/**
|
|
12606
|
-
*
|
|
12607
|
-
*
|
|
12608
|
-
*
|
|
12609
|
-
*
|
|
13367
|
+
* A snapshot of client state after this frame was rendered, as returned by
|
|
13368
|
+
* a call to exportState(), serialized as JSON, and stored within a Blob.
|
|
13369
|
+
* Use of Blobs here is required to ensure the browser can make use of
|
|
13370
|
+
* larger disk-backed storage if the size of the recording is large. If no
|
|
13371
|
+
* such snapshot has been taken, this will be null.
|
|
12610
13372
|
*
|
|
12611
|
-
* @
|
|
12612
|
-
*
|
|
13373
|
+
* @type {Blob}
|
|
13374
|
+
* @default null
|
|
12613
13375
|
*/
|
|
12614
|
-
this.
|
|
12615
|
-
|
|
12616
|
-
// Init with length of opcode
|
|
12617
|
-
var size = instruction.opcode.length;
|
|
12618
|
-
|
|
12619
|
-
// Add length of all arguments
|
|
12620
|
-
for (var i = 0; i < instruction.args.length; i++)
|
|
12621
|
-
size += instruction.args[i].length;
|
|
12622
|
-
|
|
12623
|
-
return size;
|
|
12624
|
-
|
|
12625
|
-
};
|
|
13376
|
+
this.clientState = null;
|
|
12626
13377
|
|
|
12627
13378
|
};
|
|
12628
13379
|
|
|
@@ -12673,9 +13424,7 @@ Guacamole.SessionRecording._PlaybackTunnel = function _PlaybackTunnel() {
|
|
|
12673
13424
|
tunnel.oninstruction(opcode, args);
|
|
12674
13425
|
};
|
|
12675
13426
|
|
|
12676
|
-
}
|
|
12677
|
-
|
|
12678
|
-
/*
|
|
13427
|
+
};/*
|
|
12679
13428
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
12680
13429
|
* or more contributor license agreements. See the NOTICE file
|
|
12681
13430
|
* distributed with this work for additional information
|
|
@@ -12997,7 +13746,6 @@ Guacamole.Status.Code.fromWebSocketCode = function fromWebSocketCode(code) {
|
|
|
12997
13746
|
return Guacamole.Status.Code.SERVER_ERROR;
|
|
12998
13747
|
|
|
12999
13748
|
};
|
|
13000
|
-
|
|
13001
13749
|
/*
|
|
13002
13750
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
13003
13751
|
* or more contributor license agreements. See the NOTICE file
|
|
@@ -13039,110 +13787,25 @@ Guacamole.StringReader = function(stream) {
|
|
|
13039
13787
|
var guac_reader = this;
|
|
13040
13788
|
|
|
13041
13789
|
/**
|
|
13042
|
-
*
|
|
13790
|
+
* Parser for received UTF-8 data.
|
|
13043
13791
|
*
|
|
13044
|
-
* @
|
|
13045
|
-
* @type {!Guacamole.ArrayBufferReader}
|
|
13792
|
+
* @type {!Guacamole.UTF8Parser}
|
|
13046
13793
|
*/
|
|
13047
|
-
var
|
|
13794
|
+
var utf8Parser = new Guacamole.UTF8Parser();
|
|
13048
13795
|
|
|
13049
13796
|
/**
|
|
13050
|
-
*
|
|
13051
|
-
*
|
|
13052
|
-
* @private
|
|
13053
|
-
* @type {!number}
|
|
13054
|
-
*/
|
|
13055
|
-
var bytes_remaining = 0;
|
|
13056
|
-
|
|
13057
|
-
/**
|
|
13058
|
-
* The current codepoint value, as calculated from bytes read so far.
|
|
13797
|
+
* Wrapped Guacamole.ArrayBufferReader.
|
|
13059
13798
|
*
|
|
13060
13799
|
* @private
|
|
13061
|
-
* @type {!
|
|
13062
|
-
*/
|
|
13063
|
-
var codepoint = 0;
|
|
13064
|
-
|
|
13065
|
-
/**
|
|
13066
|
-
* Decodes the given UTF-8 data into a Unicode string. The data may end in
|
|
13067
|
-
* the middle of a multibyte character.
|
|
13068
|
-
*
|
|
13069
|
-
* @private
|
|
13070
|
-
* @param {!ArrayBuffer} buffer
|
|
13071
|
-
* Arbitrary UTF-8 data.
|
|
13072
|
-
*
|
|
13073
|
-
* @return {!string}
|
|
13074
|
-
* A decoded Unicode string.
|
|
13800
|
+
* @type {!Guacamole.ArrayBufferReader}
|
|
13075
13801
|
*/
|
|
13076
|
-
|
|
13077
|
-
|
|
13078
|
-
var text = "";
|
|
13079
|
-
|
|
13080
|
-
var bytes = new Uint8Array(buffer);
|
|
13081
|
-
for (var i=0; i<bytes.length; i++) {
|
|
13082
|
-
|
|
13083
|
-
// Get current byte
|
|
13084
|
-
var value = bytes[i];
|
|
13085
|
-
|
|
13086
|
-
// Start new codepoint if nothing yet read
|
|
13087
|
-
if (bytes_remaining === 0) {
|
|
13088
|
-
|
|
13089
|
-
// 1 byte (0xxxxxxx)
|
|
13090
|
-
if ((value | 0x7F) === 0x7F)
|
|
13091
|
-
text += String.fromCharCode(value);
|
|
13092
|
-
|
|
13093
|
-
// 2 byte (110xxxxx)
|
|
13094
|
-
else if ((value | 0x1F) === 0xDF) {
|
|
13095
|
-
codepoint = value & 0x1F;
|
|
13096
|
-
bytes_remaining = 1;
|
|
13097
|
-
}
|
|
13098
|
-
|
|
13099
|
-
// 3 byte (1110xxxx)
|
|
13100
|
-
else if ((value | 0x0F )=== 0xEF) {
|
|
13101
|
-
codepoint = value & 0x0F;
|
|
13102
|
-
bytes_remaining = 2;
|
|
13103
|
-
}
|
|
13104
|
-
|
|
13105
|
-
// 4 byte (11110xxx)
|
|
13106
|
-
else if ((value | 0x07) === 0xF7) {
|
|
13107
|
-
codepoint = value & 0x07;
|
|
13108
|
-
bytes_remaining = 3;
|
|
13109
|
-
}
|
|
13110
|
-
|
|
13111
|
-
// Invalid byte
|
|
13112
|
-
else
|
|
13113
|
-
text += "\uFFFD";
|
|
13114
|
-
|
|
13115
|
-
}
|
|
13116
|
-
|
|
13117
|
-
// Continue existing codepoint (10xxxxxx)
|
|
13118
|
-
else if ((value | 0x3F) === 0xBF) {
|
|
13119
|
-
|
|
13120
|
-
codepoint = (codepoint << 6) | (value & 0x3F);
|
|
13121
|
-
bytes_remaining--;
|
|
13122
|
-
|
|
13123
|
-
// Write codepoint if finished
|
|
13124
|
-
if (bytes_remaining === 0)
|
|
13125
|
-
text += String.fromCharCode(codepoint);
|
|
13126
|
-
|
|
13127
|
-
}
|
|
13128
|
-
|
|
13129
|
-
// Invalid byte
|
|
13130
|
-
else {
|
|
13131
|
-
bytes_remaining = 0;
|
|
13132
|
-
text += "\uFFFD";
|
|
13133
|
-
}
|
|
13134
|
-
|
|
13135
|
-
}
|
|
13136
|
-
|
|
13137
|
-
return text;
|
|
13138
|
-
|
|
13139
|
-
}
|
|
13802
|
+
var array_reader = new Guacamole.ArrayBufferReader(stream);
|
|
13140
13803
|
|
|
13141
13804
|
// Receive blobs as strings
|
|
13142
13805
|
array_reader.ondata = function(buffer) {
|
|
13143
13806
|
|
|
13144
13807
|
// Decode UTF-8
|
|
13145
|
-
var text =
|
|
13808
|
+
var text = utf8Parser.decode(buffer);
|
|
13146
13809
|
|
|
13147
13810
|
// Call handler, if present
|
|
13148
13811
|
if (guac_reader.ontext)
|
|
@@ -13171,8 +13834,7 @@ Guacamole.StringReader = function(stream) {
|
|
|
13171
13834
|
*/
|
|
13172
13835
|
this.onend = null;
|
|
13173
13836
|
|
|
13174
|
-
}
|
|
13175
|
-
/*
|
|
13837
|
+
};/*
|
|
13176
13838
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
13177
13839
|
* or more contributor license agreements. See the NOTICE file
|
|
13178
13840
|
* distributed with this work for additional information
|
|
@@ -13376,8 +14038,7 @@ Guacamole.StringWriter = function(stream) {
|
|
|
13376
14038
|
*/
|
|
13377
14039
|
this.onack = null;
|
|
13378
14040
|
|
|
13379
|
-
}
|
|
13380
|
-
/*
|
|
14041
|
+
};/*
|
|
13381
14042
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
13382
14043
|
* or more contributor license agreements. See the NOTICE file
|
|
13383
14044
|
* distributed with this work for additional information
|
|
@@ -13657,7 +14318,6 @@ Guacamole.Touch.Event = function TouchEvent(type, event, state) {
|
|
|
13657
14318
|
this.state = state;
|
|
13658
14319
|
|
|
13659
14320
|
};
|
|
13660
|
-
|
|
13661
14321
|
/*
|
|
13662
14322
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
13663
14323
|
* or more contributor license agreements. See the NOTICE file
|
|
@@ -13764,7 +14424,7 @@ Guacamole.Tunnel = function() {
|
|
|
13764
14424
|
*
|
|
13765
14425
|
* @type {!number}
|
|
13766
14426
|
*/
|
|
13767
|
-
this.state = Guacamole.Tunnel.State.
|
|
14427
|
+
this.state = Guacamole.Tunnel.State.CLOSED;
|
|
13768
14428
|
|
|
13769
14429
|
/**
|
|
13770
14430
|
* The maximum amount of time to wait for data to be received, in
|
|
@@ -14016,12 +14676,16 @@ Guacamole.HTTPTunnel = function(tunnelURL, crossDomain, extraTunnelHeaders) {
|
|
|
14016
14676
|
}
|
|
14017
14677
|
|
|
14018
14678
|
/**
|
|
14019
|
-
*
|
|
14020
|
-
*
|
|
14021
|
-
*
|
|
14679
|
+
* Resets the state of timers tracking network activity and stability. If
|
|
14680
|
+
* those timers are not yet started, invoking this function starts them.
|
|
14681
|
+
* This function should be invoked when the tunnel is established and every
|
|
14682
|
+
* time there is network activity on the tunnel, such that the timers can
|
|
14683
|
+
* safely assume the network and/or server are not responding if this
|
|
14684
|
+
* function has not been invoked for a significant period of time.
|
|
14685
|
+
*
|
|
14022
14686
|
* @private
|
|
14023
14687
|
*/
|
|
14024
|
-
function
|
|
14688
|
+
var resetTimers = function resetTimers() {
|
|
14025
14689
|
|
|
14026
14690
|
// Get rid of old timeouts (if any)
|
|
14027
14691
|
window.clearTimeout(receive_timeout);
|
|
@@ -14041,7 +14705,7 @@ Guacamole.HTTPTunnel = function(tunnelURL, crossDomain, extraTunnelHeaders) {
|
|
|
14041
14705
|
tunnel.setState(Guacamole.Tunnel.State.UNSTABLE);
|
|
14042
14706
|
}, tunnel.unstableThreshold);
|
|
14043
14707
|
|
|
14044
|
-
}
|
|
14708
|
+
};
|
|
14045
14709
|
|
|
14046
14710
|
/**
|
|
14047
14711
|
* Closes this tunnel, signaling the given status and corresponding
|
|
@@ -14151,7 +14815,7 @@ Guacamole.HTTPTunnel = function(tunnelURL, crossDomain, extraTunnelHeaders) {
|
|
|
14151
14815
|
message_xmlhttprequest.onreadystatechange = function() {
|
|
14152
14816
|
if (message_xmlhttprequest.readyState === 4) {
|
|
14153
14817
|
|
|
14154
|
-
|
|
14818
|
+
resetTimers();
|
|
14155
14819
|
|
|
14156
14820
|
// If an error occurs during send, handle it
|
|
14157
14821
|
if (message_xmlhttprequest.status !== 200)
|
|
@@ -14241,7 +14905,7 @@ Guacamole.HTTPTunnel = function(tunnelURL, crossDomain, extraTunnelHeaders) {
|
|
|
14241
14905
|
if (xmlhttprequest.readyState === 3 ||
|
|
14242
14906
|
xmlhttprequest.readyState === 4) {
|
|
14243
14907
|
|
|
14244
|
-
|
|
14908
|
+
resetTimers();
|
|
14245
14909
|
|
|
14246
14910
|
// Also poll every 30ms (some browsers don't repeatedly call onreadystatechange for new data)
|
|
14247
14911
|
if (pollingMode === POLLING_ENABLED) {
|
|
@@ -14402,7 +15066,7 @@ Guacamole.HTTPTunnel = function(tunnelURL, crossDomain, extraTunnelHeaders) {
|
|
|
14402
15066
|
this.connect = function(data) {
|
|
14403
15067
|
|
|
14404
15068
|
// Start waiting for connect
|
|
14405
|
-
|
|
15069
|
+
resetTimers();
|
|
14406
15070
|
|
|
14407
15071
|
// Mark the tunnel as connecting
|
|
14408
15072
|
tunnel.setState(Guacamole.Tunnel.State.CONNECTING);
|
|
@@ -14420,7 +15084,7 @@ Guacamole.HTTPTunnel = function(tunnelURL, crossDomain, extraTunnelHeaders) {
|
|
|
14420
15084
|
return;
|
|
14421
15085
|
}
|
|
14422
15086
|
|
|
14423
|
-
|
|
15087
|
+
resetTimers();
|
|
14424
15088
|
|
|
14425
15089
|
// Get UUID and HTTP-specific tunnel session token from response
|
|
14426
15090
|
tunnel.setUUID(connect_xmlhttprequest.responseText);
|
|
@@ -14504,13 +15168,13 @@ Guacamole.WebSocketTunnel = function(tunnelURL) {
|
|
|
14504
15168
|
var unstableTimeout = null;
|
|
14505
15169
|
|
|
14506
15170
|
/**
|
|
14507
|
-
* The current connection stability test ping
|
|
15171
|
+
* The current connection stability test ping timeout ID, if any. This
|
|
14508
15172
|
* will only be set upon successful connection.
|
|
14509
15173
|
*
|
|
14510
15174
|
* @private
|
|
14511
15175
|
* @type {number}
|
|
14512
15176
|
*/
|
|
14513
|
-
var
|
|
15177
|
+
var pingTimeout = null;
|
|
14514
15178
|
|
|
14515
15179
|
/**
|
|
14516
15180
|
* The WebSocket protocol corresponding to the protocol used for the current
|
|
@@ -14534,6 +15198,16 @@ Guacamole.WebSocketTunnel = function(tunnelURL) {
|
|
|
14534
15198
|
*/
|
|
14535
15199
|
var PING_FREQUENCY = 500;
|
|
14536
15200
|
|
|
15201
|
+
/**
|
|
15202
|
+
* The timestamp of the point in time that the last connection stability
|
|
15203
|
+
* test ping was sent, in milliseconds elapsed since midnight of January 1,
|
|
15204
|
+
* 1970 UTC.
|
|
15205
|
+
*
|
|
15206
|
+
* @private
|
|
15207
|
+
* @type {!number}
|
|
15208
|
+
*/
|
|
15209
|
+
var lastSentPing = 0;
|
|
15210
|
+
|
|
14537
15211
|
// Transform current URL to WebSocket URL
|
|
14538
15212
|
|
|
14539
15213
|
// If not already a websocket URL
|
|
@@ -14568,16 +15242,35 @@ Guacamole.WebSocketTunnel = function(tunnelURL) {
|
|
|
14568
15242
|
}
|
|
14569
15243
|
|
|
14570
15244
|
/**
|
|
14571
|
-
*
|
|
14572
|
-
*
|
|
14573
|
-
*
|
|
15245
|
+
* Sends an internal "ping" instruction to the Guacamole WebSocket
|
|
15246
|
+
* endpoint, verifying network connection stability. If the network is
|
|
15247
|
+
* stable, the Guacamole server will receive this instruction and respond
|
|
15248
|
+
* with an identical ping.
|
|
15249
|
+
*
|
|
14574
15250
|
* @private
|
|
14575
15251
|
*/
|
|
14576
|
-
function
|
|
15252
|
+
var sendPing = function sendPing() {
|
|
15253
|
+
var currentTime = new Date().getTime();
|
|
15254
|
+
tunnel.sendMessage(Guacamole.Tunnel.INTERNAL_DATA_OPCODE, 'ping', currentTime);
|
|
15255
|
+
lastSentPing = currentTime;
|
|
15256
|
+
};
|
|
15257
|
+
|
|
15258
|
+
/**
|
|
15259
|
+
* Resets the state of timers tracking network activity and stability. If
|
|
15260
|
+
* those timers are not yet started, invoking this function starts them.
|
|
15261
|
+
* This function should be invoked when the tunnel is established and every
|
|
15262
|
+
* time there is network activity on the tunnel, such that the timers can
|
|
15263
|
+
* safely assume the network and/or server are not responding if this
|
|
15264
|
+
* function has not been invoked for a significant period of time.
|
|
15265
|
+
*
|
|
15266
|
+
* @private
|
|
15267
|
+
*/
|
|
15268
|
+
var resetTimers = function resetTimers() {
|
|
14577
15269
|
|
|
14578
15270
|
// Get rid of old timeouts (if any)
|
|
14579
15271
|
window.clearTimeout(receive_timeout);
|
|
14580
15272
|
window.clearTimeout(unstableTimeout);
|
|
15273
|
+
window.clearTimeout(pingTimeout);
|
|
14581
15274
|
|
|
14582
15275
|
// Clear unstable status
|
|
14583
15276
|
if (tunnel.state === Guacamole.Tunnel.State.UNSTABLE)
|
|
@@ -14593,7 +15286,17 @@ Guacamole.WebSocketTunnel = function(tunnelURL) {
|
|
|
14593
15286
|
tunnel.setState(Guacamole.Tunnel.State.UNSTABLE);
|
|
14594
15287
|
}, tunnel.unstableThreshold);
|
|
14595
15288
|
|
|
14596
|
-
|
|
15289
|
+
var currentTime = new Date().getTime();
|
|
15290
|
+
var pingDelay = Math.max(lastSentPing + PING_FREQUENCY - currentTime, 0);
|
|
15291
|
+
|
|
15292
|
+
// Ping tunnel endpoint regularly to test connection stability, sending
|
|
15293
|
+
// the ping immediately if enough time has already elapsed
|
|
15294
|
+
if (pingDelay > 0)
|
|
15295
|
+
pingTimeout = window.setTimeout(sendPing, pingDelay);
|
|
15296
|
+
else
|
|
15297
|
+
sendPing();
|
|
15298
|
+
|
|
15299
|
+
};
|
|
14597
15300
|
|
|
14598
15301
|
/**
|
|
14599
15302
|
* Closes this tunnel, signaling the given status and corresponding
|
|
@@ -14609,9 +15312,7 @@ Guacamole.WebSocketTunnel = function(tunnelURL) {
|
|
|
14609
15312
|
// Get rid of old timeouts (if any)
|
|
14610
15313
|
window.clearTimeout(receive_timeout);
|
|
14611
15314
|
window.clearTimeout(unstableTimeout);
|
|
14612
|
-
|
|
14613
|
-
// Cease connection test pings
|
|
14614
|
-
window.clearInterval(pingInterval);
|
|
15315
|
+
window.clearTimeout(pingTimeout);
|
|
14615
15316
|
|
|
14616
15317
|
// Ignore if already closed
|
|
14617
15318
|
if (tunnel.state === Guacamole.Tunnel.State.CLOSED)
|
|
@@ -14670,7 +15371,7 @@ Guacamole.WebSocketTunnel = function(tunnelURL) {
|
|
|
14670
15371
|
|
|
14671
15372
|
this.connect = function(data) {
|
|
14672
15373
|
|
|
14673
|
-
|
|
15374
|
+
resetTimers();
|
|
14674
15375
|
|
|
14675
15376
|
// Mark the tunnel as connecting
|
|
14676
15377
|
tunnel.setState(Guacamole.Tunnel.State.CONNECTING);
|
|
@@ -14679,14 +15380,7 @@ Guacamole.WebSocketTunnel = function(tunnelURL) {
|
|
|
14679
15380
|
socket = new WebSocket(tunnelURL + "?" + data, "guacamole");
|
|
14680
15381
|
|
|
14681
15382
|
socket.onopen = function(event) {
|
|
14682
|
-
|
|
14683
|
-
|
|
14684
|
-
// Ping tunnel endpoint regularly to test connection stability
|
|
14685
|
-
pingInterval = setInterval(function sendPing() {
|
|
14686
|
-
tunnel.sendMessage(Guacamole.Tunnel.INTERNAL_DATA_OPCODE,
|
|
14687
|
-
"ping", new Date().getTime());
|
|
14688
|
-
}, PING_FREQUENCY);
|
|
14689
|
-
|
|
15383
|
+
resetTimers();
|
|
14690
15384
|
};
|
|
14691
15385
|
|
|
14692
15386
|
socket.onclose = function(event) {
|
|
@@ -14708,7 +15402,7 @@ Guacamole.WebSocketTunnel = function(tunnelURL) {
|
|
|
14708
15402
|
|
|
14709
15403
|
socket.onmessage = function(event) {
|
|
14710
15404
|
|
|
14711
|
-
|
|
15405
|
+
resetTimers();
|
|
14712
15406
|
|
|
14713
15407
|
var message = event.data;
|
|
14714
15408
|
var startIndex = 0;
|
|
@@ -14754,7 +15448,7 @@ Guacamole.WebSocketTunnel = function(tunnelURL) {
|
|
|
14754
15448
|
if (tunnel.uuid === null) {
|
|
14755
15449
|
|
|
14756
15450
|
// Associate tunnel UUID if received
|
|
14757
|
-
if (opcode === Guacamole.Tunnel.INTERNAL_DATA_OPCODE)
|
|
15451
|
+
if (opcode === Guacamole.Tunnel.INTERNAL_DATA_OPCODE && elements.length === 1)
|
|
14758
15452
|
tunnel.setUUID(elements[0]);
|
|
14759
15453
|
|
|
14760
15454
|
// Tunnel is now open and UUID is available
|
|
@@ -14896,12 +15590,17 @@ Guacamole.ChainedTunnel = function(tunnelChain) {
|
|
|
14896
15590
|
tunnel.onstatechange = chained_tunnel.onstatechange;
|
|
14897
15591
|
tunnel.oninstruction = chained_tunnel.oninstruction;
|
|
14898
15592
|
tunnel.onerror = chained_tunnel.onerror;
|
|
14899
|
-
tunnel.onuuid = chained_tunnel.onuuid;
|
|
14900
15593
|
|
|
14901
15594
|
// Assign UUID if already known
|
|
14902
15595
|
if (tunnel.uuid)
|
|
14903
15596
|
chained_tunnel.setUUID(tunnel.uuid);
|
|
14904
15597
|
|
|
15598
|
+
// Assign any future received UUIDs such that they are
|
|
15599
|
+
// accessible from the main uuid property of the chained tunnel
|
|
15600
|
+
tunnel.onuuid = function uuidReceived(uuid) {
|
|
15601
|
+
chained_tunnel.setUUID(uuid);
|
|
15602
|
+
};
|
|
15603
|
+
|
|
14905
15604
|
committedTunnel = tunnel;
|
|
14906
15605
|
|
|
14907
15606
|
}
|
|
@@ -15006,13 +15705,14 @@ Guacamole.StaticHTTPTunnel = function StaticHTTPTunnel(url, crossDomain, extraTu
|
|
|
15006
15705
|
var tunnel = this;
|
|
15007
15706
|
|
|
15008
15707
|
/**
|
|
15009
|
-
*
|
|
15010
|
-
* progress, this will
|
|
15708
|
+
* AbortController instance which allows the current, in-progress HTTP
|
|
15709
|
+
* request to be aborted. If no request is currently in progress, this will
|
|
15710
|
+
* be null.
|
|
15011
15711
|
*
|
|
15012
15712
|
* @private
|
|
15013
|
-
* @type {
|
|
15713
|
+
* @type {AbortController}
|
|
15014
15714
|
*/
|
|
15015
|
-
var
|
|
15715
|
+
var abortController = null;
|
|
15016
15716
|
|
|
15017
15717
|
/**
|
|
15018
15718
|
* Additional headers to be sent in tunnel requests. This dictionary can be
|
|
@@ -15025,21 +15725,12 @@ Guacamole.StaticHTTPTunnel = function StaticHTTPTunnel(url, crossDomain, extraTu
|
|
|
15025
15725
|
var extraHeaders = extraTunnelHeaders || {};
|
|
15026
15726
|
|
|
15027
15727
|
/**
|
|
15028
|
-
*
|
|
15029
|
-
*
|
|
15030
|
-
* @param {!XMLHttpRequest} request
|
|
15031
|
-
* The request where the configured extra headers will be added.
|
|
15728
|
+
* The number of bytes in the file being downloaded, or null if this is not
|
|
15729
|
+
* known.
|
|
15032
15730
|
*
|
|
15033
|
-
* @
|
|
15034
|
-
* The headers to be added to the request.
|
|
15035
|
-
*
|
|
15036
|
-
* @private
|
|
15731
|
+
* @type {number}
|
|
15037
15732
|
*/
|
|
15038
|
-
|
|
15039
|
-
for (var name in headers) {
|
|
15040
|
-
request.setRequestHeader(name, headers[name]);
|
|
15041
|
-
}
|
|
15042
|
-
}
|
|
15733
|
+
this.size = null;
|
|
15043
15734
|
|
|
15044
15735
|
this.sendMessage = function sendMessage(elements) {
|
|
15045
15736
|
// Do nothing
|
|
@@ -15053,18 +15744,10 @@ Guacamole.StaticHTTPTunnel = function StaticHTTPTunnel(url, crossDomain, extraTu
|
|
|
15053
15744
|
// Connection is now starting
|
|
15054
15745
|
tunnel.setState(Guacamole.Tunnel.State.CONNECTING);
|
|
15055
15746
|
|
|
15056
|
-
//
|
|
15057
|
-
|
|
15058
|
-
xhr.open('GET', url);
|
|
15059
|
-
xhr.withCredentials = !!crossDomain;
|
|
15060
|
-
addExtraHeaders(xhr, extraHeaders);
|
|
15061
|
-
xhr.responseType = 'text';
|
|
15062
|
-
xhr.send(null);
|
|
15063
|
-
|
|
15064
|
-
var offset = 0;
|
|
15065
|
-
|
|
15066
|
-
// Create Guacamole protocol parser specifically for this connection
|
|
15747
|
+
// Create Guacamole protocol and UTF-8 parsers specifically for this
|
|
15748
|
+
// connection
|
|
15067
15749
|
var parser = new Guacamole.Parser();
|
|
15750
|
+
var utf8Parser = new Guacamole.UTF8Parser();
|
|
15068
15751
|
|
|
15069
15752
|
// Invoke tunnel's oninstruction handler for each parsed instruction
|
|
15070
15753
|
parser.oninstruction = function instructionReceived(opcode, args) {
|
|
@@ -15072,51 +15755,65 @@ Guacamole.StaticHTTPTunnel = function StaticHTTPTunnel(url, crossDomain, extraTu
|
|
|
15072
15755
|
tunnel.oninstruction(opcode, args);
|
|
15073
15756
|
};
|
|
15074
15757
|
|
|
15075
|
-
//
|
|
15076
|
-
|
|
15758
|
+
// Allow new request to be aborted
|
|
15759
|
+
abortController = new AbortController();
|
|
15077
15760
|
|
|
15078
|
-
|
|
15079
|
-
|
|
15761
|
+
// Stream using the Fetch API
|
|
15762
|
+
fetch(url, {
|
|
15763
|
+
headers : extraHeaders,
|
|
15764
|
+
credentials : crossDomain ? 'include' : 'same-origin',
|
|
15765
|
+
signal : abortController.signal
|
|
15766
|
+
})
|
|
15767
|
+
.then(function gotResponse(response) {
|
|
15080
15768
|
|
|
15081
|
-
|
|
15082
|
-
|
|
15769
|
+
// Reset state and close upon error
|
|
15770
|
+
if (!response.ok) {
|
|
15083
15771
|
|
|
15084
|
-
|
|
15085
|
-
|
|
15772
|
+
if (tunnel.onerror)
|
|
15773
|
+
tunnel.onerror(new Guacamole.Status(
|
|
15774
|
+
Guacamole.Status.Code.fromHTTPCode(response.status), response.statusText));
|
|
15086
15775
|
|
|
15087
|
-
|
|
15088
|
-
|
|
15089
|
-
parser.receive(buffer.substring(offset));
|
|
15090
|
-
offset = length;
|
|
15091
|
-
}
|
|
15776
|
+
tunnel.disconnect();
|
|
15777
|
+
return;
|
|
15092
15778
|
|
|
15093
15779
|
}
|
|
15094
15780
|
|
|
15095
|
-
//
|
|
15096
|
-
|
|
15097
|
-
tunnel.disconnect();
|
|
15781
|
+
// Report overall size of stream in bytes, if known
|
|
15782
|
+
tunnel.size = response.headers.get('Content-Length');
|
|
15098
15783
|
|
|
15099
|
-
|
|
15784
|
+
// Connection is open
|
|
15785
|
+
tunnel.setState(Guacamole.Tunnel.State.OPEN);
|
|
15100
15786
|
|
|
15101
|
-
|
|
15102
|
-
|
|
15787
|
+
var reader = response.body.getReader();
|
|
15788
|
+
var processReceivedText = function processReceivedText(result) {
|
|
15103
15789
|
|
|
15104
|
-
|
|
15105
|
-
|
|
15106
|
-
|
|
15107
|
-
|
|
15790
|
+
// Clean up and close when done
|
|
15791
|
+
if (result.done) {
|
|
15792
|
+
tunnel.disconnect();
|
|
15793
|
+
return;
|
|
15794
|
+
}
|
|
15108
15795
|
|
|
15109
|
-
|
|
15110
|
-
|
|
15796
|
+
// Parse only the portion of data which is newly received
|
|
15797
|
+
parser.receive(utf8Parser.decode(result.value));
|
|
15798
|
+
|
|
15799
|
+
// Continue parsing when next chunk is received
|
|
15800
|
+
reader.read().then(processReceivedText);
|
|
15801
|
+
|
|
15802
|
+
};
|
|
15803
|
+
|
|
15804
|
+
// Schedule parse of first chunk
|
|
15805
|
+
reader.read().then(processReceivedText);
|
|
15806
|
+
|
|
15807
|
+
});
|
|
15111
15808
|
|
|
15112
15809
|
};
|
|
15113
15810
|
|
|
15114
15811
|
this.disconnect = function disconnect() {
|
|
15115
15812
|
|
|
15116
|
-
// Abort
|
|
15117
|
-
if (
|
|
15118
|
-
|
|
15119
|
-
|
|
15813
|
+
// Abort any in-progress request
|
|
15814
|
+
if (abortController) {
|
|
15815
|
+
abortController.abort();
|
|
15816
|
+
abortController = null;
|
|
15120
15817
|
}
|
|
15121
15818
|
|
|
15122
15819
|
// Connection is now closed
|
|
@@ -15127,7 +15824,6 @@ Guacamole.StaticHTTPTunnel = function StaticHTTPTunnel(url, crossDomain, extraTu
|
|
|
15127
15824
|
};
|
|
15128
15825
|
|
|
15129
15826
|
Guacamole.StaticHTTPTunnel.prototype = new Guacamole.Tunnel();
|
|
15130
|
-
|
|
15131
15827
|
/*
|
|
15132
15828
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
15133
15829
|
* or more contributor license agreements. See the NOTICE file
|
|
@@ -15149,6 +15845,131 @@ Guacamole.StaticHTTPTunnel.prototype = new Guacamole.Tunnel();
|
|
|
15149
15845
|
|
|
15150
15846
|
var Guacamole = Guacamole || {};
|
|
15151
15847
|
|
|
15848
|
+
/**
|
|
15849
|
+
* Parser that decodes UTF-8 text from a series of provided ArrayBuffers.
|
|
15850
|
+
* Multi-byte characters that continue from one buffer to the next are handled
|
|
15851
|
+
* correctly.
|
|
15852
|
+
*
|
|
15853
|
+
* @constructor
|
|
15854
|
+
*/
|
|
15855
|
+
Guacamole.UTF8Parser = function UTF8Parser() {
|
|
15856
|
+
|
|
15857
|
+
/**
|
|
15858
|
+
* The number of bytes remaining for the current codepoint.
|
|
15859
|
+
*
|
|
15860
|
+
* @private
|
|
15861
|
+
* @type {!number}
|
|
15862
|
+
*/
|
|
15863
|
+
var bytesRemaining = 0;
|
|
15864
|
+
|
|
15865
|
+
/**
|
|
15866
|
+
* The current codepoint value, as calculated from bytes read so far.
|
|
15867
|
+
*
|
|
15868
|
+
* @private
|
|
15869
|
+
* @type {!number}
|
|
15870
|
+
*/
|
|
15871
|
+
var codepoint = 0;
|
|
15872
|
+
|
|
15873
|
+
/**
|
|
15874
|
+
* Decodes the given UTF-8 data into a Unicode string, returning a string
|
|
15875
|
+
* containing all complete UTF-8 characters within the provided data. The
|
|
15876
|
+
* data may end in the middle of a multi-byte character, in which case the
|
|
15877
|
+
* complete character will be returned from a later call to decode() after
|
|
15878
|
+
* enough bytes have been provided.
|
|
15879
|
+
*
|
|
15880
|
+
* @private
|
|
15881
|
+
* @param {!ArrayBuffer} buffer
|
|
15882
|
+
* Arbitrary UTF-8 data.
|
|
15883
|
+
*
|
|
15884
|
+
* @return {!string}
|
|
15885
|
+
* The decoded Unicode string.
|
|
15886
|
+
*/
|
|
15887
|
+
this.decode = function decode(buffer) {
|
|
15888
|
+
|
|
15889
|
+
var text = '';
|
|
15890
|
+
|
|
15891
|
+
var bytes = new Uint8Array(buffer);
|
|
15892
|
+
for (var i=0; i<bytes.length; i++) {
|
|
15893
|
+
|
|
15894
|
+
// Get current byte
|
|
15895
|
+
var value = bytes[i];
|
|
15896
|
+
|
|
15897
|
+
// Start new codepoint if nothing yet read
|
|
15898
|
+
if (bytesRemaining === 0) {
|
|
15899
|
+
|
|
15900
|
+
// 1 byte (0xxxxxxx)
|
|
15901
|
+
if ((value | 0x7F) === 0x7F)
|
|
15902
|
+
text += String.fromCharCode(value);
|
|
15903
|
+
|
|
15904
|
+
// 2 byte (110xxxxx)
|
|
15905
|
+
else if ((value | 0x1F) === 0xDF) {
|
|
15906
|
+
codepoint = value & 0x1F;
|
|
15907
|
+
bytesRemaining = 1;
|
|
15908
|
+
}
|
|
15909
|
+
|
|
15910
|
+
// 3 byte (1110xxxx)
|
|
15911
|
+
else if ((value | 0x0F )=== 0xEF) {
|
|
15912
|
+
codepoint = value & 0x0F;
|
|
15913
|
+
bytesRemaining = 2;
|
|
15914
|
+
}
|
|
15915
|
+
|
|
15916
|
+
// 4 byte (11110xxx)
|
|
15917
|
+
else if ((value | 0x07) === 0xF7) {
|
|
15918
|
+
codepoint = value & 0x07;
|
|
15919
|
+
bytesRemaining = 3;
|
|
15920
|
+
}
|
|
15921
|
+
|
|
15922
|
+
// Invalid byte
|
|
15923
|
+
else
|
|
15924
|
+
text += '\uFFFD';
|
|
15925
|
+
|
|
15926
|
+
}
|
|
15927
|
+
|
|
15928
|
+
// Continue existing codepoint (10xxxxxx)
|
|
15929
|
+
else if ((value | 0x3F) === 0xBF) {
|
|
15930
|
+
|
|
15931
|
+
codepoint = (codepoint << 6) | (value & 0x3F);
|
|
15932
|
+
bytesRemaining--;
|
|
15933
|
+
|
|
15934
|
+
// Write codepoint if finished
|
|
15935
|
+
if (bytesRemaining === 0)
|
|
15936
|
+
text += String.fromCharCode(codepoint);
|
|
15937
|
+
|
|
15938
|
+
}
|
|
15939
|
+
|
|
15940
|
+
// Invalid byte
|
|
15941
|
+
else {
|
|
15942
|
+
bytesRemaining = 0;
|
|
15943
|
+
text += '\uFFFD';
|
|
15944
|
+
}
|
|
15945
|
+
|
|
15946
|
+
}
|
|
15947
|
+
|
|
15948
|
+
return text;
|
|
15949
|
+
|
|
15950
|
+
};
|
|
15951
|
+
|
|
15952
|
+
};/*
|
|
15953
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
|
15954
|
+
* or more contributor license agreements. See the NOTICE file
|
|
15955
|
+
* distributed with this work for additional information
|
|
15956
|
+
* regarding copyright ownership. The ASF licenses this file
|
|
15957
|
+
* to you under the Apache License, Version 2.0 (the
|
|
15958
|
+
* "License"); you may not use this file except in compliance
|
|
15959
|
+
* with the License. You may obtain a copy of the License at
|
|
15960
|
+
*
|
|
15961
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
15962
|
+
*
|
|
15963
|
+
* Unless required by applicable law or agreed to in writing,
|
|
15964
|
+
* software distributed under the License is distributed on an
|
|
15965
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15966
|
+
* KIND, either express or implied. See the License for the
|
|
15967
|
+
* specific language governing permissions and limitations
|
|
15968
|
+
* under the License.
|
|
15969
|
+
*/
|
|
15970
|
+
|
|
15971
|
+
var Guacamole = Guacamole || {};
|
|
15972
|
+
|
|
15152
15973
|
/**
|
|
15153
15974
|
* The unique ID of this version of the Guacamole JavaScript API. This ID will
|
|
15154
15975
|
* be the version string of the guacamole-common-js Maven project, and can be
|
|
@@ -15158,7 +15979,6 @@ var Guacamole = Guacamole || {};
|
|
|
15158
15979
|
* @type {!string}
|
|
15159
15980
|
*/
|
|
15160
15981
|
Guacamole.API_VERSION = "1.4.0";
|
|
15161
|
-
|
|
15162
15982
|
/*
|
|
15163
15983
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
15164
15984
|
* or more contributor license agreements. See the NOTICE file
|
|
@@ -15267,4 +16087,4 @@ Guacamole.VideoPlayer.getInstance = function getInstance(stream, layer, mimetype
|
|
|
15267
16087
|
return null;
|
|
15268
16088
|
|
|
15269
16089
|
};
|
|
15270
|
-
module.exports = Guacamole;
|
|
16090
|
+
module.exports = Guacamole;
|