fac6e285bd
Stream statistics will now print when enabled in settings.json. There is messages in, messages out, and total time running. The main function was changed so the server setups for the main and rtmp are in separate functions, and both are started with their own goroutine. OS Interrupt catching was added, and if stream stats is true, the stats will be printed.
41 lines
704 B
Go
41 lines
704 B
Go
package main
|
|
|
|
import (
|
|
"net"
|
|
"sync"
|
|
|
|
"github.com/gorilla/websocket"
|
|
)
|
|
|
|
type chatConnection struct {
|
|
*websocket.Conn
|
|
mutex sync.Mutex
|
|
forwardedFor string
|
|
}
|
|
|
|
func (cc *chatConnection) ReadData(data interface{}) error {
|
|
defer cc.mutex.Unlock()
|
|
cc.mutex.Lock()
|
|
stats.msgInInc()
|
|
return cc.ReadJSON(data)
|
|
}
|
|
|
|
func (cc *chatConnection) WriteData(data interface{}) error {
|
|
defer cc.mutex.Unlock()
|
|
cc.mutex.Lock()
|
|
stats.msgOutInc()
|
|
return cc.WriteJSON(data)
|
|
}
|
|
|
|
func (cc *chatConnection) Host() string {
|
|
if len(cc.forwardedFor) > 0 {
|
|
return cc.forwardedFor
|
|
}
|
|
|
|
host, _, err := net.SplitHostPort(cc.RemoteAddr().String())
|
|
if err != nil {
|
|
return cc.RemoteAddr().String()
|
|
}
|
|
return host
|
|
}
|