Skip to content

Commit

Permalink
#7 There is big refactor to allow server and client to be splitted in…
Browse files Browse the repository at this point in the history
… use
  • Loading branch information
emiago committed Jun 13, 2023
1 parent f8fb502 commit 7474ae8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
22 changes: 17 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Fetch lib with:

`go get github.com/emiago/sipgo`

**NOTE**: LIB IS IN DEV. API CAN CHANGE
**NOTE**: LIB MAY HAVE API CHANGES UNTIL STABLE VERSION.

## Performance

Expand All @@ -28,6 +28,7 @@ To find out more about performance check the latest results:
- Register with authentication [example/register](example/register)
- Dialog [example/dialog](example/dialog)

***If you use this lib in some way, open issue for more sharing.***
## Usage

Lib allows you to write easily sip servers(or clients) or to build up stateful proxies, registrar or any sip routing.
Expand All @@ -36,6 +37,8 @@ Writing in GO we are not limited to handle SIP requests/responses in many ways,

### UAS/UAC build

Using server or client handle for UA you can build incoming or outgoing requests.

```go
ua, _ := sipgo.NewUA() // Build user agent
srv, _ := sipgo.NewServer(ua) // Creating server handle
Expand All @@ -52,6 +55,7 @@ go srv.ListenAndServe(ctx, "ws", "127.0.0.1:5080")
go srv.ListenAndServe(ctx, "udp", "127.0.0.1:5060")
<-ctx.Done()
```

- Server handle creates listeners and reacts on incoming requests. [More on server transactions](#server-transaction)
- Client handle allows creating transaction requests [More on client transactions](#client-transaction)

Expand All @@ -63,7 +67,6 @@ conf := sipgo.GenerateTLSConfig(certFile, keyFile, rootPems)
srv.ListenAndServeTLS(ctx, "tcp", "127.0.0.1:5061", conf)
```


## Stateful Proxy build

Proxy is combination client and server handle that creates server/client transaction. They need to share
Expand Down Expand Up @@ -124,9 +127,15 @@ srv.OnACK(ackHandler)

### Client Transaction

**NOTE**: UA needs server handle and listener on same network before sending request

Using client handle allows easy creating and sending request. All you need is this.
```go
req := sip.NewRequest(sip.INVITE, recipient)
tx, err := client.TransactionRequest(req, opts...) // Send request and get client transaction handle
```
Unless you customize transaction request with opts by default `client.TransactionRequest` will build all other
headers needed to pass correct sip request.

Here is full example:
```go
client, _ := sipgo.NewClient(ua) // Creating client handle

Expand All @@ -146,6 +155,7 @@ select {
}

```
NOTE: If you are building UA that also has server handle on UDP. UDP listener will be reused to also send packets.

### Client stateless request

Expand All @@ -158,6 +168,8 @@ client.WriteRequest(req)

### Dialogs (experiment)

NOTE: This may be redesigned to have more control

`ServerDialog` is extended type of Server with Dialog support.
For now this is in experiment.

Expand Down Expand Up @@ -230,7 +242,7 @@ This unfortunately required many design changes, therefore this libraries are no

## Support

If you find this project interesting for support or contributing, you can contact me on
If you find this project interesting for bigger support or contributing, you can contact me on
[mail]([email protected])

For bugs features pls create [issue](https://github.com/emiago/sipgo/issues).
Expand Down
4 changes: 4 additions & 0 deletions ua.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,7 @@ func (ua *UserAgent) setIP(ip net.IP) (err error) {
func (ua *UserAgent) GetIP() net.IP {
return ua.ip
}

func (ua *UserAgent) TransportLayer() *transport.Layer {
return ua.tp
}

0 comments on commit 7474ae8

Please sign in to comment.