Fixing linting

This commit is contained in:
David Négrier 2020-08-18 14:59:50 +02:00
parent 2e61c2ef62
commit cc1cb2f671
3 changed files with 37 additions and 31 deletions

View File

@ -81,7 +81,13 @@ export interface WebRtcDisconnectMessageInterface {
export interface WebRtcSignalMessageInterface { export interface WebRtcSignalMessageInterface {
userId: string, userId: string,
receiverId: string, receiverId: string, // TODO: is this needed? (can we merge this with WebRtcScreenSharingMessageInterface?)
roomId: string,
signal: SignalData
}
export interface WebRtcScreenSharingMessageInterface {
userId: string,
roomId: string, roomId: string,
signal: SignalData signal: SignalData
} }
@ -213,7 +219,7 @@ export class Connection implements Connection {
return this.socket.on(EventMessage.WEBRTC_SIGNAL, callback); return this.socket.on(EventMessage.WEBRTC_SIGNAL, callback);
} }
public receiveWebrtcScreenSharingSignal(callback: Function) { public receiveWebrtcScreenSharingSignal(callback: (message: WebRtcScreenSharingMessageInterface) => void) {
return this.socket.on(EventMessage.WEBRTC_SCREEN_SHARING_SIGNAL, callback); return this.socket.on(EventMessage.WEBRTC_SCREEN_SHARING_SIGNAL, callback);
} }

View File

