ThinkCats / rim

im server based on tokio-ws and rocket , writing in rust
MIT License
41 stars 3 forks source link
im rust
# rim ![GitHub branch checks state](https://img.shields.io/github/checks-status/ThinkCats/rim/master) ![GitHub](https://img.shields.io/github/license/ThinkCats/rim) [![996.icu](https://img.shields.io/badge/link-996.icu-red.svg)](https://996.icu)

rim 是一个使用rust编写的im服务端。 English

前端展示

rim-front , 使用react编写,仅做演示用.

功能列表

demo 视频

video

😄好友关系前端暂未实现

rest api 文档

api doc

websocket 消息体协议

struct

Msg Struct

#[derive(Serialize, Deserialize, Clone)]
pub struct MsgEvent {
    //event: Login,Msg,Read,Heart,Logout,Ack
    pub event: EventType,
    pub body: MsgBody,
}

MsgBody

#[derive(Serialize, Deserialize, Clone)]
pub struct MsgBody {
     //message type: Text,RichText,Image...
    pub kind: MessageType,
    pub uid: u64,
    pub gid: Option<u64>,
    pub content: String,
    #[serde(rename(serialize = "clientMsgId", deserialize = "clientMsgId"))]
    pub client_msg_id: String,
    #[serde(rename(serialize = "msgId", deserialize = "msgId"))]
    pub msg_id: Option<u64>,
}

Server Ack

#[derive(Serialize, Deserialize)]
pub struct MsgAck {
    #[serde(rename(serialize = "clientMsgId", deserialize = "clientMsgId"))]
    pub client_msg_id: String,
    #[serde(rename(serialize = "serverMsgId", deserialize = "serverMsgId"))]
    pub server_msg_id: Option<u64>,
    pub kind: EventType,
    pub content: String,
}

msg example

  1. Login message
    {
    "event": "Login",
    "body": {
        "kind": "Text",
        "content": "d5219358-f96b-4bfc-8672-d01ba95d16fa",
        "uid": 1,
        "clientMsgId": "72aebfd4aeef7634"
    }
    }

server ack:

{
    "clientMsgId": "72aebfd4aeef7634",
    "serverMsgId": null,
    "kind": "Ack",
    "content": "Ok"
}
  1. Msg message
{
    "event": "Msg",
    "body": {
        "kind": "Text",
        "content": "Hello World",
        "uid": 1,
        "gid": 1,
        "clientMsgId": "badc6d33aebfd40ab3cda"
    }
}

server ack:

{
    "clientMsgId": "badc6d33aebfd40ab3cda",
    "serverMsgId": 28,
    "kind": "Ack",
    "content": "Ok"
}

client msg body is same as server msg body

  1. Logout message
    {
    "event": "Logout",
    "body": {
        "kind": "Text",
        "content": "", //empty string
        "uid": 1,
        "clientMsgId": "72aebfd4aeef7634"
    }
    }

server ack:

{
    "clientMsgId": "72aebfd4aeef7634",
    "serverMsgId": null,
    "kind": "Ack",
    "content": "Ok"
}
  1. client ack message
    {
    "event": "Ack",
    "body": {
        "kind": "Text",
        "content": "", 
        "uid": 2,
        "gid": 3,
        "clientMsgId": "72aebfd4aeefaaa",
        "msgId": 29
    }
    }

server ack:

{
    "clientMsgId": "72aebfd4aeefaaa",
    "serverMsgId": null,
    "kind": "Ack",
    "content": "Ok"
}
  1. client read message
    {
    "event": "Read",
    "body": {
        "kind": "Text",
        "content": "", 
        "uid": 2,
        "gid": 3,
        "clientMsgId": "72aebfd4aeefaaa",
        "msgId": 29
    }
    }

    server ack:

    {
    "clientMsgId": "72aebfd4aeefaaa",
    "serverMsgId": 29,
    "kind": "Ack",
    "content": "Ok"
    }