@@ -203,10 +203,18 @@ function ServerConnection() {
203
203
*/
204
204
this . onusermessage = null ;
205
205
/**
206
+ * The set of files currently being transferred.
207
+ *
206
208
* @type {Object<string,TransferredFile> }
207
209
*/
208
210
this . transferredFiles = { } ;
209
211
/**
212
+ * onfiletransfer is called whenever a peer offers a file transfer.
213
+ *
214
+ * If the transfer is accepted, it should set up the file transfer
215
+ * callbacks and return immediately. It may also throw an exception
216
+ * in order to reject the file transfer.
217
+ *
210
218
* @type {(this: ServerConnection, f: TransferredFile) => void }
211
219
*/
212
220
this . onfiletransfer = null ;
@@ -1466,6 +1474,12 @@ Stream.prototype.setStatsInterval = function(ms) {
1466
1474
* A file in the process of being transferred.
1467
1475
* These are stored in the ServerConnection.transferredFiles dictionary.
1468
1476
*
1477
+ * State transitions:
1478
+ * @example
1479
+ * '' -> inviting -> connecting -> connected -> done -> closed
1480
+ * any -> cancelled -> closed
1481
+ *
1482
+ *
1469
1483
* @parm {ServerConnection} sc
1470
1484
* @parm {string} userid
1471
1485
* @parm {string} rid
@@ -1474,47 +1488,109 @@ Stream.prototype.setStatsInterval = function(ms) {
1474
1488
* @parm {string} mimetype
1475
1489
* @parm {number} size
1476
1490
* @constructor
1477
- *
1478
- * State transitions:
1479
- *
1480
- * '' -> inviting -> connecting -> connected -> done -> closed
1481
- * any -> cancelled -> closed
1482
- *
1483
1491
*/
1484
1492
function TransferredFile ( sc , userid , id , up , username , name , mimetype , size ) {
1485
- /** @type {ServerConnection } */
1493
+ /**
1494
+ * The server connection this file is associated with.
1495
+ *
1496
+ * @type {ServerConnection }
1497
+ */
1486
1498
this . sc = sc ;
1487
- /** @type {string } */
1499
+ /** The id of the remote peer.
1500
+ *
1501
+ * @type {string }
1502
+ */
1488
1503
this . userid = userid ;
1489
- /** @type {string } */
1504
+ /**
1505
+ * The id of this file transfer.
1506
+ *
1507
+ * @type {string }
1508
+ */
1490
1509
this . id = id ;
1491
- /** @type {boolean } */
1510
+ /**
1511
+ * True if this is an upload.
1512
+ *
1513
+ * @type {boolean }
1514
+ */
1492
1515
this . up = up ;
1493
- /** @type {string } */
1516
+ /**
1517
+ * The state of this file transfer. See the description of the
1518
+ * constructor for possible state transitions.
1519
+ *
1520
+ * @type {string }
1521
+ */
1494
1522
this . state = '' ;
1495
- /** @type {string } */
1523
+ /**
1524
+ * The username of the remote peer.
1525
+ *
1526
+ * @type {string }
1527
+ */
1496
1528
this . username = username ;
1497
- /** @type {string } */
1529
+ /**
1530
+ * The name of the file being transferred.
1531
+ *
1532
+ * @type {string }
1533
+ */
1498
1534
this . name = name ;
1499
- /** @type {string } */
1535
+ /**
1536
+ * The MIME type of the file being transferred.
1537
+ *
1538
+ * @type {string }
1539
+ */
1500
1540
this . mimetype = mimetype ;
1501
- /** @type {number } */
1541
+ /**
1542
+ * The size in bytes of the file being transferred.
1543
+ *
1544
+ * @type {number }
1545
+ */
1502
1546
this . size = size ;
1503
- /** @type {File } */
1547
+ /**
1548
+ * The file being uploaded. Unused for downloads.
1549
+ *
1550
+ * @type {File }
1551
+ */
1504
1552
this . file = null ;
1505
- /** @type {boolean } */
1506
- this . closed = false ;
1507
- /** @type {RTCPeerConnection } */
1553
+ /**
1554
+ * The peer connection used for the transfer.
1555
+ *
1556
+ * @type {RTCPeerConnection }
1557
+ */
1508
1558
this . pc = null ;
1509
- /** @type {RTCDataChannel } */
1559
+ /**
1560
+ * The datachannel used for the transfer.
1561
+ *
1562
+ * @type {RTCDataChannel }
1563
+ */
1510
1564
this . dc = null ;
1511
- /** @type {Array<RTCIceCandidateInit> } */
1565
+ /**
1566
+ * Buffered remote ICE candidates.
1567
+ *
1568
+ * @type {Array<RTCIceCandidateInit> }
1569
+ */
1512
1570
this . candidates = [ ] ;
1513
- /** @type {Array<Blob|ArrayBuffer> } */
1571
+ /**
1572
+ * The data received to date, stored as a list of blobs or array buffers,
1573
+ * depending on what the browser supports.
1574
+ *
1575
+ * @type {Array<Blob|ArrayBuffer> }
1576
+ */
1514
1577
this . data = [ ] ;
1515
- /** @type {number } */
1578
+ /**
1579
+ * The total size of the data received to date.
1580
+ *
1581
+ * @type {number }
1582
+ */
1516
1583
this . datalen = 0 ;
1517
- /** @type {(this: TransferredFile, type: string, [data]: string) => void } */
1584
+ /**
1585
+ * The main filetransfer callback.
1586
+ *
1587
+ * This is called whenever the state of the transfer changes,
1588
+ * but may also be called multiple times in a single state, for example
1589
+ * in order to display a progress bar. Call this.cancel in order
1590
+ * to cancel the transfer.
1591
+ *
1592
+ * @type {(this: TransferredFile, type: string, [data]: string) => void }
1593
+ */
1518
1594
this . onevent = null ;
1519
1595
}
1520
1596
@@ -1903,6 +1979,8 @@ TransferredFile.prototype.send = async function() {
1903
1979
}
1904
1980
1905
1981
/**
1982
+ * Called after we receive an answer. Don't call this.
1983
+ *
1906
1984
* @param {string } sdp
1907
1985
*/
1908
1986
TransferredFile . prototype . receiveFile = async function ( sdp ) {
@@ -1917,6 +1995,8 @@ TransferredFile.prototype.receiveFile = async function(sdp) {
1917
1995
}
1918
1996
1919
1997
/**
1998
+ * Called whenever we receive a chunk of data. Don't call this.
1999
+ *
1920
2000
* @param {Blob|ArrayBuffer } data
1921
2001
*/
1922
2002
TransferredFile . prototype . receiveData = async function ( data ) {
@@ -1957,6 +2037,9 @@ TransferredFile.prototype.receiveData = async function(data) {
1957
2037
}
1958
2038
1959
2039
/**
2040
+ * fileTransfer handles a usermessage of kind 'filetransfer'. Don't call
2041
+ * this, it is called automatically as needed.
2042
+ *
1960
2043
* @param {string } id
1961
2044
* @param {string } username
1962
2045
* @param {object } message
0 commit comments