Skip to content

Commit

Permalink
Merge branch 'master' of github.com:tomochain/tomox-sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
thanhson1085 committed Jun 9, 2020
2 parents 36f4bda + 0b7649f commit 5fc5d88
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 26 deletions.
4 changes: 2 additions & 2 deletions ws/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
)

const (
writeWait = 60 * time.Second
pongWait = 60 * time.Second
writeWait = 30 * time.Second
pongWait = 30 * time.Second
pingPeriod = (pongWait * 9) / 10
)

Expand Down
11 changes: 8 additions & 3 deletions ws/lending_markets.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,16 @@ func (s *LendingMarketsSocket) Unsubscribe(c *Client) {
}
}

// BroadcastMessage streams message to all the subscriptions subscribed to the pair
func (s *LendingMarketsSocket) BroadcastMessage(channelID string, p interface{}) error {
func (s *LendingMarketsSocket) getSubscriptions() map[string]map[*Client]bool {
s.subsMutex.RLock()
defer s.subsMutex.RUnlock()
for c, status := range s.subscriptions[channelID] {
return s.subscriptions
}

// BroadcastMessage streams message to all the subscriptions subscribed to the pair
func (s *LendingMarketsSocket) BroadcastMessage(channelID string, p interface{}) error {
subs := s.getSubscriptions()
for c, status := range subs[channelID] {
if status {
s.SendUpdateMessage(c, p)
}
Expand Down
11 changes: 8 additions & 3 deletions ws/lending_orderbook.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,16 @@ func (s *LendingOrderBookSocket) Unsubscribe(c *Client) {
}
}

// BroadcastMessage streams message to all the subscribtions subscribed to the pair
func (s *LendingOrderBookSocket) BroadcastMessage(channelID string, p interface{}) error {
func (s *LendingOrderBookSocket) getSubscriptions() map[string]map[*Client]bool {
s.subsMutex.RLock()
defer s.subsMutex.RUnlock()
for c, status := range s.subscriptions[channelID] {
return s.subscriptions
}

// BroadcastMessage streams message to all the subscribtions subscribed to the pair
func (s *LendingOrderBookSocket) BroadcastMessage(channelID string, p interface{}) error {
subs := s.getSubscriptions()
for c, status := range subs[channelID] {
if status {
s.SendUpdateMessage(c, p)
}
Expand Down
11 changes: 8 additions & 3 deletions ws/lending_priceboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,16 @@ func (s *LendingPriceBoardSocket) Unsubscribe(c *Client) {
}
}

// BroadcastMessage streams message to all the subscriptions subscribed to the pair
func (s *LendingPriceBoardSocket) BroadcastMessage(channelID string, p interface{}) error {
func (s *LendingPriceBoardSocket) getSubscriptions() map[string]map[*Client]bool {
s.subsMutex.RLock()
defer s.subsMutex.RUnlock()
for c, status := range s.subscriptions[channelID] {
return s.subscriptions
}

// BroadcastMessage streams message to all the subscriptions subscribed to the pair
func (s *LendingPriceBoardSocket) BroadcastMessage(channelID string, p interface{}) error {
subs := s.getSubscriptions()
for c, status := range subs[channelID] {
if status {
s.SendUpdateMessage(c, p)
}
Expand Down
11 changes: 8 additions & 3 deletions ws/lending_trade.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,17 @@ func (s *LendingTradeSocket) Unsubscribe(c *Client) {
}
}

func (s *LendingTradeSocket) getSubscriptions() map[string]map[*Client]bool {
s.subsMutex.RLock()
defer s.subsMutex.RUnlock()
return lendingTradeSocket.subscriptions
}

// BroadcastMessage broadcasts trade message to all subscribed sockets
func (s *LendingTradeSocket) BroadcastMessage(channelID string, p interface{}) {
go func() {
s.subsMutex.RLock()
defer s.subsMutex.RUnlock()
for conn, active := range lendingTradeSocket.subscriptions[channelID] {
subs := s.getSubscriptions()
for conn, active := range subs[channelID] {
if active {
s.SendUpdateMessage(conn, p)
}
Expand Down
11 changes: 8 additions & 3 deletions ws/markets.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,16 @@ func (s *MarketsSocket) Unsubscribe(c *Client) {
}
}

// BroadcastMessage streams message to all the subscriptions subscribed to the pair
func (s *MarketsSocket) BroadcastMessage(channelID string, p interface{}) error {
func (s *MarketsSocket) getSubscriptions() map[string]map[*Client]bool {
s.subsMutex.RLock()
defer s.subsMutex.RUnlock()
for c, status := range s.subscriptions[channelID] {
return s.subscriptions
}

// BroadcastMessage streams message to all the subscriptions subscribed to the pair
func (s *MarketsSocket) BroadcastMessage(channelID string, p interface{}) error {
subs := s.getSubscriptions()
for c, status := range subs[channelID] {
if status {
s.SendUpdateMessage(c, p)
}
Expand Down
11 changes: 8 additions & 3 deletions ws/orderbook.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,16 @@ func (s *OrderBookSocket) Unsubscribe(c *Client) {
}
}

// BroadcastMessage streams message to all the subscribtions subscribed to the pair
func (s *OrderBookSocket) BroadcastMessage(channelID string, p interface{}) error {
func (s *OrderBookSocket) getSubscriptions() map[string]map[*Client]bool {
s.subsMutex.RLock()
defer s.subsMutex.RUnlock()
for c, status := range s.subscriptions[channelID] {
return s.subscriptions
}

// BroadcastMessage streams message to all the subscribtions subscribed to the pair
func (s *OrderBookSocket) BroadcastMessage(channelID string, p interface{}) error {
subs := s.getSubscriptions()
for c, status := range subs[channelID] {
if status {
s.SendUpdateMessage(c, p)
}
Expand Down
11 changes: 8 additions & 3 deletions ws/price_board.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,16 @@ func (s *PriceBoardSocket) Unsubscribe(c *Client) {
}
}

// BroadcastMessage streams message to all the subscriptions subscribed to the pair
func (s *PriceBoardSocket) BroadcastMessage(channelID string, p interface{}) error {
func (s *PriceBoardSocket) getSubscriptions() map[string]map[*Client]bool {
s.subsMutex.RLock()
defer s.subsMutex.RUnlock()
for c, status := range s.subscriptions[channelID] {
return s.subscriptions
}

// BroadcastMessage streams message to all the subscriptions subscribed to the pair
func (s *PriceBoardSocket) BroadcastMessage(channelID string, p interface{}) error {
subs := s.getSubscriptions()
for c, status := range subs[channelID] {
if status {
s.SendUpdateMessage(c, p)
}
Expand Down
11 changes: 8 additions & 3 deletions ws/trades.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,17 @@ func (s *TradeSocket) Unsubscribe(c *Client) {
}
}

func (s *TradeSocket) getSubscriptions() map[string]map[*Client]bool {
s.subsMutex.RLock()
defer s.subsMutex.RUnlock()
return tradeSocket.subscriptions
}

// BroadcastMessage broadcasts trade message to all subscribed sockets
func (s *TradeSocket) BroadcastMessage(channelID string, p interface{}) {
go func() {
s.subsMutex.RLock()
defer s.subsMutex.RUnlock()
for conn, active := range tradeSocket.subscriptions[channelID] {
subs := s.getSubscriptions()
for conn, active := range subs[channelID] {
if active {
s.SendUpdateMessage(conn, p)
}
Expand Down

0 comments on commit 5fc5d88

Please sign in to comment.