This repository has been archived by the owner on Mar 21, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1449 from Bytom/dev
Dev
- Loading branch information
Showing
62 changed files
with
8,346 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package api | ||
|
||
import ( | ||
"net/http" | ||
"time" | ||
|
||
log "github.com/sirupsen/logrus" | ||
|
||
"github.com/bytom/net/websocket" | ||
) | ||
|
||
// timeZeroVal is simply the zero value for a time.Time and is used to avoid | ||
// creating multiple instances. | ||
var timeZeroVal time.Time | ||
|
||
// WebsocketHandler handles connections and requests from websocket client | ||
func (a *API) websocketHandler(w http.ResponseWriter, r *http.Request) { | ||
log.WithField("remoteAddress", r.RemoteAddr).Info("New websocket client") | ||
|
||
client, err := websocket.NewWebsocketClient(w, r, a.notificationMgr) | ||
if err != nil { | ||
log.WithField("error", err).Error("Failed to new websocket client") | ||
http.Error(w, "400 Bad Request.", http.StatusBadRequest) | ||
return | ||
} | ||
|
||
a.notificationMgr.AddClient(client) | ||
client.Start() | ||
client.WaitForShutdown() | ||
a.notificationMgr.RemoveClient(client) | ||
log.WithField("address", r.RemoteAddr).Infoln("Disconnected websocket client") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.