diff --git a/config/config.go b/config/config.go index c7ca9dc..147aade 100644 --- a/config/config.go +++ b/config/config.go @@ -26,7 +26,7 @@ type Config struct { Default any //默认值 Enum []struct { Label string `json:"label"` - Value string `json:"value"` + Value any `json:"value"` } name string // 小写 propsMap map[string]*Config @@ -144,12 +144,16 @@ func (config *Config) Parse(s any, prefix ...string) { if len(kvs) != 2 { continue } + var tmp struct { + Value any + } + yaml.Unmarshal([]byte(fmt.Sprintf("value: %s", strings.TrimSpace(kvs[0]))), &tmp) prop.Enum = append(prop.Enum, struct { Label string `json:"label"` - Value string `json:"value"` + Value any `json:"value"` }{ Label: strings.TrimSpace(kvs[1]), - Value: strings.TrimSpace(kvs[0]), + Value: tmp.Value, }) } } @@ -272,6 +276,9 @@ func (config *Config) schema(index int) (r any) { "title": config.name, } for i, v := range config.props { + if strings.HasPrefix(v.tag.Get("desc"), "废弃") { + continue + } r.Properties[v.name] = v.schema(i) } return r @@ -332,7 +339,7 @@ func (config *Config) schema(index int) (r any) { case reflect.Map: var children []struct { Key string `json:"mkey"` - Value any `json:"mvalue"` + Value any `json:"mvalue"` } p := Property{ Type: "array", @@ -402,7 +409,7 @@ func (config *Config) schema(index int) (r any) { for iter.Next() { children = append(children, struct { Key string `json:"mkey"` - Value any `json:"mvalue"` + Value any `json:"mvalue"` }{ Key: iter.Key().String(), Value: iter.Value().Interface(), @@ -427,6 +434,9 @@ func (config *Config) GetFormily() (r Formily) { Properties: make(map[string]any), } for i, v := range config.props { + if strings.HasPrefix(v.tag.Get("desc"), "废弃") { + continue + } r.Schema.Properties[v.name] = v.schema(i) } return diff --git a/config/formily.go b/config/formily.go index 1a24ee7..69423ef 100644 --- a/config/formily.go +++ b/config/formily.go @@ -6,7 +6,7 @@ type Property struct { Description string `json:"description"` Enum []struct { Label string `json:"label"` - Value string `json:"value"` + Value any `json:"value"` } `json:"enum,omitempty"` Items *Object `json:"items,omitempty"` Properties map[string]any `json:"properties,omitempty"` diff --git a/events.go b/events.go index 3200b6f..ba31683 100644 --- a/events.go +++ b/events.go @@ -1,6 +1,7 @@ package engine import ( + "reflect" "time" "m7s.live/engine/v4/common" @@ -104,3 +105,17 @@ type InviteTrackEvent struct { func InviteTrack(name string, suber ISubscriber) { EventBus <- InviteTrackEvent{Event: CreateEvent(name), ISubscriber: suber} } + +var handlers = make(map[reflect.Type][]any) + +func ListenEvent[T any](handler func(event T)) { + t := reflect.TypeOf(handler).In(0) + handlers[t] = append(handlers[t], handler) +} + +func EmitEvent[T any](event T) { + t := reflect.TypeOf(event) + for _, handler := range handlers[t] { + handler.(func(event T))(event) + } +} diff --git a/pusher.go b/pusher.go index ec6d1dd..5380f52 100644 --- a/pusher.go +++ b/pusher.go @@ -34,10 +34,14 @@ func (pub *Pusher) startPush(pusher IPusher) { Pushers.Store(pub.RemoteURL, pusher) defer Pushers.Delete(pub.RemoteURL) defer pusher.Disconnect() + var startTime time.Time for pusher.Info("start push"); pusher.Reconnect(); pusher.Warn("restart push") { + if time.Since(startTime) < 5*time.Second { + time.Sleep(5 * time.Second) + } + startTime = time.Now() if err = pusher.Subscribe(pub.StreamPath, pusher); err != nil { pusher.Error("push subscribe", zap.Error(err)) - time.Sleep(time.Second * 5) } else { stream := pusher.GetSubscriber().Stream if err = pusher.Connect(); err != nil {