@ -6,9 +6,6 @@ const videoConstraint: boolean|MediaTrackConstraints = {
height: { ideal: 720 }, height: { ideal: 720 },
facingMode: "user" facingMode: "user"
}; };
interface MediaServiceInterface extends MediaDevices{
getDisplayMedia(constrain: any) : Promise<any>;
}
type UpdatedLocalStreamCallback = (media: MediaStream) => void; type UpdatedLocalStreamCallback = (media: MediaStream) => void;
type UpdatedScreenSharingCallback = (media: MediaStream) => void; type UpdatedScreenSharingCallback = (media: MediaStream) => void;
@ -71,14 +68,14 @@ export class MediaManager {
this.monitorClose = this.getElementByIdOrFail<HTMLImageElement>('monitor-close'); this.monitorClose = this.getElementByIdOrFail<HTMLImageElement>('monitor-close');
this.monitorClose.style.display = "block"; this.monitorClose.style.display = "block";
this.monitorClose.addEventListener('click', (e: any) => { this.monitorClose.addEventListener('click', (e: MouseEvent) => {
e.preventDefault(); e.preventDefault();
this.enabledMonitor(); this.enabledMonitor();
//update tracking //update tracking
}); });
this.monitor = this.getElementByIdOrFail<HTMLImageElement>('monitor'); this.monitor = this.getElementByIdOrFail<HTMLImageElement>('monitor');
this.monitor.style.display = "none"; this.monitor.style.display = "none";
this.monitor.addEventListener('click', (e: any) => { this.monitor.addEventListener('click', (e: MouseEvent) => {
e.preventDefault(); e.preventDefault();
this.disabledMonitor(); this.disabledMonitor();
//update tracking //update tracking
@ -191,8 +188,8 @@ export class MediaManager {
this.localScreenCapture = stream; this.localScreenCapture = stream;
return stream; return stream;
}) })
.catch((err: any) => { .catch((err: unknown) => {
console.error("Error => getScreenMedia => " + err); console.error("Error => getScreenMedia => ", err);
throw err; throw err;
}); });
}catch (err) { }catch (err) {
@ -203,10 +200,13 @@ export class MediaManager {
} }
private _startScreenCapture() { private _startScreenCapture() {
if ((navigator as any).getDisplayMedia) { // getDisplayMedia was moved to mediaDevices in 2018. Typescript definitions are not up to date yet.
return (navigator as any).getDisplayMedia({video: true}); // See: https://github.com/w3c/mediacapture-screen-share/pull/86
} else if ((navigator.mediaDevices as any).getDisplayMedia) { // https://github.com/microsoft/TypeScript/issues/31821
return (navigator.mediaDevices as any).getDisplayMedia({video: true}); if ((navigator as any).getDisplayMedia) { // eslint-disable-line @typescript-eslint/no-explicit-any
return (navigator as any).getDisplayMedia({video: true}); // eslint-disable-line @typescript-eslint/no-explicit-any
} else if ((navigator.mediaDevices as any).getDisplayMedia) { // eslint-disable-line @typescript-eslint/no-explicit-any
return (navigator.mediaDevices as any).getDisplayMedia({video: true}); // eslint-disable-line @typescript-eslint/no-explicit-any
} else { } else {
//return navigator.mediaDevices.getUserMedia(({video: {mediaSource: 'screen'}} as any)); //return navigator.mediaDevices.getUserMedia(({video: {mediaSource: 'screen'}} as any));
return new Promise((resolve, reject) => { // eslint-disable-line no-unused-vars return new Promise((resolve, reject) => { // eslint-disable-line no-unused-vars
@ -302,13 +302,13 @@ export class MediaManager {
userId = `screen-sharing-${userId}`; userId = `screen-sharing-${userId}`;
this.webrtcInAudio.play(); this.webrtcInAudio.play();
// FIXME: switch to DisplayManager! // FIXME: switch to DisplayManager!
let elementRemoteVideo = this.getElementByIdOrFail("activeScreenSharing"); const elementRemoteVideo = this.getElementByIdOrFail("activeScreenSharing");
elementRemoteVideo.insertAdjacentHTML('beforeend', ` elementRemoteVideo.insertAdjacentHTML('beforeend', `
<div id="div-${userId}" class="screen-sharing-video-container"> <div id="div-${userId}" class="screen-sharing-video-container">
<video id="${userId}" autoplay></video> <video id="${userId}" autoplay></video>
</div> </div>
`); `);
let activeHTMLVideoElement : HTMLElement|null = document.getElementById(userId); const activeHTMLVideoElement : HTMLElement|null = document.getElementById(userId);
if(!activeHTMLVideoElement){ if(!activeHTMLVideoElement){
return; return;
} }

View File

@ -1,6 +1,6 @@
import { import {
Connection, Connection,
WebRtcDisconnectMessageInterface, WebRtcDisconnectMessageInterface, WebRtcScreenSharingMessageInterface,
WebRtcSignalMessageInterface, WebRtcSignalMessageInterface,
WebRtcStartMessageInterface WebRtcStartMessageInterface
} from "../Connection"; } from "../Connection";
@ -64,7 +64,7 @@ export class SimplePeer {
}); });
//receive signal by gemer //receive signal by gemer
this.Connection.receiveWebrtcScreenSharingSignal((message: WebRtcDisconnectMessageInterface) => { this.Connection.receiveWebrtcScreenSharingSignal((message: WebRtcScreenSharingMessageInterface) => {
this.receiveWebrtcScreenSharingSignal(message); this.receiveWebrtcScreenSharingSignal(message);
}); });
@ -200,7 +200,7 @@ export class SimplePeer {
}); });
peer.on('data', (chunk: Buffer) => { peer.on('data', (chunk: Buffer) => {
let constraint = JSON.parse(chunk.toString('utf8')); const constraint = JSON.parse(chunk.toString('utf8'));
console.log("data", constraint); console.log("data", constraint);
if (constraint.audio) { if (constraint.audio) {
mediaManager.enabledMicrophoneByUserId(user.userId); mediaManager.enabledMicrophoneByUserId(user.userId);
@ -264,7 +264,7 @@ export class SimplePeer {
private closeScreenSharingConnection(userId : string) { private closeScreenSharingConnection(userId : string) {
try { try {
mediaManager.removeActiveScreenSharingVideo(userId); mediaManager.removeActiveScreenSharingVideo(userId);
let peer = this.PeerScreenSharingConnectionArray.get(userId); const peer = this.PeerScreenSharingConnectionArray.get(userId);
if (peer === undefined) { if (peer === undefined) {
console.warn("Tried to close connection for user "+userId+" but could not find user") console.warn("Tried to close connection for user "+userId+" but could not find user")
return; return;
@ -312,12 +312,12 @@ export class SimplePeer {
* @param userId * @param userId
* @param data * @param data
*/ */
private sendWebrtcScreenSharingSignal(data: any, userId : string) { private sendWebrtcScreenSharingSignal(data: unknown, userId : string) {
console.log("sendWebrtcScreenSharingSignal", data); console.log("sendWebrtcScreenSharingSignal", data);
try { try {
this.Connection.sendWebrtcScreenSharingSignal(data, this.WebRtcRoomId, userId); this.Connection.sendWebrtcScreenSharingSignal(data, this.WebRtcRoomId, userId);
}catch (e) { }catch (e) {
console.error(`sendWebrtcSignal => ${userId}`, e); console.error(`sendWebrtcScreenSharingSignal => ${userId}`, e);
} }
} }
@ -339,14 +339,14 @@ export class SimplePeer {
} }
} }
private receiveWebrtcScreenSharingSignal(data: any) { private receiveWebrtcScreenSharingSignal(data: WebRtcScreenSharingMessageInterface) {
console.log("receiveWebrtcScreenSharingSignal", data); console.log("receiveWebrtcScreenSharingSignal", data);
try { try {
//if offer type, create peer connection //if offer type, create peer connection
if(data.signal.type === "offer"){ if(data.signal.type === "offer"){
this.createPeerConnection(data, true); this.createPeerConnection(data, true);
} }
let peer = this.PeerScreenSharingConnectionArray.get(data.userId); const peer = this.PeerScreenSharingConnectionArray.get(data.userId);
if (peer !== undefined) { if (peer !== undefined) {
peer.signal(data.signal); peer.signal(data.signal);
} else { } else {
@ -386,11 +386,11 @@ export class SimplePeer {
*/ */
private addMedia (userId : string) { private addMedia (userId : string) {
try { try {
let PeerConnection = this.PeerConnectionArray.get(userId); const PeerConnection = this.PeerConnectionArray.get(userId);
if (!PeerConnection) { if (!PeerConnection) {
throw new Error('While adding media, cannot find user with ID ' + userId); throw new Error('While adding media, cannot find user with ID ' + userId);
} }
let localStream: MediaStream | null = mediaManager.localStream; const localStream: MediaStream | null = mediaManager.localStream;
PeerConnection.write(new Buffer(JSON.stringify(mediaManager.constraintsMedia))); PeerConnection.write(new Buffer(JSON.stringify(mediaManager.constraintsMedia)));
if(!localStream){ if(!localStream){
@ -406,12 +406,12 @@ export class SimplePeer {
} }
} }
private addMediaScreenSharing (userId : any = null) { private addMediaScreenSharing(userId : string) {
let PeerConnection = this.PeerScreenSharingConnectionArray.get(userId); const PeerConnection = this.PeerScreenSharingConnectionArray.get(userId);
if (!PeerConnection) { if (!PeerConnection) {
throw new Error('While adding media, cannot find user with ID ' + userId); throw new Error('While adding media, cannot find user with ID ' + userId);
} }
let localScreenCapture: MediaStream | null = mediaManager.localScreenCapture; const localScreenCapture: MediaStream | null = mediaManager.localScreenCapture;
if(!localScreenCapture){ if(!localScreenCapture){
return; return;
} }
@ -436,11 +436,11 @@ export class SimplePeer {
if(!userId){ if(!userId){
return; return;
} }
let screenSharingUser: UserSimplePeerInterface = { const screenSharingUser: UserSimplePeerInterface = {
userId, userId,
initiator: true initiator: true
}; };
let PeerConnectionScreenSharing = this.createPeerConnection(screenSharingUser, true); const PeerConnectionScreenSharing = this.createPeerConnection(screenSharingUser, true);
if (!PeerConnectionScreenSharing) { if (!PeerConnectionScreenSharing) {
return; return;
} }
@ -457,7 +457,7 @@ export class SimplePeer {
if (!userId || !this.PeerScreenSharingConnectionArray.has(userId)) { if (!userId || !this.PeerScreenSharingConnectionArray.has(userId)) {
return; return;
} }
let PeerConnectionScreenSharing = this.PeerScreenSharingConnectionArray.get(userId); const PeerConnectionScreenSharing = this.PeerScreenSharingConnectionArray.get(userId);
console.log("updatedScreenSharing => destroy", PeerConnectionScreenSharing); console.log("updatedScreenSharing => destroy", PeerConnectionScreenSharing);
if (!PeerConnectionScreenSharing) { if (!PeerConnectionScreenSharing) {
return; return;