foundersandcoders / Live-Peers

2 stars 2 forks source link

add create route #56

Closed jsms90 closed 7 years ago

jsms90 commented 7 years ago
jsms90 commented 7 years ago

@esraajb I need to change this so that I am not manipulating the rooms object directly. I should be using the methods that you have written in the room class.

Let me know when you're done with the changes :+1:

njsfield commented 7 years ago

@jsms90 let me know how you get on with this branch!

jsms90 commented 7 years ago

@njsfield Depends slightly on whether we implement this suggestion:

addEndpoint () {
  let endpointId = // function to create a random string
  this.endpoints[endpointId] = {};
}
jsms90 commented 7 years ago

@njsfield Wasn't entirely sure whether to populate the endpoints object as part of the constructor function in room.js, or do it in the /create route.

In a way, I think it makes more sense for it to happen whenever a new instance of room is created. So I had:

  constructor (username, roomname) {
    this.roomname = roomname;
    this.pin = Math.floor(Math.random() * 10000);
    this.endpoints = {};
    let endpointId = this.createEndpointId();
    this.addEndpoint(endpointId);
    this.updateUsername(endpointId, username);
    this.updatePermissions(endpointId, ['CHAT', 'AV']);
  }

But then I wouldn't already have access to the endpointId that gets created with a new room. So I would have needed to create a new method (e.g. getEndpointId(username)) in the room class, which looked for the endpointId by finding the correct username in the entire endpoints object....

I seem to remember that you were thinking of making a function like that anyway? If you do, maybe I should just use that?