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