Stian Fredrik Aune
4 years ago
7 changed files with 111 additions and 9 deletions
-
50app/services/bridges.go
-
32app/services/events.go
-
4internal/drivers/nanoleaf/bridge.go
-
16models/event.go
-
6models/shared.go
-
4webui/src/primitives/Forms.tsx
-
8webui/src/setupProxy.js
@ -0,0 +1,50 @@ |
|||
package services |
|||
|
|||
import ( |
|||
"context" |
|||
"git.aiterp.net/lucifer/new-server/app/config" |
|||
"log" |
|||
"time" |
|||
) |
|||
|
|||
var cancelMap = make(map[int]context.CancelFunc, 8) |
|||
|
|||
func ConnectToBridges() { |
|||
go func() { |
|||
for { |
|||
err := runConnectToBridges() |
|||
if err != nil { |
|||
log.Println("Bridge connection error: ", err.Error()) |
|||
} |
|||
|
|||
time.Sleep(15 * time.Second) |
|||
} |
|||
}() |
|||
} |
|||
|
|||
func runConnectToBridges() error { |
|||
bridges, err := config.BridgeRepository().FetchAll(context.Background()) |
|||
if err != nil { |
|||
return err |
|||
} |
|||
|
|||
for _, bridge := range bridges { |
|||
if cancelMap[bridge.ID] != nil { |
|||
continue |
|||
} |
|||
|
|||
driver, err := config.DriverProvider().Provide(bridge.Driver) |
|||
if err != nil { |
|||
return err |
|||
} |
|||
|
|||
ctx, cancel := context.WithCancel(context.Background()) |
|||
err = driver.Run(ctx, bridge, config.EventChannel) |
|||
|
|||
cancelMap[bridge.ID] = cancel |
|||
|
|||
log.Printf("Connected to bridge \"%s\" (%d)", bridge.Name, bridge.ID) |
|||
} |
|||
|
|||
return nil |
|||
} |
@ -0,0 +1,8 @@ |
|||
const proxy = require("http-proxy-middleware"); |
|||
|
|||
let config = {url: "http://127.0.0.1:9000/"}; |
|||
|
|||
module.exports = function(app) { |
|||
app.use(proxy('/api/ws', { target: config.url, ws: true })); |
|||
app.use(proxy('/api', { target: config.url, ws: false })); |
|||
}; |
Write
Preview
Loading…
Cancel
Save
Reference in new issue