last version on Github
parent
8bb6415d41
commit
0b65309bbb
|
|
@ -146,3 +146,15 @@ func GetAllUsers(c *fiber.Ctx) error {
|
|||
|
||||
return c.JSON(users)
|
||||
}
|
||||
|
||||
func WixIntegration(c *fiber.Ctx) error {
|
||||
var data map[string]string
|
||||
|
||||
if err := c.BodyParser(&data); err != nil {
|
||||
return fiber.ErrBadRequest
|
||||
}
|
||||
|
||||
utils.PrettyPrintJson(data)
|
||||
|
||||
return c.JSON(data)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,75 +1,70 @@
|
|||
package controllers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"api/models"
|
||||
"api/utils"
|
||||
"log"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
type Pub struct {
|
||||
Server string `json:"server_id"`
|
||||
Protocol string `json:"protocol"`
|
||||
Url string `json:"url"`
|
||||
AppName string `json:"app_name"`
|
||||
Channel string `json:"stream_name"`
|
||||
UrlParam string `json:"url_param"`
|
||||
RemoteAddress string `json:"remotet_addr"`
|
||||
HasInSession bool `json:"has_in_session"`
|
||||
HasOutSession bool `json:"has_out_session"`
|
||||
}
|
||||
|
||||
type Update struct {
|
||||
Server string `json:"server_id"`
|
||||
Groups []Group `json:"groups"`
|
||||
}
|
||||
|
||||
type Group struct {
|
||||
Channel string `json:"stream_name"`
|
||||
AudioCodec string `json:"audio_codec"`
|
||||
VideoCodec string `json:"video_codec"`
|
||||
VideoWidth int `json:"video_width"`
|
||||
VideoHeight int `json:"video_height"`
|
||||
UpdPub UpdPub `json:"pub"`
|
||||
Subs string `json:"subs"`
|
||||
UpdPull UpdPub `json:"pull"`
|
||||
}
|
||||
|
||||
type UpdPub struct {
|
||||
Protocol string `json:"protocol"`
|
||||
SessionId string `json:"session_id"`
|
||||
RemoteAddress string `json:"remote_addr"`
|
||||
StartTime string `json:"start_time"`
|
||||
ReadBytesSum int `json:"read_bytes_sum"`
|
||||
WroteBytesSum int `json:"wrote_bytes_sum"`
|
||||
Bitrate int `json:"bitrate"`
|
||||
ReadBitrate int `json:"read_bitrate"`
|
||||
WriteBitrate int `json:"write_bitrate"`
|
||||
}
|
||||
|
||||
func ServerStart(c *fiber.Ctx) error {
|
||||
fmt.Println("Server started")
|
||||
log.Println(string(c.Body()))
|
||||
// Creates a server struct
|
||||
s := new(models.LalServer)
|
||||
|
||||
// Parse the body of the request to the server struct
|
||||
if err := c.BodyParser(s); err != nil {
|
||||
log.Printf("Error Start: %s\n", err)
|
||||
return err
|
||||
}
|
||||
|
||||
log.Printf("Server started")
|
||||
|
||||
// Marshal the server struct to JSON
|
||||
utils.PrettyPrintJson(s)
|
||||
return c.SendString("Server started: " + string(c.Body()))
|
||||
}
|
||||
|
||||
func OnUpdate(c *fiber.Ctx) error {
|
||||
p := new(Update)
|
||||
p := new(models.Update)
|
||||
if err := c.BodyParser(p); err != nil {
|
||||
log.Printf("Error Update: %s\n", err)
|
||||
return err
|
||||
}
|
||||
|
||||
log.Printf("Update")
|
||||
utils.PrettyPrintJson(p)
|
||||
|
||||
if len(p.Groups) > 0 {
|
||||
for _, g := range p.Groups {
|
||||
log.Printf("Update %s %s [(%dx%d) %d]\n", g.Channel, g.UpdPub.StartTime, g.VideoWidth, g.VideoHeight, g.UpdPub.ReadBytesSum)
|
||||
}
|
||||
}
|
||||
|
||||
return c.SendString("On_Update: " + string(c.Body()))
|
||||
}
|
||||
|
||||
func OnSubStart(c *fiber.Ctx) error {
|
||||
p := new(models.Update)
|
||||
if err := c.BodyParser(p); err != nil {
|
||||
log.Printf("Error Update: %s\n", err)
|
||||
return err
|
||||
}
|
||||
|
||||
log.Printf("SubStart")
|
||||
utils.PrettyPrintJson(p)
|
||||
|
||||
// if len(p.Groups) > 0 {
|
||||
// for _, g := range p.Groups {
|
||||
// log.Printf("Update %s %s [(%dx%d) %d]\n", g.Channel, g.UpdPub.StartTime, g.VideoWidth, g.VideoHeight, g.UpdPub.ReadBytesSum)
|
||||
// }
|
||||
// }
|
||||
|
||||
return c.SendString("On_Substart: " + string(c.Body()))
|
||||
}
|
||||
|
||||
func OnPubStart(c *fiber.Ctx) error {
|
||||
p := new(Pub)
|
||||
p := new(models.Pub)
|
||||
if err := c.BodyParser(p); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -78,7 +73,7 @@ func OnPubStart(c *fiber.Ctx) error {
|
|||
}
|
||||
|
||||
func OnPubStop(c *fiber.Ctx) error {
|
||||
p := new(Pub)
|
||||
p := new(models.Pub)
|
||||
if err := c.BodyParser(p); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package globals
|
||||
|
||||
var (
|
||||
API_VERSION = "1.0.18"
|
||||
API_VERSION = "1.0.20"
|
||||
API_RELEASE = ""
|
||||
)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,30 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>HLS.js Example</title>
|
||||
<script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<video id="videoPlayer" controls autoplay></video>
|
||||
<script>
|
||||
if (Hls.isSupported()) {
|
||||
var video = document.getElementById('videoPlayer');
|
||||
var hls = new Hls();
|
||||
hls.loadSource('http://localhost:8080/hls/teste/playlist.m3u8');
|
||||
hls.attachMedia(video);
|
||||
hls.on(Hls.Events.MANIFEST_PARSED, function () {
|
||||
video.play();
|
||||
});
|
||||
}
|
||||
else if (video.canPlayType('application/vnd.apple.mpegurl')) {
|
||||
video.src = 'http://localhost:8080/hls/teste/playlist.m3u8';
|
||||
video.addEventListener('loadedmetadata', function () {
|
||||
video.play();
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
|
@ -6,12 +6,3 @@ http://www.pcastt.com.br, http://pcastt.com.br, https://www.pcastt.com.br, https
|
|||
reverse_proxy localhost:8111
|
||||
}
|
||||
}
|
||||
|
||||
http://www.pcastlive.com.br, http://pcastlive.com.br, https://www.pcastlive.com.br, https://pcastlive.com.br {
|
||||
root * /root/sites/pcastlive
|
||||
file_server
|
||||
|
||||
handle_path /api/* {
|
||||
reverse_proxy localhost:8112
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
service api stop
|
||||
cp /home/ftpuser/ftp/files/api /root/api
|
||||
chmod 777 /root//api/api
|
||||
chmod 777 /root/api/api
|
||||
service api start
|
||||
|
|
|
|||
14
main.go
14
main.go
|
|
@ -14,17 +14,17 @@ import (
|
|||
)
|
||||
|
||||
func main() {
|
||||
logFile, err := os.OpenFile("api.log", os.O_CREATE | os.O_APPEND | os.O_RDWR, 0666)
|
||||
logFile, err := os.OpenFile("api.log", os.O_CREATE|os.O_APPEND|os.O_RDWR, 0666)
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
panic(err)
|
||||
}
|
||||
mw := io.MultiWriter(os.Stdout, logFile)
|
||||
log.SetOutput(mw)
|
||||
|
||||
log.Println("Starting API", globals.API_VERSION)
|
||||
log.Println("OS:", os.Getenv("OS"))
|
||||
|
||||
log.Println("OS:", os.Getenv("OS"))
|
||||
|
||||
app := fiber.New(fiber.Config{
|
||||
StrictRouting: false,
|
||||
DisableStartupMessage: true,
|
||||
|
|
@ -42,7 +42,7 @@ func main() {
|
|||
if err != nil {
|
||||
log.Fatalf("error opening file: %v", err)
|
||||
}
|
||||
|
||||
|
||||
defer file.Close()
|
||||
|
||||
app.Use(logger.New(logger.Config{
|
||||
|
|
@ -56,5 +56,7 @@ func main() {
|
|||
routes.Setup(app)
|
||||
|
||||
log.Println("Server started in port " + os.Getenv("API_PORT"))
|
||||
app.Listen(":" + os.Getenv("API_PORT"))
|
||||
if erro := app.Listen(":" + os.Getenv("API_PORT")); err != nil {
|
||||
panic(erro)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,51 @@
|
|||
package models
|
||||
|
||||
type LalServer struct {
|
||||
Server string `json:"server_id"`
|
||||
BinInfo string `json:"-"`
|
||||
LalVersion string `json:"lal_version"`
|
||||
APIVersion string `json:"-"`
|
||||
NotifyVersion string `json:"-"`
|
||||
WebUIVersion string `json:"-"`
|
||||
StartTime string `json:"start_time"`
|
||||
}
|
||||
|
||||
type Pub struct {
|
||||
Server string `json:"server_id"`
|
||||
Protocol string `json:"protocol"`
|
||||
Url string `json:"url"`
|
||||
AppName string `json:"app_name"`
|
||||
Channel string `json:"stream_name"`
|
||||
UrlParam string `json:"url_param"`
|
||||
RemoteAddress string `json:"remotet_addr"`
|
||||
HasInSession bool `json:"has_in_session"`
|
||||
HasOutSession bool `json:"has_out_session"`
|
||||
}
|
||||
|
||||
type Update struct {
|
||||
LalServer string `json:"server_id"`
|
||||
Groups []Group `json:"groups"`
|
||||
}
|
||||
|
||||
type Group struct {
|
||||
Channel string `json:"stream_name"`
|
||||
AudioCodec string `json:"audio_codec"`
|
||||
VideoCodec string `json:"video_codec"`
|
||||
VideoWidth int `json:"video_width"`
|
||||
VideoHeight int `json:"video_height"`
|
||||
UpdPub UpdPub `json:"pub"`
|
||||
Subs string `json:"subs"`
|
||||
UpdPull UpdPub `json:"pull"`
|
||||
}
|
||||
|
||||
type UpdPub struct {
|
||||
Protocol string `json:"protocol"`
|
||||
SessionId string `json:"session_id"`
|
||||
RemoteAddress string `json:"remote_addr"`
|
||||
StartTime string `json:"start_time"`
|
||||
ReadBytesSum int `json:"read_bytes_sum"`
|
||||
WroteBytesSum int `json:"wrote_bytes_sum"`
|
||||
Bitrate int `json:"bitrate"`
|
||||
ReadBitrate int `json:"read_bitrate"`
|
||||
WriteBitrate int `json:"write_bitrate"`
|
||||
}
|
||||
|
|
@ -12,6 +12,8 @@ import (
|
|||
// Setup sets up the routes
|
||||
func Setup(app *fiber.App) {
|
||||
|
||||
app.Post("/integration", controllers.WixIntegration)
|
||||
|
||||
app.Get("/version", controllers.Version)
|
||||
|
||||
app.Post("/login", controllers.Login)
|
||||
|
|
@ -23,6 +25,7 @@ func Setup(app *fiber.App) {
|
|||
app.Post("/on_update", controllers.OnUpdate)
|
||||
app.Post("/on_pub_start", controllers.OnPubStart)
|
||||
app.Post("/on_pub_stop", controllers.OnPubStop)
|
||||
app.Post("/on_sub_start", controllers.OnSubStart)
|
||||
|
||||
// Protected routes. Needs login before.
|
||||
protected := app.Group("/")
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
|
|
@ -61,3 +63,11 @@ func ProcessToken(c *fiber.Ctx) (interface{}, error) {
|
|||
func jwtKeyFunc(token *jwt.Token) (interface{}, error) {
|
||||
return []byte(os.Getenv("API_SECRET")), nil
|
||||
}
|
||||
|
||||
func PrettyPrintJson(data interface{}) {
|
||||
b, err := json.MarshalIndent(data, "", " ")
|
||||
if err != nil {
|
||||
fmt.Println("error:", err)
|
||||
}
|
||||
log.Println(string(b))
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue