Giter VIP home page Giter VIP logo

gsip's Introduction

gsip

基于 Golang 实现的 SIP 协议栈

写在前面

  • 本项目是在 @gosip 的 项目基础上修改,根据自己的使用习惯修改添加,感谢!

使用

go get -u github.com/zenghr0820/gsip

package sip
import (
	"fmt"

	"github.com/zenghr0820/gsip"
	"github.com/zenghr0820/gsip/sip"
)

// 处理sip请求
var RequestHandleMap map[sip.RequestMethod]sip.RequestHandler
// 处理 SIP 响应
var ResponseHandle sip.ResponseHandler

// 初始化
func init() {
	// 请求
	RequestHandleMap = map[sip.RequestMethod]sip.RequestHandler{
		sip.REGISTER: func (request sip.Request, tx sip.ServerTransaction) {
			// ...
		},
		sip.MESSAGE:  func (request sip.Request, tx sip.ServerTransaction) {
			// ...
		},
		// ...
	}
	
	// 响应
	ResponseHandle = func (response sip.Response, tx sip.ClientTransaction) {
		// ...
	}
}

func InitSipServlet() {

	// 创建 SIP 服务
	service := gsip.NewService(
		gsip.Transport("192.168.0.102"),
		// 添加 sip 处理函数
		gsip.RequestCallback(RequestHandleMap),
		gsip.ResponseCallback(ResponseHandle),
		// 开启 sip 日志
		gsip.LoggerConfig(
			gsip.LoggerEnv("dev"),
			gsip.LoggerLevel("info"),
		),
	)

	// 监听 sip 端口
	if err := service.Listen("udp", fmt.Sprintf(
		"%s:%v",
		"0.0.0.0",
		5060)); err !=nil {
		fmt.Println(err)
	}

	if err := service.Listen("tcp", fmt.Sprintf(
		"%s:%v",
		"0.0.0.0",
		5060)); err !=nil {
		fmt.Println(err)
	}

	// 阻塞运行
	if err := service.Run(); err != nil {
		fmt.Println(err)
	}

}

参考资料

gsip's People

Contributors

zenghr0820 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.