Commit 48092226 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Some more tweaks to JS typing.

parent f2c81165
...@@ -83,7 +83,7 @@ function ServerConnection() { ...@@ -83,7 +83,7 @@ function ServerConnection() {
* clientdata is a convenient place to attach data to a ServerConnection. * clientdata is a convenient place to attach data to a ServerConnection.
* It is not used by the library. * It is not used by the library.
* *
* @type{Object<any,any>} * @type{Object<unknown,unknown>}
*/ */
this.userdata = {}; this.userdata = {};
...@@ -92,25 +92,25 @@ function ServerConnection() { ...@@ -92,25 +92,25 @@ function ServerConnection() {
/** /**
* onconnected is called when the connection has been established * onconnected is called when the connection has been established
* *
* @type{(this: ServerConnection) => any} * @type{(this: ServerConnection) => void}
*/ */
this.onconnected = null; this.onconnected = null;
/** /**
* onclose is called when the connection is closed * onclose is called when the connection is closed
* *
* @type{(this: ServerConnection, code: number, reason: string) => any} * @type{(this: ServerConnection, code: number, reason: string) => void}
*/ */
this.onclose = null; this.onclose = null;
/** /**
* onuser is called whenever a user is added or removed from the group * onuser is called whenever a user is added or removed from the group
* *
* @type{(this: ServerConnection, id: string, kind: string, username: string) => any} * @type{(this: ServerConnection, id: string, kind: string, username: string) => void}
*/ */
this.onuser = null; this.onuser = null;
/** /**
* onpermissions is called whenever the current user's permissions change * onpermissions is called whenever the current user's permissions change
* *
* @type{(this: ServerConnection, permissions: Object<string,boolean>) => any} * @type{(this: ServerConnection, permissions: Object<string,boolean>) => void}
*/ */
this.onpermissions = null; this.onpermissions = null;
/** /**
...@@ -118,27 +118,27 @@ function ServerConnection() { ...@@ -118,27 +118,27 @@ function ServerConnection() {
* should set up the stream's callbacks; actually setting up the UI * should set up the stream's callbacks; actually setting up the UI
* should be done in the stream's ondowntrack callback. * should be done in the stream's ondowntrack callback.
* *
* @type{(this: ServerConnection, stream: Stream) => any} * @type{(this: ServerConnection, stream: Stream) => void}
*/ */
this.ondownstream = null; this.ondownstream = null;
/** /**
* onchat is called whenever a new chat message is received. * onchat is called whenever a new chat message is received.
* *
* @type {(this: ServerConnection, id: string, username: string, kind: string, message: string) => any} * @type {(this: ServerConnection, id: string, username: string, kind: string, message: string) => void}
*/ */
this.onchat = null; this.onchat = null;
/** /**
* onclearchat is called whenever the server requests that the chat * onclearchat is called whenever the server requests that the chat
* be cleared. * be cleared.
* *
* @type{(this: ServerConnection) => any} * @type{(this: ServerConnection) => void}
*/ */
this.onclearchat = null; this.onclearchat = null;
/** /**
* onusermessage is called when the server sends an error or warning * onusermessage is called when the server sends an error or warning
* message that should be displayed to the user. * message that should be displayed to the user.
* *
* @type{(this: ServerConnection, kind: string, message: string) => any} * @type{(this: ServerConnection, kind: string, message: string) => void}
*/ */
this.onusermessage = null; this.onusermessage = null;
} }
...@@ -739,10 +739,10 @@ function Stream(sc, id, pc) { ...@@ -739,10 +739,10 @@ function Stream(sc, id, pc) {
this.renegotiate = false; this.renegotiate = false;
/** /**
* The statistics last computed by the stats handler. This is * The statistics last computed by the stats handler. This is
* a dictionary indexed by track id, with each value a disctionary of * a dictionary indexed by track id, with each value a dictionary of
* statistics. * statistics.
* *
* @type {Object<string,any>} * @type {Object<string,unknown>}
*/ */
this.stats = {}; this.stats = {};
/** /**
...@@ -755,7 +755,7 @@ function Stream(sc, id, pc) { ...@@ -755,7 +755,7 @@ function Stream(sc, id, pc) {
/** /**
* clientdata is a convenient place to attach data to a Stream. * clientdata is a convenient place to attach data to a Stream.
* It is not used by the library. * It is not used by the library.
* @type{Object<any,any>} * @type{Object<unknown,unknown>}
*/ */
this.userdata = {}; this.userdata = {};
...@@ -764,21 +764,21 @@ function Stream(sc, id, pc) { ...@@ -764,21 +764,21 @@ function Stream(sc, id, pc) {
/** /**
* onclose is called when the stream is closed. * onclose is called when the stream is closed.
* *
* @type{(this: Stream) => any} * @type{(this: Stream) => void}
*/ */
this.onclose = null; this.onclose = null;
/** /**
* onerror is called whenever an error occurs. If the error is * onerror is called whenever an error occurs. If the error is
* fatal, then onclose will be called afterwards. * fatal, then onclose will be called afterwards.
* *
* @type{(this: Stream, error: any) => any} * @type{(this: Stream, error: unknown) => void}
*/ */
this.onerror = null; this.onerror = null;
/** /**
* onnegotiationcompleted is called whenever negotiation or * onnegotiationcompleted is called whenever negotiation or
* renegotiation has completed. * renegotiation has completed.
* *
* @type{(this: Stream) => any} * @type{(this: Stream) => void}
*/ */
this.onnegotiationcompleted = null; this.onnegotiationcompleted = null;
/** /**
...@@ -786,32 +786,32 @@ function Stream(sc, id, pc) { ...@@ -786,32 +786,32 @@ function Stream(sc, id, pc) {
* If the stream parameter differs from its previous value, then it * If the stream parameter differs from its previous value, then it
* indicates that the old stream has been discarded. * indicates that the old stream has been discarded.
* *
* @type{(this: Stream, track: MediaStreamTrack, transceiver: RTCRtpTransceiver, label: string, stream: MediaStream) => any} * @type{(this: Stream, track: MediaStreamTrack, transceiver: RTCRtpTransceiver, label: string, stream: MediaStream) => void}
*/ */
this.ondowntrack = null; this.ondowntrack = null;
/** /**
* onlabel is called whenever the server sets a new label for the stream. * onlabel is called whenever the server sets a new label for the stream.
* *
* @type{(this: Stream, label: string) => any} * @type{(this: Stream, label: string) => void}
*/ */
this.onlabel = null; this.onlabel = null;
/** /**
* onstatus is called whenever the status of the stream changes. * onstatus is called whenever the status of the stream changes.
* *
* @type{(this: Stream, status: string) => any} * @type{(this: Stream, status: string) => void}
*/ */
this.onstatus = null; this.onstatus = null;
/** /**
* onabort is called when the server requested that an up stream be * onabort is called when the server requested that an up stream be
* closed. It is the resposibility of the client to close the stream. * closed. It is the resposibility of the client to close the stream.
* *
* @type{(this: Stream) => any} * @type{(this: Stream) => void}
*/ */
this.onabort = null; this.onabort = null;
/** /**
* onstats is called when we have new statistics about the connection * onstats is called when we have new statistics about the connection
* *
* @type{(this: Stream, stats: Object<any,any>) => any} * @type{(this: Stream, stats: Object<unknown,unknown>) => void}
*/ */
this.onstats = null; this.onstats = null;
} }
...@@ -855,7 +855,7 @@ Stream.prototype.close = function(sendclose) { ...@@ -855,7 +855,7 @@ Stream.prototype.close = function(sendclose) {
* @function * @function
*/ */
Stream.prototype.flushIceCandidates = async function () { Stream.prototype.flushIceCandidates = async function () {
/** @type {Promise<any>[]} */ /** @type {Promise<void>[]} */
let promises = []; let promises = [];
this.iceCandidates.forEach(c => { this.iceCandidates.forEach(c => {
promises.push(this.pc.addIceCandidate(c).catch(console.warn)); promises.push(this.pc.addIceCandidate(c).catch(console.warn));
...@@ -937,6 +937,7 @@ Stream.prototype.restartIce = function () { ...@@ -937,6 +937,7 @@ Stream.prototype.restartIce = function () {
Stream.prototype.updateStats = async function() { Stream.prototype.updateStats = async function() {
let c = this; let c = this;
let old = c.stats; let old = c.stats;
/** @type{Object<string,unknown>} */
let stats = {}; let stats = {};
let transceivers = c.pc.getTransceivers(); let transceivers = c.pc.getTransceivers();
......
...@@ -1504,32 +1504,25 @@ function chatResizer(e) { ...@@ -1504,32 +1504,25 @@ function chatResizer(e) {
document.getElementById('resizer').addEventListener('mousedown', chatResizer, false); document.getElementById('resizer').addEventListener('mousedown', chatResizer, false);
/** @enum {string} */
const MessageLevel = {
info: 'info',
warning: 'warning',
error: 'error',
}
/** /**
* @param {string} message * @param {unknown} message
* @param {MessageLevel} [level] * @param {string} [level]
*/ */
function displayError(message, level) { function displayError(message, level) {
if(!level) if(!level)
level = MessageLevel.error; level = "error";
var background = 'linear-gradient(to right, #e20a0a, #df2d2d)'; var background = 'linear-gradient(to right, #e20a0a, #df2d2d)';
var position = 'center'; var position = 'center';
var gravity = 'top'; var gravity = 'top';
switch(level) { switch(level) {
case MessageLevel.info: case "info":
background = 'linear-gradient(to right, #529518, #96c93d)'; background = 'linear-gradient(to right, #529518, #96c93d)';
position = 'right'; position = 'right';
gravity = 'bottom'; gravity = 'bottom';
break; break;
case MessageLevel.warning: case "warning":
background = "linear-gradient(to right, #edd800, #c9c200)"; background = "linear-gradient(to right, #edd800, #c9c200)";
break; break;
} }
...@@ -1547,17 +1540,17 @@ function displayError(message, level) { ...@@ -1547,17 +1540,17 @@ function displayError(message, level) {
} }
/** /**
* @param {string} message * @param {unknown} message
*/ */
function displayWarning(message) { function displayWarning(message) {
return displayError(message, MessageLevel.warning); return displayError(message, "warning");
} }
/** /**
* @param {string} message * @param {unknown} message
*/ */
function displayMessage(message) { function displayMessage(message) {
return displayError(message, MessageLevel.info); return displayError(message, "info");
} }
document.getElementById('userform').onsubmit = function(e) { document.getElementById('userform').onsubmit = function(e) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment