@@ -2,19 +2,18 @@ import { util } from "./util";
22import logger from "./logger" ;
33import { MediaConnection } from "./mediaconnection" ;
44import { DataConnection } from "./dataconnection" ;
5- import {
6- ConnectionType ,
7- PeerErrorType ,
8- ConnectionEventType ,
9- ServerMessageType ,
10- } from "./enums" ;
11- import { BaseConnection } from "./baseconnection" ;
5+ import { ConnectionType , PeerErrorType , ServerMessageType } from "./enums" ;
6+ import { BaseConnection , BaseConnectionEvents } from "./baseconnection" ;
7+ import { ValidEventTypes } from "eventemitter3" ;
128
139/**
1410 * Manages all negotiations between Peers.
1511 */
16- export class Negotiator {
17- constructor ( readonly connection : BaseConnection ) { }
12+ export class Negotiator <
13+ A extends ValidEventTypes ,
14+ T extends BaseConnection < A | BaseConnectionEvents > ,
15+ > {
16+ constructor ( readonly connection : T ) { }
1817
1918 /** Returns a PeerConnection object set up correctly (for data, media). */
2019 startConnection ( options : any ) {
@@ -30,7 +29,7 @@ export class Negotiator {
3029 // What do we need to do now?
3130 if ( options . originator ) {
3231 if ( this . connection . type === ConnectionType . Data ) {
33- const dataConnection = < DataConnection > this . connection ;
32+ const dataConnection = < DataConnection > ( < unknown > this . connection ) ;
3433
3534 const config : RTCDataChannelInit = { ordered : ! ! options . reliable } ;
3635
@@ -93,7 +92,7 @@ export class Negotiator {
9392 "iceConnectionState is failed, closing connections to " + peerId ,
9493 ) ;
9594 this . connection . emit (
96- ConnectionEventType . Error ,
95+ "error" ,
9796 new Error ( "Negotiation of connection to " + peerId + " failed." ) ,
9897 ) ;
9998 this . connection . close ( ) ;
@@ -103,7 +102,7 @@ export class Negotiator {
103102 "iceConnectionState is closed, closing connections to " + peerId ,
104103 ) ;
105104 this . connection . emit (
106- ConnectionEventType . Error ,
105+ "error" ,
107106 new Error ( "Connection to " + peerId + " closed." ) ,
108107 ) ;
109108 this . connection . close ( ) ;
@@ -120,7 +119,7 @@ export class Negotiator {
120119 }
121120
122121 this . connection . emit (
123- ConnectionEventType . IceStateChanged ,
122+ "iceStateChanged" ,
124123 peerConnection . iceConnectionState ,
125124 ) ;
126125 } ;
@@ -179,7 +178,7 @@ export class Negotiator {
179178 let dataChannelNotClosed = false ;
180179
181180 if ( this . connection . type === ConnectionType . Data ) {
182- const dataConnection = < DataConnection > this . connection ;
181+ const dataConnection = < DataConnection > ( < unknown > this . connection ) ;
183182 const dataChannel = dataConnection . dataChannel ;
184183
185184 if ( dataChannel ) {
@@ -230,7 +229,7 @@ export class Negotiator {
230229 } ;
231230
232231 if ( this . connection . type === ConnectionType . Data ) {
233- const dataConnection = < DataConnection > this . connection ;
232+ const dataConnection = < DataConnection > ( < unknown > this . connection ) ;
234233
235234 payload = {
236235 ...payload ,
0 commit comments