mirror of
https://github.com/jech/galene.git
synced 2024-11-22 08:35:57 +01:00
Move disk writer to its own package.
This commit is contained in:
parent
c608723394
commit
813d89b60d
4 changed files with 24 additions and 20 deletions
|
@ -1,4 +1,4 @@
|
|||
package main
|
||||
package disk
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
@ -19,7 +19,9 @@ import (
|
|||
"sfu/group"
|
||||
)
|
||||
|
||||
type diskClient struct {
|
||||
var Directory string
|
||||
|
||||
type Client struct {
|
||||
group *group.Group
|
||||
id string
|
||||
|
||||
|
@ -42,31 +44,31 @@ func newId() string {
|
|||
return s
|
||||
}
|
||||
|
||||
func NewDiskClient(g *group.Group) *diskClient {
|
||||
return &diskClient{group: g, id: newId()}
|
||||
func New(g *group.Group) *Client {
|
||||
return &Client{group: g, id: newId()}
|
||||
}
|
||||
|
||||
func (client *diskClient) Group() *group.Group {
|
||||
func (client *Client) Group() *group.Group {
|
||||
return client.group
|
||||
}
|
||||
|
||||
func (client *diskClient) Id() string {
|
||||
func (client *Client) Id() string {
|
||||
return client.id
|
||||
}
|
||||
|
||||
func (client *diskClient) Credentials() group.ClientCredentials {
|
||||
func (client *Client) Credentials() group.ClientCredentials {
|
||||
return group.ClientCredentials{"RECORDING", ""}
|
||||
}
|
||||
|
||||
func (client *diskClient) SetPermissions(perms group.ClientPermissions) {
|
||||
func (client *Client) SetPermissions(perms group.ClientPermissions) {
|
||||
return
|
||||
}
|
||||
|
||||
func (client *diskClient) PushClient(id, username string, add bool) error {
|
||||
func (client *Client) PushClient(id, username string, add bool) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (client *diskClient) Close() error {
|
||||
func (client *Client) Close() error {
|
||||
client.mu.Lock()
|
||||
defer client.mu.Unlock()
|
||||
|
||||
|
@ -78,13 +80,13 @@ func (client *diskClient) Close() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (client *diskClient) kick(message string) error {
|
||||
func (client *Client) kick(message string) error {
|
||||
err := client.Close()
|
||||
group.DelClient(client)
|
||||
return err
|
||||
}
|
||||
|
||||
func (client *diskClient) PushConn(id string, up conn.Up, tracks []conn.UpTrack, label string) error {
|
||||
func (client *Client) PushConn(id string, up conn.Up, tracks []conn.UpTrack, label string) error {
|
||||
client.mu.Lock()
|
||||
defer client.mu.Unlock()
|
||||
|
||||
|
@ -102,7 +104,7 @@ func (client *diskClient) PushConn(id string, up conn.Up, tracks []conn.UpTrack,
|
|||
return nil
|
||||
}
|
||||
|
||||
directory := filepath.Join(recordingsDir, client.group.Name())
|
||||
directory := filepath.Join(Directory, client.group.Name())
|
||||
err := os.MkdirAll(directory, 0700)
|
||||
if err != nil {
|
||||
return err
|
4
sfu.go
4
sfu.go
|
@ -15,13 +15,13 @@ import (
|
|||
"runtime/pprof"
|
||||
"syscall"
|
||||
|
||||
"sfu/disk"
|
||||
"sfu/group"
|
||||
)
|
||||
|
||||
var httpAddr string
|
||||
var staticRoot string
|
||||
var dataDir string
|
||||
var recordingsDir string
|
||||
|
||||
func main() {
|
||||
var cpuprofile, memprofile, mutexprofile string
|
||||
|
@ -33,7 +33,7 @@ func main() {
|
|||
"data `directory`")
|
||||
flag.StringVar(&group.Directory, "groups", "./groups/",
|
||||
"group description `directory`")
|
||||
flag.StringVar(&recordingsDir, "recordings", "./recordings/",
|
||||
flag.StringVar(&disk.Directory, "recordings", "./recordings/",
|
||||
"recordings `directory`")
|
||||
flag.StringVar(&cpuprofile, "cpuprofile", "",
|
||||
"store CPU profile in `file`")
|
||||
|
|
|
@ -18,6 +18,7 @@ import (
|
|||
"github.com/pion/webrtc/v3"
|
||||
|
||||
"sfu/conn"
|
||||
"sfu/disk"
|
||||
"sfu/estimator"
|
||||
"sfu/group"
|
||||
)
|
||||
|
@ -1037,12 +1038,12 @@ func handleClientMessage(c *webClient, m clientMessage) error {
|
|||
return c.error(group.UserError("not authorised"))
|
||||
}
|
||||
for _, cc := range c.group.GetClients(c) {
|
||||
_, ok := cc.(*diskClient)
|
||||
_, ok := cc.(*disk.Client)
|
||||
if ok {
|
||||
return c.error(group.UserError("already recording"))
|
||||
}
|
||||
}
|
||||
disk := NewDiskClient(c.group)
|
||||
disk := disk.New(c.group)
|
||||
_, err := group.AddClient(c.group.Name(), disk)
|
||||
if err != nil {
|
||||
disk.Close()
|
||||
|
@ -1054,7 +1055,7 @@ func handleClientMessage(c *webClient, m clientMessage) error {
|
|||
return c.error(group.UserError("not authorised"))
|
||||
}
|
||||
for _, cc := range c.group.GetClients(c) {
|
||||
disk, ok := cc.(*diskClient)
|
||||
disk, ok := cc.(*disk.Client)
|
||||
if ok {
|
||||
disk.Close()
|
||||
group.DelClient(disk)
|
||||
|
|
|
@ -19,6 +19,7 @@ import (
|
|||
|
||||
"github.com/gorilla/websocket"
|
||||
|
||||
"sfu/disk"
|
||||
"sfu/group"
|
||||
)
|
||||
|
||||
|
@ -324,7 +325,7 @@ func recordingsHandler(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
f, err := os.Open(filepath.Join(recordingsDir, pth))
|
||||
f, err := os.Open(filepath.Join(disk.Directory, pth))
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
notFound(w)
|
||||
|
@ -391,7 +392,7 @@ func handleGroupAction(w http.ResponseWriter, r *http.Request, group string) {
|
|||
return
|
||||
}
|
||||
err := os.Remove(
|
||||
filepath.Join(recordingsDir, group+"/"+filename),
|
||||
filepath.Join(disk.Directory, group+"/"+filename),
|
||||
)
|
||||
if err != nil {
|
||||
if os.IsPermission(err) {
|
||||
|
|
Loading…
Reference in a new issue