You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* add LiveKit section to configuration file to support video call or video meeting.
* chat supports video call now
* Add document "How to add REST RPC API"
OpenIM Chat server works with the OpenIM Server to offer the powerfull IM service. It has many REST APIs which are called by the OpenIM Server, works as an Application Server to fullfill your system demands.
5
+
6
+
You can add your business extensions to the OpenIM Chat server by adding REST APIs and let the OpenIM Server call these extend APIs to fulfill your system demands. The following will show you how to add a REST API for it.
7
+
8
+
## Protobuf source file modifications
9
+
10
+
First, your should add the REST API request and response message declarations, and RPC method declarations to the '.proto' protobuf source code, then call 'protoc' command to generate '.pb.go' go protobuf implementation codes.
11
+
12
+
For example, to add a REST API to generate login token for video meeting, you may want to add a request message named <fontcolor="#FF8000">GetTokenForVideoMeetingReq</font> and a response message named <fontcolor="#FF8000">GetTokenForVideoMeetingResp</font>. This can be done by adding this two messages to '/pkg/proto/chat/chat.proto'. You also should add a RPC method named <fontcolor="#FF8000">GetTokenForVideoMeeting()</font> fors the <fontcolor="#FF8000">chat</font> service.
Then, we start a terminal to run 'pkg/proto/gen.sh' shell script, which will call protoc command to regenerate chat.pb.go with protobuf implementation codes for your add messages.
47
+
48
+
49
+
## Add Check() method for the request message
50
+
</br>
51
+
52
+
To check the parameters in the request message, we should add a Check() method for newly added Request message. Take chat.proto as an example, we add the a Check() member method for GetTokenForVideoMeetingReq class in 'pkg/proto/chat/chat.go'.
For example, to add a REST API to generate login token for video meeting, you may want to add a RPC API named 'get_token', which is a member of the 'user' group, the REST URL can be '/user/rtc/get_token'.
73
+
74
+
This URL should be add to NewChatRoute() method in 'internal/api/router.go'.
user.POST("/update", chat.UpdateUserInfo) // Edit personal information
82
+
user.POST("/find/public", chat.FindUserPublicInfo) // Get user's public information
83
+
user.POST("/find/full", chat.FindUserFullInfo) // Get all information of the user
84
+
user.POST("/search/full", chat.SearchUserFullInfo) // Search user's public information
85
+
user.POST("/search/public", chat.SearchUserPublicInfo) // Search all information of the user
86
+
87
+
// your added code begins here
88
+
user.POST("/rtc/get_token", chat.GetTokenForVideoMeeting) // Get token for video meeting
89
+
90
+
...
91
+
}
92
+
```
93
+
94
+
## Implement the REST service
95
+
96
+
### Implement the REST Service Api
97
+
98
+
We add REST RPC API implementation to the corresponding service implementation go file located in '/internal/api/'. For the chat service, we add codes to '/internal/api/chat.go'.
a2r.Call(chat.ChatClient.GetTokenForVideoMeeting, o.chatClient, c)
105
+
}
106
+
...
107
+
```
108
+
109
+
### Implement the REST Service logic
110
+
111
+
We implement the REST Service logic in go files of the path '/internal/rpc/service_name/group_name.go'. For the user group of <fontcolor="#FF8000">chat</font> service, the implementation logic should be added to '/internal/rpc/chat/user.go'.
112
+
113
+
Here we call the GetLiveKitServerUrl() and GetLiveKitToken() func in the rtc package to allocate a new GetTokenForVideoMeetingResp message and return it to the RPC caller.
0 commit comments