This commit is contained in:
langhuihui
2020-09-08 08:01:46 +08:00
parent 80d5d335fa
commit dd27ba82d8
9 changed files with 9491 additions and 28 deletions

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
node_modules
.vscode

30
main.go
View File

@@ -5,10 +5,12 @@ import (
"gitee.com/xiaochengtech/sdp"
"gitee.com/xiaochengtech/sip"
. "github.com/Monibuca/engine/v2"
"github.com/Monibuca/engine/v2/util"
"github.com/Monibuca/plugin-gb28181/transaction"
"github.com/Monibuca/plugin-gb28181/tu"
pluginrtp "github.com/Monibuca/plugin-rtp"
"math/rand"
"net/http"
//"github.com/max-min/streams/packet"
"github.com/looplab/fsm"
"log"
@@ -20,12 +22,13 @@ import (
var Devices sync.Map
var config = struct {
SipID string
Serial string
Realm string
ListenAddr string
Expires int
AutoInvite bool
MediaPort int
}{"34020000002000000001", ":5060", 3600, true,6000}
}{"34020000002000000001", "3402000000","127.0.0.1:5060", 3600, true,6000}
type DeviceInfo struct {
sip.User
@@ -153,18 +156,21 @@ func resolvePS(){
}
func run() {
ipAddr,err:=net.ResolveUDPAddr("",config.ListenAddr)
if err!=nil{
log.Fatal(err)
}
go resolvePS()
config := &transaction.Config{
SipIP: "192.168.1.120",
SipPort: 5060,
SipIP: ipAddr.IP.String(),
SipPort: uint16(ipAddr.Port),
SipNetwork: "UDP",
Serial: "34020000002000000001",
Realm: "3402000000",
Serial: config.Serial,
Realm: config.Realm,
AckTimeout: 10,
RegisterValidity: 3600,
RegisterValidity: config.Expires,
RegisterInterval: 60,
HeartbeatInterval: 60,
HeartbeatRetry: 3,
@@ -175,11 +181,13 @@ func run() {
MediaPortMax: 58300,
MediaIdleTimeout: 30,
}
s := tu.NewServer(config)
s := transaction.NewCore(config)
s.Start()
http.HandleFunc("gb28181/list", func(w http.ResponseWriter, r *http.Request) {
sse:=util.NewSSE(w,r.Context())
})
//addr, err := net.ResolveUDPAddr("udp", config.ListenAddr)
//if err != nil {
// log.Fatal(err)

6
ps.go
View File

@@ -1 +1,7 @@
package gb28181
import "github.com/mask-pp/rtp-ps/packet"
func init(){
println(packet.NewRtpParsePacket())
}

View File

@@ -5,6 +5,7 @@ import (
"fmt"
"github.com/Monibuca/plugin-gb28181/sip"
"github.com/Monibuca/plugin-gb28181/transport"
"github.com/Monibuca/plugin-gb28181/tu"
"github.com/Monibuca/plugin-gb28181/utils"
"os"
"sync"
@@ -33,21 +34,20 @@ func NewCore(config *Config) *Core {
core := &Core{
handlers: make(map[State]map[Event]Handler),
transactions: make(map[string]*Transaction),
mutex: sync.Mutex{},
removeTa: make(chan string, 10),
config: config,
tp: transport.NewUDPClient(config.SipIP, config.SipPort),
ctx: context.Background(),
}
if config.SipNetwork == "TCP" {
core.tp = transport.NewTCPServer(config.SipPort,true)
} else {
core.tp = transport.NewUDPServer(config.SipPort)
}
//可以放一些全局参数在ctx
core.ctx = context.Background()
//填充fsm
core.addICTHandler()
core.addISTHandler()
core.addNICTHandler()
core.addNISTHandler()
return core
}
@@ -317,21 +317,21 @@ func (c *Core) HandleReceiveMessage(p *transport.Packet) (err error) {
}
ta = c.initTransaction(c.ctx, e)
//as uas
if msg.GetMethod() == sip.INVITE {
switch msg.GetMethod() {
case sip.INVITE:
ta.typo = FSM_IST
ta.state = IST_PRE_PROCEEDING
} else {
ta.typo = FSM_NIST
ta.state = NIST_PRE_TRYING
}
//构建transaction之后
if msg.GetMethod() == sip.CANCEL {
case sip.CANCEL:
//TODO:CANCEL处理
/* special handling for CANCEL */
/* in the new spec, if the CANCEL has a Via branch, then it
is the same as the one in the original INVITE */
return
case sip.REGISTER:
ta.typo = FSM_NIST
ta.state = NIST_PRE_TRYING
response:=tu.BuildResponse(msg)
c.SendMessage(response)
}
c.AddTransaction(ta)
} else {

View File

@@ -64,7 +64,19 @@ func BuildMessageRequest(method sip.Method, transport, sipSerial, sipRealm, user
}
return msg
}
func BuildResponse(msg *sip.Message)*sip.Message{
response:=sip.Message{
Mode: sip.SIP_MESSAGE_RESPONSE,
From: msg.From,
To: msg.To,
CallID: msg.CallID,
CSeq: msg.CSeq,
Via:msg.Via,
MaxForwards: msg.MaxForwards,
}
response.StartLine
return &response
}
//z9hG4bK + 10个随机数字
func randBranch() string {
return fmt.Sprintf("z9hG4bK%s", utils.RandNumString(8))

View File

@@ -16,7 +16,6 @@ type Server struct {
func NewServer(config *transaction.Config) *Server {
return &Server{
Core: transaction.NewCore(config),
registers: sync.Map{},
}
}

9373
ui/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

15
ui/package.json Normal file
View File

@@ -0,0 +1,15 @@
{
"name": "dashboard",
"version": "1.0.0",
"description": "dashboard of gb28181 plugin for monibuca",
"main": "index.js",
"scripts": {
"build": "vue-cli-service build --target lib --name plugin-gb28181"
},
"author": "dexter",
"license": "ISC",
"devDependencies": {
"@vue/cli-service": "^4.5.4",
"vue-template-compiler": "^2.6.12"
}
}

48
ui/src/App.vue Normal file
View File

@@ -0,0 +1,48 @@
<template>
<div>
<mu-data-table :data="Devices" :columns="columns">
<template #default="{row:item}">
<td>{{item.ID}}</td>
<td>
<StartTime :value="item.RegisterTime"></StartTime>
</td>
<td>
<StartTime :value="item.UpdateTime"></StartTime>
</td>
<td>{{item.IP}}</td>
<td>{{item.Status}}</td>
<td>
<mu-button flat @click="preview(item)">预览</mu-button>
</td>
</template>
</mu-data-table>
</div>
</template>
<script>
export default {
data(){
return {
Devices:[],
columns:Object.freeze([
"设备号","注册时间","更新时间","IP","状态"
].map(title=>({title})))
}
},
created(){
this.fetchlist()
},
methods:{
fetchlist() {
const listES = new EventSource(this.apiHost + "/gb28181/list");
listES.onmessage = evt => {
if (!evt.data) return;
this.Devices = JSON.parse(evt.data) || [];
};
this.$once("hook:destroyed",()=>listES.close())
},
preview(item){
alert("尚未实现")
}
}
}
</script>