mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
Go generics and changes in v1.18 (#5)
* ArrayIn to use generics. * interface{} -> any.
This commit is contained in:
parent
c725e96c90
commit
babddacbf3
@ -46,7 +46,7 @@ func (h *RoomHandler) boradcastStart(w http.ResponseWriter, r *http.Request) err
|
|||||||
message.BroadcastStatus{
|
message.BroadcastStatus{
|
||||||
IsActive: broadcast.Started(),
|
IsActive: broadcast.Started(),
|
||||||
URL: broadcast.Url(),
|
URL: broadcast.Url(),
|
||||||
}, nil)
|
})
|
||||||
|
|
||||||
return utils.HttpSuccess(w)
|
return utils.HttpSuccess(w)
|
||||||
}
|
}
|
||||||
@ -64,7 +64,7 @@ func (h *RoomHandler) boradcastStop(w http.ResponseWriter, r *http.Request) erro
|
|||||||
message.BroadcastStatus{
|
message.BroadcastStatus{
|
||||||
IsActive: broadcast.Started(),
|
IsActive: broadcast.Started(),
|
||||||
URL: broadcast.Url(),
|
URL: broadcast.Url(),
|
||||||
}, nil)
|
})
|
||||||
|
|
||||||
return utils.HttpSuccess(w)
|
return utils.HttpSuccess(w)
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ func (h *RoomHandler) screenConfigurationChange(w http.ResponseWriter, r *http.R
|
|||||||
}
|
}
|
||||||
|
|
||||||
payload := message.ScreenSize(*data)
|
payload := message.ScreenSize(*data)
|
||||||
h.sessions.Broadcast(event.SCREEN_UPDATED, payload, nil)
|
h.sessions.Broadcast(event.SCREEN_UPDATED, payload)
|
||||||
|
|
||||||
return utils.HttpSuccess(w, data)
|
return utils.HttpSuccess(w, data)
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ func (manager *DesktopManagerCtx) ClipboardSetBinary(mime string, data []byte) e
|
|||||||
// TODO: Refactor.
|
// TODO: Refactor.
|
||||||
// We need to wait until the data came to the clipboard.
|
// We need to wait until the data came to the clipboard.
|
||||||
wait := make(chan struct{})
|
wait := make(chan struct{})
|
||||||
xevent.Emmiter.Once("clipboard-updated", func(payload ...interface{}) {
|
xevent.Emmiter.Once("clipboard-updated", func(payload ...any) {
|
||||||
wait <- struct{}{}
|
wait <- struct{}{}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -18,20 +18,20 @@ func (manager *DesktopManagerCtx) DropFiles(x int, y int, files []string) bool {
|
|||||||
|
|
||||||
drop.Emmiter.Clear()
|
drop.Emmiter.Clear()
|
||||||
|
|
||||||
drop.Emmiter.Once("create", func(payload ...interface{}) {
|
drop.Emmiter.Once("create", func(payload ...any) {
|
||||||
manager.Move(0, 0)
|
manager.Move(0, 0)
|
||||||
})
|
})
|
||||||
|
|
||||||
drop.Emmiter.Once("cursor-enter", func(payload ...interface{}) {
|
drop.Emmiter.Once("cursor-enter", func(payload ...any) {
|
||||||
//nolint
|
//nolint
|
||||||
manager.ButtonDown(1)
|
manager.ButtonDown(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
drop.Emmiter.Once("button-press", func(payload ...interface{}) {
|
drop.Emmiter.Once("button-press", func(payload ...any) {
|
||||||
manager.Move(x, y)
|
manager.Move(x, y)
|
||||||
})
|
})
|
||||||
|
|
||||||
drop.Emmiter.Once("begin", func(payload ...interface{}) {
|
drop.Emmiter.Once("begin", func(payload ...any) {
|
||||||
for i := 0; i < dropMoveRepeat; i++ {
|
for i := 0; i < dropMoveRepeat; i++ {
|
||||||
manager.Move(x, y)
|
manager.Move(x, y)
|
||||||
time.Sleep(dropMoveDelay)
|
time.Sleep(dropMoveDelay)
|
||||||
@ -42,7 +42,7 @@ func (manager *DesktopManagerCtx) DropFiles(x int, y int, files []string) bool {
|
|||||||
})
|
})
|
||||||
|
|
||||||
finished := make(chan bool)
|
finished := make(chan bool)
|
||||||
drop.Emmiter.Once("finish", func(payload ...interface{}) {
|
drop.Emmiter.Once("finish", func(payload ...any) {
|
||||||
finished <- payload[0].(bool)
|
finished <- payload[0].(bool)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -79,13 +79,13 @@ func (manager *DesktopManagerCtx) Start() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (manager *DesktopManagerCtx) OnBeforeScreenSizeChange(listener func()) {
|
func (manager *DesktopManagerCtx) OnBeforeScreenSizeChange(listener func()) {
|
||||||
manager.emmiter.On("before_screen_size_change", func(payload ...interface{}) {
|
manager.emmiter.On("before_screen_size_change", func(payload ...any) {
|
||||||
listener()
|
listener()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (manager *DesktopManagerCtx) OnAfterScreenSizeChange(listener func()) {
|
func (manager *DesktopManagerCtx) OnAfterScreenSizeChange(listener func()) {
|
||||||
manager.emmiter.On("after_screen_size_change", func(payload ...interface{}) {
|
manager.emmiter.On("after_screen_size_change", func(payload ...any) {
|
||||||
listener()
|
listener()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -5,31 +5,31 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (manager *DesktopManagerCtx) OnCursorChanged(listener func(serial uint64)) {
|
func (manager *DesktopManagerCtx) OnCursorChanged(listener func(serial uint64)) {
|
||||||
xevent.Emmiter.On("cursor-changed", func(payload ...interface{}) {
|
xevent.Emmiter.On("cursor-changed", func(payload ...any) {
|
||||||
listener(payload[0].(uint64))
|
listener(payload[0].(uint64))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (manager *DesktopManagerCtx) OnClipboardUpdated(listener func()) {
|
func (manager *DesktopManagerCtx) OnClipboardUpdated(listener func()) {
|
||||||
xevent.Emmiter.On("clipboard-updated", func(payload ...interface{}) {
|
xevent.Emmiter.On("clipboard-updated", func(payload ...any) {
|
||||||
listener()
|
listener()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (manager *DesktopManagerCtx) OnFileChooserDialogOpened(listener func()) {
|
func (manager *DesktopManagerCtx) OnFileChooserDialogOpened(listener func()) {
|
||||||
xevent.Emmiter.On("file-chooser-dialog-opened", func(payload ...interface{}) {
|
xevent.Emmiter.On("file-chooser-dialog-opened", func(payload ...any) {
|
||||||
listener()
|
listener()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (manager *DesktopManagerCtx) OnFileChooserDialogClosed(listener func()) {
|
func (manager *DesktopManagerCtx) OnFileChooserDialogClosed(listener func()) {
|
||||||
xevent.Emmiter.On("file-chooser-dialog-closed", func(payload ...interface{}) {
|
xevent.Emmiter.On("file-chooser-dialog-closed", func(payload ...any) {
|
||||||
listener()
|
listener()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (manager *DesktopManagerCtx) OnEventError(listener func(error_code uint8, message string, request_code uint8, minor_code uint8)) {
|
func (manager *DesktopManagerCtx) OnEventError(listener func(error_code uint8, message string, request_code uint8, minor_code uint8)) {
|
||||||
xevent.Emmiter.On("event-error", func(payload ...interface{}) {
|
xevent.Emmiter.On("event-error", func(payload ...any) {
|
||||||
listener(payload[0].(uint8), payload[1].(string), payload[2].(uint8), payload[3].(uint8))
|
listener(payload[0].(uint8), payload[1].(string), payload[2].(uint8), payload[3].(uint8))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ func (l *logFormatter) NewLogEntry(r *http.Request) middleware.LogEntry {
|
|||||||
return &nulllog{}
|
return &nulllog{}
|
||||||
}
|
}
|
||||||
|
|
||||||
req := map[string]interface{}{}
|
req := map[string]any{}
|
||||||
|
|
||||||
if reqID := middleware.GetReqID(r.Context()); reqID != "" {
|
if reqID := middleware.GetReqID(r.Context()); reqID != "" {
|
||||||
req["id"] = reqID
|
req["id"] = reqID
|
||||||
@ -57,7 +57,7 @@ type logPanic struct {
|
|||||||
stack string
|
stack string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *logEntry) Panic(v interface{}, stack []byte) {
|
func (e *logEntry) Panic(v any, stack []byte) {
|
||||||
e.panic = &logPanic{
|
e.panic = &logPanic{
|
||||||
message: fmt.Sprintf("%+v", v),
|
message: fmt.Sprintf("%+v", v),
|
||||||
stack: string(stack),
|
stack: string(stack),
|
||||||
@ -72,8 +72,8 @@ func (e *logEntry) SetSession(session types.Session) {
|
|||||||
e.session = &session
|
e.session = &session
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *logEntry) Write(status, bytes int, header http.Header, elapsed time.Duration, extra interface{}) {
|
func (e *logEntry) Write(status, bytes int, header http.Header, elapsed time.Duration, extra any) {
|
||||||
res := map[string]interface{}{}
|
res := map[string]any{}
|
||||||
res["time"] = time.Now().UTC().Format(time.RFC1123)
|
res["time"] = time.Now().UTC().Format(time.RFC1123)
|
||||||
res["status"] = status
|
res["status"] = status
|
||||||
res["bytes"] = bytes
|
res["bytes"] = bytes
|
||||||
@ -128,8 +128,8 @@ func (e *logEntry) Write(status, bytes int, header http.Header, elapsed time.Dur
|
|||||||
|
|
||||||
type nulllog struct{}
|
type nulllog struct{}
|
||||||
|
|
||||||
func (e *nulllog) Panic(v interface{}, stack []byte) {}
|
func (e *nulllog) Panic(v any, stack []byte) {}
|
||||||
func (e *nulllog) Error(err error) {}
|
func (e *nulllog) Error(err error) {}
|
||||||
func (e *nulllog) SetSession(session types.Session) {}
|
func (e *nulllog) SetSession(session types.Session) {}
|
||||||
func (e *nulllog) Write(status, bytes int, header http.Header, elapsed time.Duration, extra interface{}) {
|
func (e *nulllog) Write(status, bytes int, header http.Header, elapsed time.Duration, extra any) {
|
||||||
}
|
}
|
||||||
|
@ -237,13 +237,13 @@ func (manager *SessionManagerCtx) PopCursors() map[types.Session][]types.Cursor
|
|||||||
// broadcasts
|
// broadcasts
|
||||||
// ---
|
// ---
|
||||||
|
|
||||||
func (manager *SessionManagerCtx) Broadcast(event string, payload interface{}, exclude interface{}) {
|
func (manager *SessionManagerCtx) Broadcast(event string, payload any, exclude ...string) {
|
||||||
for _, session := range manager.List() {
|
for _, session := range manager.List() {
|
||||||
if !session.State().IsConnected {
|
if !session.State().IsConnected {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if exclude != nil {
|
if len(exclude) > 0 {
|
||||||
if in, _ := utils.ArrayIn(session.ID(), exclude); in {
|
if in, _ := utils.ArrayIn(session.ID(), exclude); in {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -253,13 +253,13 @@ func (manager *SessionManagerCtx) Broadcast(event string, payload interface{}, e
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (manager *SessionManagerCtx) AdminBroadcast(event string, payload interface{}, exclude interface{}) {
|
func (manager *SessionManagerCtx) AdminBroadcast(event string, payload any, exclude ...string) {
|
||||||
for _, session := range manager.List() {
|
for _, session := range manager.List() {
|
||||||
if !session.State().IsConnected || !session.Profile().IsAdmin {
|
if !session.State().IsConnected || !session.Profile().IsAdmin {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if exclude != nil {
|
if len(exclude) > 0 {
|
||||||
if in, _ := utils.ArrayIn(session.ID(), exclude); in {
|
if in, _ := utils.ArrayIn(session.ID(), exclude); in {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -269,13 +269,13 @@ func (manager *SessionManagerCtx) AdminBroadcast(event string, payload interface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (manager *SessionManagerCtx) InactiveCursorsBroadcast(event string, payload interface{}, exclude interface{}) {
|
func (manager *SessionManagerCtx) InactiveCursorsBroadcast(event string, payload any, exclude ...string) {
|
||||||
for _, session := range manager.List() {
|
for _, session := range manager.List() {
|
||||||
if !session.State().IsConnected || !session.Profile().CanSeeInactiveCursors {
|
if !session.State().IsConnected || !session.Profile().CanSeeInactiveCursors {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if exclude != nil {
|
if len(exclude) > 0 {
|
||||||
if in, _ := utils.ArrayIn(session.ID(), exclude); in {
|
if in, _ := utils.ArrayIn(session.ID(), exclude); in {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -290,43 +290,43 @@ func (manager *SessionManagerCtx) InactiveCursorsBroadcast(event string, payload
|
|||||||
// ---
|
// ---
|
||||||
|
|
||||||
func (manager *SessionManagerCtx) OnCreated(listener func(session types.Session)) {
|
func (manager *SessionManagerCtx) OnCreated(listener func(session types.Session)) {
|
||||||
manager.emmiter.On("created", func(payload ...interface{}) {
|
manager.emmiter.On("created", func(payload ...any) {
|
||||||
listener(payload[0].(*SessionCtx))
|
listener(payload[0].(*SessionCtx))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (manager *SessionManagerCtx) OnDeleted(listener func(session types.Session)) {
|
func (manager *SessionManagerCtx) OnDeleted(listener func(session types.Session)) {
|
||||||
manager.emmiter.On("deleted", func(payload ...interface{}) {
|
manager.emmiter.On("deleted", func(payload ...any) {
|
||||||
listener(payload[0].(*SessionCtx))
|
listener(payload[0].(*SessionCtx))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (manager *SessionManagerCtx) OnConnected(listener func(session types.Session)) {
|
func (manager *SessionManagerCtx) OnConnected(listener func(session types.Session)) {
|
||||||
manager.emmiter.On("connected", func(payload ...interface{}) {
|
manager.emmiter.On("connected", func(payload ...any) {
|
||||||
listener(payload[0].(*SessionCtx))
|
listener(payload[0].(*SessionCtx))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (manager *SessionManagerCtx) OnDisconnected(listener func(session types.Session)) {
|
func (manager *SessionManagerCtx) OnDisconnected(listener func(session types.Session)) {
|
||||||
manager.emmiter.On("disconnected", func(payload ...interface{}) {
|
manager.emmiter.On("disconnected", func(payload ...any) {
|
||||||
listener(payload[0].(*SessionCtx))
|
listener(payload[0].(*SessionCtx))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (manager *SessionManagerCtx) OnProfileChanged(listener func(session types.Session)) {
|
func (manager *SessionManagerCtx) OnProfileChanged(listener func(session types.Session)) {
|
||||||
manager.emmiter.On("profile_changed", func(payload ...interface{}) {
|
manager.emmiter.On("profile_changed", func(payload ...any) {
|
||||||
listener(payload[0].(*SessionCtx))
|
listener(payload[0].(*SessionCtx))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (manager *SessionManagerCtx) OnStateChanged(listener func(session types.Session)) {
|
func (manager *SessionManagerCtx) OnStateChanged(listener func(session types.Session)) {
|
||||||
manager.emmiter.On("state_changed", func(payload ...interface{}) {
|
manager.emmiter.On("state_changed", func(payload ...any) {
|
||||||
listener(payload[0].(*SessionCtx))
|
listener(payload[0].(*SessionCtx))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (manager *SessionManagerCtx) OnHostChanged(listener func(session types.Session)) {
|
func (manager *SessionManagerCtx) OnHostChanged(listener func(session types.Session)) {
|
||||||
manager.emmiter.On("host_changed", func(payload ...interface{}) {
|
manager.emmiter.On("host_changed", func(payload ...any) {
|
||||||
if payload[0] == nil {
|
if payload[0] == nil {
|
||||||
listener(nil)
|
listener(nil)
|
||||||
} else {
|
} else {
|
||||||
@ -336,7 +336,7 @@ func (manager *SessionManagerCtx) OnHostChanged(listener func(session types.Sess
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (manager *SessionManagerCtx) OnSettingsChanged(listener func(new types.Settings, old types.Settings)) {
|
func (manager *SessionManagerCtx) OnSettingsChanged(listener func(new types.Settings, old types.Settings)) {
|
||||||
manager.emmiter.On("settings_changed", func(payload ...interface{}) {
|
manager.emmiter.On("settings_changed", func(payload ...any) {
|
||||||
listener(payload[0].(types.Settings), payload[1].(types.Settings))
|
listener(payload[0].(types.Settings), payload[1].(types.Settings))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -119,7 +119,7 @@ func (session *SessionCtx) GetWebSocketPeer() types.WebSocketPeer {
|
|||||||
return session.websocketPeer
|
return session.websocketPeer
|
||||||
}
|
}
|
||||||
|
|
||||||
func (session *SessionCtx) Send(event string, payload interface{}) {
|
func (session *SessionCtx) Send(event string, payload any) {
|
||||||
peer := session.GetWebSocketPeer()
|
peer := session.GetWebSocketPeer()
|
||||||
if peer != nil {
|
if peer != nil {
|
||||||
peer.Send(event, payload)
|
peer.Send(event, payload)
|
||||||
|
@ -83,7 +83,7 @@ func (manager *WebRTCManagerCtx) peerConfiguration() webrtc.Configuration {
|
|||||||
|
|
||||||
ICEServers := []webrtc.ICEServer{}
|
ICEServers := []webrtc.ICEServer{}
|
||||||
for _, server := range manager.config.ICEServers {
|
for _, server := range manager.config.ICEServers {
|
||||||
var credential interface{}
|
var credential any
|
||||||
if server.Credential != "" {
|
if server.Credential != "" {
|
||||||
credential = server.Credential
|
credential = server.Credential
|
||||||
} else {
|
} else {
|
||||||
|
@ -16,7 +16,7 @@ func (l logger) Trace(msg string) {
|
|||||||
l.logger.Trace().Msg(strings.TrimSpace(msg))
|
l.logger.Trace().Msg(strings.TrimSpace(msg))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l logger) Tracef(format string, args ...interface{}) {
|
func (l logger) Tracef(format string, args ...any) {
|
||||||
msg := fmt.Sprintf(format, args...)
|
msg := fmt.Sprintf(format, args...)
|
||||||
l.logger.Trace().Msg(strings.TrimSpace(msg))
|
l.logger.Trace().Msg(strings.TrimSpace(msg))
|
||||||
}
|
}
|
||||||
@ -25,7 +25,7 @@ func (l logger) Debug(msg string) {
|
|||||||
l.logger.Debug().Msg(strings.TrimSpace(msg))
|
l.logger.Debug().Msg(strings.TrimSpace(msg))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l logger) Debugf(format string, args ...interface{}) {
|
func (l logger) Debugf(format string, args ...any) {
|
||||||
msg := fmt.Sprintf(format, args...)
|
msg := fmt.Sprintf(format, args...)
|
||||||
l.logger.Debug().Msg(strings.TrimSpace(msg))
|
l.logger.Debug().Msg(strings.TrimSpace(msg))
|
||||||
}
|
}
|
||||||
@ -38,7 +38,7 @@ func (l logger) Info(msg string) {
|
|||||||
l.logger.Info().Msg(strings.TrimSpace(msg))
|
l.logger.Info().Msg(strings.TrimSpace(msg))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l logger) Infof(format string, args ...interface{}) {
|
func (l logger) Infof(format string, args ...any) {
|
||||||
msg := fmt.Sprintf(format, args...)
|
msg := fmt.Sprintf(format, args...)
|
||||||
if strings.Contains(msg, "duplicated packet") {
|
if strings.Contains(msg, "duplicated packet") {
|
||||||
return
|
return
|
||||||
@ -51,7 +51,7 @@ func (l logger) Warn(msg string) {
|
|||||||
l.logger.Warn().Msg(strings.TrimSpace(msg))
|
l.logger.Warn().Msg(strings.TrimSpace(msg))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l logger) Warnf(format string, args ...interface{}) {
|
func (l logger) Warnf(format string, args ...any) {
|
||||||
msg := fmt.Sprintf(format, args...)
|
msg := fmt.Sprintf(format, args...)
|
||||||
l.logger.Warn().Msg(strings.TrimSpace(msg))
|
l.logger.Warn().Msg(strings.TrimSpace(msg))
|
||||||
}
|
}
|
||||||
@ -60,7 +60,7 @@ func (l logger) Error(msg string) {
|
|||||||
l.logger.Error().Msg(strings.TrimSpace(msg))
|
l.logger.Error().Msg(strings.TrimSpace(msg))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l logger) Errorf(format string, args ...interface{}) {
|
func (l logger) Errorf(format string, args ...any) {
|
||||||
msg := fmt.Sprintf(format, args...)
|
msg := fmt.Sprintf(format, args...)
|
||||||
l.logger.Error().Msg(strings.TrimSpace(msg))
|
l.logger.Error().Msg(strings.TrimSpace(msg))
|
||||||
}
|
}
|
||||||
|
@ -2,13 +2,13 @@ package pionlog
|
|||||||
|
|
||||||
type nulllog struct{}
|
type nulllog struct{}
|
||||||
|
|
||||||
func (l nulllog) Trace(msg string) {}
|
func (l nulllog) Trace(msg string) {}
|
||||||
func (l nulllog) Tracef(format string, args ...interface{}) {}
|
func (l nulllog) Tracef(format string, args ...any) {}
|
||||||
func (l nulllog) Debug(msg string) {}
|
func (l nulllog) Debug(msg string) {}
|
||||||
func (l nulllog) Debugf(format string, args ...interface{}) {}
|
func (l nulllog) Debugf(format string, args ...any) {}
|
||||||
func (l nulllog) Info(msg string) {}
|
func (l nulllog) Info(msg string) {}
|
||||||
func (l nulllog) Infof(format string, args ...interface{}) {}
|
func (l nulllog) Infof(format string, args ...any) {}
|
||||||
func (l nulllog) Warn(msg string) {}
|
func (l nulllog) Warn(msg string) {}
|
||||||
func (l nulllog) Warnf(format string, args ...interface{}) {}
|
func (l nulllog) Warnf(format string, args ...any) {}
|
||||||
func (l nulllog) Error(msg string) {}
|
func (l nulllog) Error(msg string) {}
|
||||||
func (l nulllog) Errorf(format string, args ...interface{}) {}
|
func (l nulllog) Errorf(format string, args ...any) {}
|
||||||
|
@ -26,7 +26,7 @@ func (manager *WebSocketManagerCtx) fileChooserDialogEvents() {
|
|||||||
event.FILE_CHOOSER_DIALOG_OPENED,
|
event.FILE_CHOOSER_DIALOG_OPENED,
|
||||||
message.SessionID{
|
message.SessionID{
|
||||||
ID: host.ID(),
|
ID: host.ID(),
|
||||||
}, nil)
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
// when dialog closes, everyone should be notified.
|
// when dialog closes, everyone should be notified.
|
||||||
@ -37,7 +37,7 @@ func (manager *WebSocketManagerCtx) fileChooserDialogEvents() {
|
|||||||
|
|
||||||
go manager.sessions.Broadcast(
|
go manager.sessions.Broadcast(
|
||||||
event.FILE_CHOOSER_DIALOG_CLOSED,
|
event.FILE_CHOOSER_DIALOG_CLOSED,
|
||||||
message.SessionID{}, nil)
|
message.SessionID{})
|
||||||
})
|
})
|
||||||
|
|
||||||
// when new user joins, and someone holds dialog, he shouldd be notified about it.
|
// when new user joins, and someone holds dialog, he shouldd be notified about it.
|
||||||
|
@ -18,6 +18,6 @@ func (h *MessageHandlerCtx) screenSet(session types.Session, payload *message.Sc
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
h.sessions.Broadcast(event.SCREEN_UPDATED, payload, nil)
|
h.sessions.Broadcast(event.SCREEN_UPDATED, payload)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ func (h *MessageHandlerCtx) sendBroadcast(session types.Session, payload *messag
|
|||||||
Sender: session.ID(),
|
Sender: session.ID(),
|
||||||
Subject: payload.Subject,
|
Subject: payload.Subject,
|
||||||
Body: payload.Body,
|
Body: payload.Body,
|
||||||
}, []string{session.ID()})
|
}, session.ID())
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ func (h *MessageHandlerCtx) SessionCreated(session types.Session) error {
|
|||||||
ID: session.ID(),
|
ID: session.ID(),
|
||||||
Profile: session.Profile(),
|
Profile: session.Profile(),
|
||||||
State: session.State(),
|
State: session.State(),
|
||||||
}, nil)
|
})
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -23,7 +23,7 @@ func (h *MessageHandlerCtx) SessionDeleted(session types.Session) error {
|
|||||||
event.SESSION_DELETED,
|
event.SESSION_DELETED,
|
||||||
message.SessionID{
|
message.SessionID{
|
||||||
ID: session.ID(),
|
ID: session.ID(),
|
||||||
}, nil)
|
})
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -58,7 +58,7 @@ func (h *MessageHandlerCtx) SessionProfileChanged(session types.Session) error {
|
|||||||
message.MemberProfile{
|
message.MemberProfile{
|
||||||
ID: session.ID(),
|
ID: session.ID(),
|
||||||
MemberProfile: session.Profile(),
|
MemberProfile: session.Profile(),
|
||||||
}, nil)
|
})
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func (h *MessageHandlerCtx) SessionStateChanged(session types.Session) error {
|
|||||||
message.SessionState{
|
message.SessionState{
|
||||||
ID: session.ID(),
|
ID: session.ID(),
|
||||||
SessionState: session.State(),
|
SessionState: session.State(),
|
||||||
}, nil)
|
})
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -105,7 +105,7 @@ func (manager *WebSocketManagerCtx) Start() {
|
|||||||
payload.HostID = session.ID()
|
payload.HostID = session.ID()
|
||||||
}
|
}
|
||||||
|
|
||||||
manager.sessions.Broadcast(event.CONTROL_HOST, payload, nil)
|
manager.sessions.Broadcast(event.CONTROL_HOST, payload)
|
||||||
|
|
||||||
manager.logger.Info().
|
manager.logger.Info().
|
||||||
Bool("has_host", payload.HasHost).
|
Bool("has_host", payload.HasHost).
|
||||||
@ -124,7 +124,7 @@ func (manager *WebSocketManagerCtx) Start() {
|
|||||||
manager.stopInactiveCursors()
|
manager.stopInactiveCursors()
|
||||||
}
|
}
|
||||||
|
|
||||||
manager.sessions.Broadcast(event.SYSTEM_SETTINGS, new, nil)
|
manager.sessions.Broadcast(event.SYSTEM_SETTINGS, new)
|
||||||
manager.logger.Info().
|
manager.logger.Info().
|
||||||
Interface("new", new).
|
Interface("new", new).
|
||||||
Interface("old", old).
|
Interface("old", old).
|
||||||
@ -347,7 +347,7 @@ func (manager *WebSocketManagerCtx) startInactiveCursors() {
|
|||||||
|
|
||||||
// remove last cursor entries and send empty message
|
// remove last cursor entries and send empty message
|
||||||
_ = manager.sessions.PopCursors()
|
_ = manager.sessions.PopCursors()
|
||||||
manager.sessions.InactiveCursorsBroadcast(event.SESSION_CURSORS, []message.SessionCursors{}, nil)
|
manager.sessions.InactiveCursorsBroadcast(event.SESSION_CURSORS, []message.SessionCursors{})
|
||||||
return
|
return
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
cursorsMap := manager.sessions.PopCursors()
|
cursorsMap := manager.sessions.PopCursors()
|
||||||
@ -369,7 +369,7 @@ func (manager *WebSocketManagerCtx) startInactiveCursors() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
manager.sessions.InactiveCursorsBroadcast(event.SESSION_CURSORS, sessionCursors, nil)
|
manager.sessions.InactiveCursorsBroadcast(event.SESSION_CURSORS, sessionCursors)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
@ -36,7 +36,7 @@ func (peer *WebSocketPeerCtx) setSessionID(sessionId string) {
|
|||||||
peer.logger = peer.logger.With().Str("session_id", sessionId).Logger()
|
peer.logger = peer.logger.With().Str("session_id", sessionId).Logger()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (peer *WebSocketPeerCtx) Send(event string, payload interface{}) {
|
func (peer *WebSocketPeerCtx) Send(event string, payload any) {
|
||||||
peer.mu.Lock()
|
peer.mu.Lock()
|
||||||
defer peer.mu.Unlock()
|
defer peer.mu.Unlock()
|
||||||
|
|
||||||
|
@ -79,14 +79,14 @@ type VideoConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (config *VideoConfig) GetPipeline(screen ScreenSize) (string, error) {
|
func (config *VideoConfig) GetPipeline(screen ScreenSize) (string, error) {
|
||||||
values := map[string]interface{}{
|
values := map[string]any{
|
||||||
"width": screen.Width,
|
"width": screen.Width,
|
||||||
"height": screen.Height,
|
"height": screen.Height,
|
||||||
"fps": screen.Rate,
|
"fps": screen.Rate,
|
||||||
}
|
}
|
||||||
|
|
||||||
language := []gval.Language{
|
language := []gval.Language{
|
||||||
gval.Function("round", func(args ...interface{}) (interface{}, error) {
|
gval.Function("round", func(args ...any) (any, error) {
|
||||||
return (int)(math.Round(args[0].(float64))), nil
|
return (int)(math.Round(args[0].(float64))), nil
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
|
@ -32,9 +32,9 @@ type SystemAdmin struct {
|
|||||||
type SystemLogs = []SystemLog
|
type SystemLogs = []SystemLog
|
||||||
|
|
||||||
type SystemLog struct {
|
type SystemLog struct {
|
||||||
Level string `json:"level"`
|
Level string `json:"level"`
|
||||||
Fields map[string]interface{} `json:"fields"`
|
Fields map[string]any `json:"fields"`
|
||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SystemDisconnect struct {
|
type SystemDisconnect struct {
|
||||||
@ -163,14 +163,14 @@ type BroadcastStatus struct {
|
|||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
|
|
||||||
type SendUnicast struct {
|
type SendUnicast struct {
|
||||||
Sender string `json:"sender"`
|
Sender string `json:"sender"`
|
||||||
Receiver string `json:"receiver"`
|
Receiver string `json:"receiver"`
|
||||||
Subject string `json:"subject"`
|
Subject string `json:"subject"`
|
||||||
Body interface{} `json:"body"`
|
Body any `json:"body"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SendBroadcast struct {
|
type SendBroadcast struct {
|
||||||
Sender string `json:"sender"`
|
Sender string `json:"sender"`
|
||||||
Subject string `json:"subject"`
|
Subject string `json:"subject"`
|
||||||
Body interface{} `json:"body"`
|
Body any `json:"body"`
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ type Session interface {
|
|||||||
SetWebSocketPeer(websocketPeer WebSocketPeer)
|
SetWebSocketPeer(websocketPeer WebSocketPeer)
|
||||||
SetWebSocketConnected(websocketPeer WebSocketPeer, connected bool)
|
SetWebSocketConnected(websocketPeer WebSocketPeer, connected bool)
|
||||||
GetWebSocketPeer() WebSocketPeer
|
GetWebSocketPeer() WebSocketPeer
|
||||||
Send(event string, payload interface{})
|
Send(event string, payload any)
|
||||||
|
|
||||||
// webrtc
|
// webrtc
|
||||||
SetWebRTCPeer(webrtcPeer WebRTCPeer)
|
SetWebRTCPeer(webrtcPeer WebRTCPeer)
|
||||||
@ -66,9 +66,9 @@ type SessionManager interface {
|
|||||||
SetCursor(cursor Cursor, session Session)
|
SetCursor(cursor Cursor, session Session)
|
||||||
PopCursors() map[Session][]Cursor
|
PopCursors() map[Session][]Cursor
|
||||||
|
|
||||||
Broadcast(event string, payload interface{}, exclude interface{})
|
Broadcast(event string, payload any, exclude ...string)
|
||||||
AdminBroadcast(event string, payload interface{}, exclude interface{})
|
AdminBroadcast(event string, payload any, exclude ...string)
|
||||||
InactiveCursorsBroadcast(event string, payload interface{}, exclude interface{})
|
InactiveCursorsBroadcast(event string, payload any, exclude ...string)
|
||||||
|
|
||||||
OnCreated(listener func(session Session))
|
OnCreated(listener func(session Session))
|
||||||
OnDeleted(listener func(session Session))
|
OnDeleted(listener func(session Session))
|
||||||
|
@ -15,7 +15,7 @@ type WebSocketHandler func(Session, WebSocketMessage) bool
|
|||||||
type CheckOrigin func(r *http.Request) bool
|
type CheckOrigin func(r *http.Request) bool
|
||||||
|
|
||||||
type WebSocketPeer interface {
|
type WebSocketPeer interface {
|
||||||
Send(event string, payload interface{})
|
Send(event string, payload any)
|
||||||
Ping() error
|
Ping() error
|
||||||
Destroy(reason string)
|
Destroy(reason string)
|
||||||
}
|
}
|
||||||
|
@ -1,22 +1,12 @@
|
|||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
func ArrayIn[T comparable](val T, array []T) (exists bool, index int) {
|
||||||
"reflect"
|
exists, index = false, -1
|
||||||
)
|
|
||||||
|
|
||||||
func ArrayIn(val interface{}, array interface{}) (exists bool, index int) {
|
for i, a := range array {
|
||||||
exists = false
|
if a == val {
|
||||||
index = -1
|
exists, index = true, i
|
||||||
|
return
|
||||||
switch reflect.TypeOf(array).Kind() {
|
|
||||||
case reflect.Slice:
|
|
||||||
s := reflect.ValueOf(array)
|
|
||||||
for i := 0; i < s.Len(); i++ {
|
|
||||||
if reflect.DeepEqual(val, s.Index(i).Interface()) {
|
|
||||||
index = i
|
|
||||||
exists = true
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,6 +29,6 @@ func Color(str string) string {
|
|||||||
return result + str[lastIndex:]
|
return result + str[lastIndex:]
|
||||||
}
|
}
|
||||||
|
|
||||||
func Colorf(format string, a ...interface{}) string {
|
func Colorf(format string, a ...any) string {
|
||||||
return fmt.Sprintf(Color(format), a...)
|
return fmt.Sprintf(Color(format), a...)
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func HttpJsonRequest(w http.ResponseWriter, r *http.Request, res interface{}) error {
|
func HttpJsonRequest(w http.ResponseWriter, r *http.Request, res any) error {
|
||||||
err := json.NewDecoder(r.Body).Decode(res)
|
err := json.NewDecoder(r.Body).Decode(res)
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@ -23,7 +23,7 @@ func HttpJsonRequest(w http.ResponseWriter, r *http.Request, res interface{}) er
|
|||||||
return HttpBadRequest("unable to parse provided data").WithInternalErr(err)
|
return HttpBadRequest("unable to parse provided data").WithInternalErr(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func HttpJsonResponse(w http.ResponseWriter, code int, res interface{}) {
|
func HttpJsonResponse(w http.ResponseWriter, code int, res any) {
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
w.WriteHeader(code)
|
w.WriteHeader(code)
|
||||||
|
|
||||||
@ -32,7 +32,7 @@ func HttpJsonResponse(w http.ResponseWriter, code int, res interface{}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func HttpSuccess(w http.ResponseWriter, res ...interface{}) error {
|
func HttpSuccess(w http.ResponseWriter, res ...any) error {
|
||||||
if len(res) == 0 {
|
if len(res) == 0 {
|
||||||
w.WriteHeader(http.StatusNoContent)
|
w.WriteHeader(http.StatusNoContent)
|
||||||
} else {
|
} else {
|
||||||
@ -78,13 +78,13 @@ func (e *HTTPError) WithInternalMsg(msg string) *HTTPError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// WithInternalMsg adds internal formated message information to the error
|
// WithInternalMsg adds internal formated message information to the error
|
||||||
func (e *HTTPError) WithInternalMsgf(fmtStr string, args ...interface{}) *HTTPError {
|
func (e *HTTPError) WithInternalMsgf(fmtStr string, args ...any) *HTTPError {
|
||||||
e.InternalMsg = fmt.Sprintf(fmtStr, args...)
|
e.InternalMsg = fmt.Sprintf(fmtStr, args...)
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sends error with custom formated message
|
// Sends error with custom formated message
|
||||||
func (e *HTTPError) Msgf(fmtSt string, args ...interface{}) *HTTPError {
|
func (e *HTTPError) Msgf(fmtSt string, args ...any) *HTTPError {
|
||||||
e.Message = fmt.Sprintf(fmtSt, args...)
|
e.Message = fmt.Sprintf(fmtSt, args...)
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
|
@ -5,15 +5,15 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Unmarshal(in interface{}, raw []byte, callback func() error) error {
|
func Unmarshal(in any, raw []byte, callback func() error) error {
|
||||||
if err := json.Unmarshal(raw, &in); err != nil {
|
if err := json.Unmarshal(raw, &in); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return callback()
|
return callback()
|
||||||
}
|
}
|
||||||
|
|
||||||
func JsonStringAutoDecode(m interface{}) func(rf reflect.Kind, rt reflect.Kind, data interface{}) (interface{}, error) {
|
func JsonStringAutoDecode(m any) func(rf reflect.Kind, rt reflect.Kind, data any) (any, error) {
|
||||||
return func(rf reflect.Kind, rt reflect.Kind, data interface{}) (interface{}, error) {
|
return func(rf reflect.Kind, rt reflect.Kind, data any) (any, error) {
|
||||||
if rf != reflect.String || rt == reflect.String {
|
if rf != reflect.String || rt == reflect.String {
|
||||||
return data, nil
|
return data, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user