message: Error handling first steps
diff: @@ -117,7 +117,8 @@ export class Peer implements IPeer {
  };
  this.currentRooms.push(room);
  - return Promise.all(roomUsers
  + return Promise.all(
  + roomUsers
  .filter(user => user.userId !== this.nickname)
  .map(user => {
  if (
  @@ -132,7 +133,8 @@ export class Peer implements IPeer {
  });
  return this.beConnectedTo(user.peerId);
  - }));
  + })
  + );
  }
  public beConnectedTo(peerId: string, timeout: number = 5000): Promise<void> {
  @@ -149,7 +151,9 @@ export class Peer implements IPeer {
  setTimeout(() => {
  if (!this.isConnectedTo(peerId)) {
  - reject(`Awaiting connection to peer ${peerId} timed out after ${timeout}ms`);
  + reject(
  + `Awaiting connection to peer ${peerId} timed out after ${timeout}ms`
  + );
  this.peerConnectionPromises[peerId] = this.peerConnectionPromises[
  peerId
  ].splice(this.peerConnectionPromises[peerId].indexOf(promisePair), 1);
  @@ -201,6 +205,23 @@ export class Peer implements IPeer {
  this.currentRooms.forEach(it => it.users.set(this.key(data), data));
  });
  + connection.on("close", () => {
  + console.log(
  + "DISCONNECTED from " +
  + peerId +
  + " through " +
  + connectionIdFor(this.nickname, peerId, reliable)
  + );
  + });
  +
  + connection.on("error", err => {
  + console.log(
  + "error in peer connection" +
  + connectionIdFor(this.nickname, peerId, reliable),
  + err
  + );
  + });
  +
  connection.on("data", data => {
  const parsed = JSON.parse(data);
  switch (parsed.type as PacketType) {
  @@ -298,6 +319,7 @@ export class Peer implements IPeer {
  conn.write(JSON.stringify(packet));
  }
  }
  + //TODO: Fail on error? Promise rejection?
  }
  private handleSignal(peerId: string, reliable: boolean) {
  