47 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			47 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| // Package asChat -----------------------------
 | |
| // @file      : service.go
 | |
| // @author    : JJXu
 | |
| // @contact   : wavingbear@163.com
 | |
| // @time      : 2024/9/10 下午7:05
 | |
| // -------------------------------------------
 | |
| package asChat
 | |
| 
 | |
| import (
 | |
| 	"encoding/json"
 | |
| 	"fonchain-fiee/pkg/common/ws"
 | |
| )
 | |
| 
 | |
| func HandleMessage(sourceData []byte, cli *ws.Client) {
 | |
| 	var msg map[string]any
 | |
| 	err := json.Unmarshal(sourceData, &msg)
 | |
| 	if err != nil {
 | |
| 		cli.Send <- ws.WsErrorInvalidDataFormat(cli.ClientId)
 | |
| 		return
 | |
| 	}
 | |
| 	switch msg["type"] {
 | |
| 	default:
 | |
| 		cli.Send <- ws.WsErrorUnknownMessageType(cli.ClientId)
 | |
| 	case ws.TestType:
 | |
| 		var newMsg = ws.WsInfo{
 | |
| 			Type:    ws.TestType,
 | |
| 			Content: msg["content"],
 | |
| 		}
 | |
| 		byteMsg, _ := json.Marshal(newMsg)
 | |
| 		cli.Send <- byteMsg
 | |
| 		//case ws.ChatType:
 | |
| 		//	var chatInfo ChatInfo
 | |
| 		//	_ = json.Unmarshal(sourceData, &chatInfo)
 | |
| 		//	//解析Content
 | |
| 		//	if clients, ok := cli.Room.clients[chatInfo.Content.TargetUserId]; ok {
 | |
| 		//		for _, targetObj := range clients {
 | |
| 		//			if targetObj != nil {
 | |
| 		//				targetObj.Send <- WsChatMessage(msg.From, chatInfo.Content.TargetClientId, chatInfo.Content.Msg)
 | |
| 		//			}
 | |
| 		//		}
 | |
| 		//	} else {
 | |
| 		//		//对方不在线
 | |
| 		//		cli.Send <- WsErrorMessage(ChatType, msg.From, e.ErrTargetOutLine, nil)
 | |
| 		//	}
 | |
| 	}
 | |
| }
 |