Skip to content

Commit

Permalink
Add version to ui
Browse files Browse the repository at this point in the history
  • Loading branch information
jmattheis committed Oct 4, 2020
1 parent 91fa253 commit 4b45a7f
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 37 deletions.
2 changes: 1 addition & 1 deletion cmd/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func Run(version, commitHash string) {
Name: "screego",
Version: fmt.Sprintf("%s; screego/server@%s", version, commitHash),
Commands: []cli.Command{
serveCmd,
serveCmd(version),
hashCmd,
},
}
Expand Down
72 changes: 37 additions & 35 deletions cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,41 @@ import (
"github.com/urfave/cli"
)

var serveCmd = cli.Command{
Name: "serve",
Action: func(ctx *cli.Context) {

mrand.Seed(time.Now().Unix())
conf, errs := config.Get()
logger.Init(conf.LogLevel.AsZeroLogLevel())

exit := false
for _, err := range errs {
log.WithLevel(err.Level).Msg(err.Msg)
exit = exit || err.Level == zerolog.FatalLevel || err.Level == zerolog.PanicLevel
}
if exit {
os.Exit(1)
}
users, err := auth.ReadPasswordsFile(conf.UsersFile, conf.Secret)
if err != nil {
log.Fatal().Str("file", conf.UsersFile).Err(err).Msg("While loading users file")
}

auth, err := turn.Start(conf)
if err != nil {
log.Fatal().Err(err).Msg("could not start turn server")
}

rooms := ws.NewRooms(auth, users, conf)

go rooms.Start()

r := router.Router(conf, rooms, users)
if err := server.Start(r, conf.ServerAddress, conf.TLSCertFile, conf.TLSKeyFile); err != nil {
log.Fatal().Err(err).Msg("http server")
}
},
func serveCmd(version string) cli.Command {
return cli.Command{
Name: "serve",
Action: func(ctx *cli.Context) {

mrand.Seed(time.Now().Unix())
conf, errs := config.Get()
logger.Init(conf.LogLevel.AsZeroLogLevel())

exit := false
for _, err := range errs {
log.WithLevel(err.Level).Msg(err.Msg)
exit = exit || err.Level == zerolog.FatalLevel || err.Level == zerolog.PanicLevel
}
if exit {
os.Exit(1)
}
users, err := auth.ReadPasswordsFile(conf.UsersFile, conf.Secret)
if err != nil {
log.Fatal().Str("file", conf.UsersFile).Err(err).Msg("While loading users file")
}

auth, err := turn.Start(conf)
if err != nil {
log.Fatal().Err(err).Msg("could not start turn server")
}

rooms := ws.NewRooms(auth, users, conf)

go rooms.Start()

r := router.Router(conf, rooms, users, version)
if err := server.Start(r, conf.ServerAddress, conf.TLSCertFile, conf.TLSKeyFile); err != nil {
log.Fatal().Err(err).Msg("http server")
}
},
}
}
4 changes: 3 additions & 1 deletion router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ type UIConfig struct {
AuthMode string `json:"authMode"`
User string `json:"user"`
LoggedIn bool `json:"loggedIn"`
Version string `json:"version"`
}

func Router(conf config.Config, rooms *ws.Rooms, users *auth.Users) *mux.Router {
func Router(conf config.Config, rooms *ws.Rooms, users *auth.Users, version string) *mux.Router {
router := mux.NewRouter()
router.Use(handlers.CORS(handlers.AllowedMethods([]string{"GET", "POST"}), handlers.AllowedOriginValidator(conf.CheckOrigin)))
router.HandleFunc("/stream", rooms.Upgrade)
Expand All @@ -30,6 +31,7 @@ func Router(conf config.Config, rooms *ws.Rooms, users *auth.Users) *mux.Router
AuthMode: conf.AuthMode,
LoggedIn: loggedIn,
User: user,
Version: version,
})
})

Expand Down
5 changes: 5 additions & 0 deletions ui/src/RoomManage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
Select,
TextField,
Typography,
Link,
} from '@material-ui/core';
import {FCreateRoom, UseRoom} from './useRoom';
import {RoomMode, UIConfig} from './message';
Expand Down Expand Up @@ -144,6 +145,10 @@ export const RoomManage = ({room, config}: {room: FCreateRoom; config: UseConfig
)}
</Paper>
</Grid>
<div style={{position: 'absolute', margin: '0 auto', bottom: 0}}>
Screego {config.version} |{' '}
<Link href="https://github.com/screego/server/">GitHub</Link>
</div>
</Grid>
);
};
1 change: 1 addition & 0 deletions ui/src/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface UIConfig {
authMode: 'turn' | 'none' | 'all';
user: string;
loggedIn: boolean;
version: string;
}

export interface RoomConfiguration {
Expand Down
1 change: 1 addition & 0 deletions ui/src/useConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const useConfig = (): UseConfig => {
user: 'guest',
loggedIn: false,
loading: true,
version: 'unknown',
});

const refetch = React.useCallback(() => {
Expand Down

0 comments on commit 4b45a7f

Please sign in to comment.