-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
Dev
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package api | ||
|
||
import socketio "github.com/googollee/go-socket.io" | ||
|
||
var distributor = make(map[string][]socketio.Socket) | ||
|
||
func AddSubscriber(name string, s socketio.Socket) { | ||
ss, ok := distributor[name] | ||
if !ok { | ||
distributor[name] = []socketio.Socket{s} | ||
} | ||
distributor[name] = append(ss, s) | ||
} | ||
|
||
func FindSocket(so socketio.Socket) (string, bool) { | ||
for name, ss := range distributor { | ||
for _, s := range ss { | ||
if s == so { | ||
return name, true | ||
} | ||
} | ||
} | ||
return "", false | ||
} | ||
func RemoveSubscriber(so socketio.Socket) { | ||
name, ok := FindSocket(so) | ||
if !ok { | ||
return | ||
} | ||
ss := distributor[name] | ||
ts := make([]socketio.Socket, len(ss)-1) | ||
j := 0 | ||
for _, v := range ss { | ||
if v == so { | ||
continue | ||
} | ||
ts[j] = v | ||
j++ | ||
} | ||
distributor[name] = ts | ||
} | ||
|
||
func Distribute(name string, log logBody) { | ||
ss, ok := distributor[name] | ||
if ok { | ||
for _, s := range ss { | ||
s.Emit("log:log", log) | ||
} | ||
} | ||
ss, ok = distributor["all"] | ||
if ok { | ||
for _, s := range ss { | ||
s.Emit("log:log", log) | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,13 +4,14 @@ | |
<meta charset="utf-8"> | ||
<title>Neo Log Monitor</title> | ||
<!-- Not present in the tutorial. Just for basic styling. --> | ||
<link rel="stylesheet" href="css/base.css" /> | ||
<link href="css/base.css" rel="stylesheet"/> | ||
<link href="node_modules/react-widgets/dist/css/react-widgets.css" rel="stylesheet"/> | ||
<script src="https://unpkg.com/[email protected]/dist/react.js"></script> | ||
<script src="https://unpkg.com/[email protected]/dist/react-dom.js"></script> | ||
<script src="https://unpkg.com/[email protected]/babel.min.js"></script> | ||
<script src="https://unpkg.com/[email protected]/dist/jquery.min.js"></script> | ||
<script src="https://unpkg.com/[email protected]/dist/remarkable.min.js"></script> | ||
<script src="https://cdn.socket.io/socket.io-1.2.1.js"></script> | ||
<script src="node_modules/react-widgets/dist/react-widgets.js"></script> | ||
</head> | ||
<body> | ||
<div id="content"></div> | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.