code: func newSession(client *NodeClient,
  	joinSession *session.Session,
  	env map[string]string,
  	stdin io.Reader,
  	stdout io.Writer,
  	stderr io.Writer) (*NodeSession, error) {
  
  	if stdin == nil {
  		stdin = os.Stdin
  	}
  	if stdout == nil {
  		stdout = os.Stdout
  	}
  	if stderr == nil {
  		stderr = os.Stderr
  	}
  	if env == nil {
  		env = make(map[string]string)
  	}
  
  	var err error
  	ns := &NodeSession{
  		env:        env,
  		nodeClient: client,
  		stdin:      stdin,
  		stdout:     stdout,
  		stderr:     stderr,
  		namespace:  client.Namespace,
  		closer:     utils.NewCloseBroadcaster(),
  	}
  	// if we're joining an existing session, we need to assume that session's
  	// existing/current terminal size:
  	if joinSession != nil {
  		ns.id = joinSession.ID
  		ns.namespace = joinSession.Namespace
  		tsize := joinSession.TerminalParams.Winsize()
  		if ns.isTerminalAttached() {
  			err = term.SetWinsize(0, tsize)
  			if err != nil {
  				log.Error(err)
  			}
  			os.Stdout.Write([]byte(fmt.Sprintf("\x1b[8;%d;%dt", tsize.Height, tsize.Width)))
  		}
  		// new session!
  	} else {
  		sid, ok := ns.env[sshutils.SessionEnvVar]
  		if !ok {
  			sid = string(session.NewID())
  		}
  		ns.id = session.ID(sid)
  	}
  	ns.env[sshutils.SessionEnvVar] = string(ns.id)
  	return ns, nil
  }
docs: // newSession creates a new Teleport session with the given remote node
  // if 'joinSessin' is given, the session will join the existing session
  // of another user