mirror of
https://github.com/lkmio/gb-cms.git
synced 2025-09-26 19:51:22 +08:00
feat: 支持1078转GB28181
This commit is contained in:
50
hook/event.go
Normal file
50
hook/event.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package hook
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
const (
|
||||
EventTypeDeviceOnline = iota + 1
|
||||
EventTypeDeviceOffline
|
||||
EventTypeDevicePosition
|
||||
EventTypeDeviceOnInvite
|
||||
)
|
||||
|
||||
var (
|
||||
EventUrls = make(map[int]string)
|
||||
)
|
||||
|
||||
func RegisterEventUrl(event int, url string) {
|
||||
EventUrls[event] = url
|
||||
}
|
||||
|
||||
func PostEvent(url string, body []byte) (*http.Response, error) {
|
||||
client := &http.Client{
|
||||
//Timeout: time.Duration(AppConfig.Hooks.Timeout),
|
||||
}
|
||||
|
||||
request, err := http.NewRequest("post", url, bytes.NewBuffer(body))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
request.Header.Set("Content-Type", "application/json")
|
||||
return client.Do(request)
|
||||
}
|
||||
|
||||
func PostOnInviteEvent(simNumber, channelNumber string) (*http.Response, error) {
|
||||
params := map[string]string{
|
||||
"sim_number": simNumber,
|
||||
"channel_number": channelNumber,
|
||||
}
|
||||
|
||||
body, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return PostEvent(EventUrls[EventTypeDeviceOnInvite], body)
|
||||
}
|
Reference in New Issue
Block a user