-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
298 additions
and
27 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,65 @@ | ||
package controllers | ||
|
||
import ( | ||
"github.com/goravel/framework/contracts/http" | ||
"github.com/okami-chen/goravel-websocket/servers" | ||
) | ||
|
||
func (r *WebsocketController) BindToGroup(ctx http.Context) http.Response { | ||
|
||
validator, err := ctx.Request().Validate(map[string]string{ | ||
"clientId": "required", | ||
"userId": "required", | ||
"groupName": "required", | ||
"systemId": "required", | ||
}) | ||
|
||
if err != nil { | ||
return ctx.Response().Success().Json(http.Json{ | ||
"code": 500, | ||
"msg": err.Error(), | ||
"data": []string{}, | ||
}) | ||
} | ||
|
||
if validator.Fails() { | ||
return ctx.Response().Success().Json(http.Json{ | ||
"code": 500, | ||
"msg": validator.Errors().One(), | ||
"data": []string{}, | ||
}) | ||
} | ||
userId := ctx.Request().Input("userId") | ||
groupName := ctx.Request().Input("groupName") | ||
systemId := ctx.Request().Input("systemId") | ||
if userId != "" { | ||
clients, e := servers.Manager.GetByUserId(userId) | ||
if e != nil { | ||
return ctx.Response().Success().Json(http.Json{ | ||
"code": 404, | ||
"msg": "client not found", | ||
"data": []string{}, | ||
}) | ||
} | ||
|
||
for _, client := range clients { | ||
servers.AddClient2Group(systemId, groupName, client.ClientId, client.UserId, "") | ||
} | ||
} else { | ||
client, err := servers.Manager.GetByClientId(ctx.Request().Input("clientId")) | ||
if err != nil { | ||
return ctx.Response().Success().Json(http.Json{ | ||
"code": 404, | ||
"msg": "client not found", | ||
"data": []string{}, | ||
}) | ||
} | ||
servers.AddClient2Group(systemId, groupName, client.ClientId, client.UserId, "") | ||
} | ||
|
||
return ctx.Response().Success().Json(http.Json{ | ||
"code": 0, | ||
"msg": "success", | ||
"data": []string{}, | ||
}) | ||
} |
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,41 @@ | ||
package controllers | ||
|
||
import ( | ||
"github.com/goravel/framework/contracts/http" | ||
"github.com/okami-chen/goravel-websocket/servers" | ||
) | ||
|
||
func (r *WebsocketController) CloseClient(ctx http.Context) http.Response { | ||
|
||
validator, err := ctx.Request().Validate(map[string]string{ | ||
"systemId": "required", | ||
"clientId": "required", | ||
}) | ||
|
||
if err != nil { | ||
return ctx.Response().Success().Json(http.Json{ | ||
"code": 500, | ||
"msg": err.Error(), | ||
"data": []string{}, | ||
}) | ||
} | ||
|
||
if validator.Fails() { | ||
return ctx.Response().Success().Json(http.Json{ | ||
"code": 500, | ||
"msg": validator.Errors().One(), | ||
"data": []string{}, | ||
}) | ||
} | ||
|
||
systemId := ctx.Request().Input("systemId") | ||
clientId := ctx.Request().Input("clientId") | ||
|
||
servers.CloseClient(clientId, systemId) | ||
|
||
return ctx.Response().Success().Json(http.Json{ | ||
"code": 0, | ||
"msg": "success", | ||
"data": []string{clientId}, | ||
}) | ||
} |
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,55 @@ | ||
package controllers | ||
|
||
import ( | ||
"github.com/goravel/framework/contracts/http" | ||
"github.com/okami-chen/goravel-websocket/servers" | ||
) | ||
|
||
func (r *WebsocketController) KickUser(ctx http.Context) http.Response { | ||
|
||
validator, err := ctx.Request().Validate(map[string]string{ | ||
"userId": "required", | ||
"systemId": "required", | ||
}) | ||
|
||
if err != nil { | ||
return ctx.Response().Success().Json(http.Json{ | ||
"code": 500, | ||
"msg": err.Error(), | ||
"data": []string{}, | ||
}) | ||
} | ||
|
||
if validator.Fails() { | ||
return ctx.Response().Success().Json(http.Json{ | ||
"code": 500, | ||
"msg": validator.Errors().One(), | ||
"data": []string{}, | ||
}) | ||
} | ||
|
||
systemId := ctx.Request().Input("systemId") | ||
userId := ctx.Request().Input("userId") | ||
|
||
client, err := servers.Manager.GetByUserId(userId) | ||
|
||
if err != nil { | ||
return ctx.Response().Success().Json(http.Json{ | ||
"code": 500, | ||
"msg": err.Error(), | ||
"data": []string{}, | ||
}) | ||
} | ||
|
||
var ids []string | ||
for _, c := range client { | ||
servers.CloseClient(c.ClientId, systemId) | ||
ids = append(ids, c.ClientId) | ||
} | ||
|
||
return ctx.Response().Success().Json(http.Json{ | ||
"code": 0, | ||
"msg": "success", | ||
"data": ids, | ||
}) | ||
} |
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,39 @@ | ||
package controllers | ||
|
||
import ( | ||
"github.com/goravel/framework/contracts/http" | ||
"github.com/okami-chen/goravel-websocket/servers" | ||
) | ||
|
||
func (r *WebsocketController) OnelineList(ctx http.Context) http.Response { | ||
|
||
validator, err := ctx.Request().Validate(map[string]string{ | ||
"systemId": "required", | ||
"groupName": "required", | ||
}) | ||
|
||
if err != nil { | ||
return ctx.Response().Success().Json(http.Json{ | ||
"code": 500, | ||
"msg": err.Error(), | ||
"data": []string{}, | ||
}) | ||
} | ||
|
||
if validator.Fails() { | ||
return ctx.Response().Success().Json(http.Json{ | ||
"code": 500, | ||
"msg": validator.Errors().One(), | ||
"data": []string{}, | ||
}) | ||
} | ||
|
||
systemId := ctx.Request().Input("systemId") | ||
groupName := ctx.Request().Input("groupName") | ||
|
||
return ctx.Response().Success().Json(http.Json{ | ||
"code": 0, | ||
"msg": "success", | ||
"data": servers.GetOnlineList(&systemId, &groupName), | ||
}) | ||
} |
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,49 @@ | ||
package controllers | ||
|
||
import ( | ||
"github.com/goravel/framework/contracts/http" | ||
"github.com/okami-chen/goravel-websocket/servers" | ||
) | ||
|
||
func (r *WebsocketController) SendToGroup(ctx http.Context) http.Response { | ||
|
||
validator, err := ctx.Request().Validate(map[string]string{ | ||
"systemId": "required", | ||
"groupName": "required", | ||
"sendUserId": "required", | ||
"code": "required", | ||
"msg": "required", | ||
"data": "required", | ||
}) | ||
|
||
if err != nil { | ||
return ctx.Response().Success().Json(http.Json{ | ||
"code": 500, | ||
"msg": err.Error(), | ||
"data": []string{}, | ||
}) | ||
} | ||
|
||
if validator.Fails() { | ||
return ctx.Response().Success().Json(http.Json{ | ||
"code": 500, | ||
"msg": validator.Errors().One(), | ||
"data": []string{}, | ||
}) | ||
} | ||
|
||
systemId := ctx.Request().Input("systemId") | ||
sendUserId := ctx.Request().Input("sendUserId") | ||
groupName := ctx.Request().Input("groupName") | ||
code := ctx.Request().InputInt("code") | ||
msg := ctx.Request().Input("msg") | ||
data := ctx.Request().Input("data") | ||
|
||
messageId := servers.SendMessage2Group(systemId, sendUserId, groupName, code, msg, &data) | ||
|
||
return ctx.Response().Success().Json(http.Json{ | ||
"code": 0, | ||
"msg": "success", | ||
"data": []string{messageId}, | ||
}) | ||
} |
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