Skip to content

Commit 4be1866

Browse files
authored
Add video call support for open-im chat (#411)
* 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"
1 parent a030b8a commit 4be1866

File tree

16 files changed

+741
-242
lines changed

16 files changed

+741
-242
lines changed

HOW_TO_ADD_REST_RPC_API.md

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
# How to add REST RPC API for OpenIM Chat
2+
</br>
3+
4+
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 <font color="#FF8000">GetTokenForVideoMeetingReq</font> and a response message named <font color="#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 <font color="#FF8000">GetTokenForVideoMeeting()</font> fors the <font color="#FF8000">chat</font> service.
13+
14+
### chat.proto:
15+
16+
```proto
17+
syntax = "proto3";
18+
package OpenIMChat.chat;
19+
import "pub/wrapperspb.proto";
20+
import "pub/sdkws.proto";
21+
import "common/common.proto";
22+
option go_package = "github.com/OpenIMSDK/chat/pkg/proto/chat";
23+
24+
...
25+
26+
message GetTokenForVideoMeetingReq {
27+
string room = 1;
28+
string identity = 2;
29+
}
30+
31+
message GetTokenForVideoMeetingResp {
32+
string serverUrl = 1;
33+
string token = 2;
34+
}
35+
36+
service chat {
37+
...
38+
// Audio/video call and video meeting
39+
rpc GetTokenForVideoMeeting(GetTokenForVideoMeetingReq) returns (GetTokenForVideoMeetingResp);
40+
}
41+
```
42+
43+
## Generate protobuf implementations
44+
</br>
45+
46+
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'.
53+
54+
```go
55+
func (x *GetTokenForVideoMeetingReq) Check() error {
56+
if x.Room == "" {
57+
errs.ErrArgs.Wrap("Room is empty")
58+
}
59+
if x.Identity == "" {
60+
errs.ErrArgs.Wrap("User Identity is empty")
61+
}
62+
return nil
63+
}
64+
```
65+
66+
67+
## Add the URL for REST RPC API
68+
</br>
69+
70+
Now, we should add a URL for REST RPC API.
71+
72+
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'.
75+
76+
```go
77+
func NewChatRoute(router gin.IRouter, discov discoveryregistry.SvcDiscoveryRegistry) {
78+
...
79+
80+
user := router.Group("/user", mw.CheckToken)
81+
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'.
99+
100+
```go
101+
...
102+
func (o *ChatApi) GetTokenForVideoMeeting(c *gin.Context)
103+
{
104+
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 <font color="#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.
114+
115+
```go
116+
package chat
117+
118+
import (
119+
...
120+
"github.com/OpenIMSDK/chat/pkg/common/rtc"
121+
...
122+
)
123+
124+
...
125+
126+
func (o *chatSvr) GetTokenForVideoMeeting(ctx context.Context, req *chat.GetTokenForVideoMeetingReq) (*chat.GetTokenForVideoMeetingResp, error)
127+
{
128+
if _, _, err := mctx.Check(ctx); err != nil {
129+
return nil, err
130+
}
131+
serverUrl := rtc.GetLiveKitServerUrl()
132+
token, err := rtc.GetLiveKitToken(req.Room, req.Identity)
133+
if err != nil {
134+
return nil, err
135+
}
136+
return &chat.GetTokenForVideoMeetingResp{
137+
ServerUrl: serverUrl,
138+
Token: token,
139+
}, err
140+
}
141+
```
142+
143+
## Done
144+
145+
Now we have finished all the works to add an REST RPC API for OpenIM Chat. We may call
146+
147+
```shell
148+
make build
149+
```
150+
to re-compile the chat project and call
151+
152+
```shell
153+
make start
154+
```
155+
to start the OpenIM Chat server and test the <font color="#FF8000">chat</font> service's new REST RPC API.
156+
157+
###

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ $ make stop
184184
# OR use scripts stop
185185
$ ./scripts/stop_all.sh
186186
```
187+
## Add REST RPC API
188+
189+
Please refer to "[How to add REST RPC API for OpenIM Chat](./HOW_TO_ADD_REST_RPC_API.md)".
187190

188191
## Contributing
189192

deployments/templates/config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,9 @@ redis:
132132
address: [ 172.28.0.1:16379 ] # REDIS_ADDRESS and REDIS_PORT, Redis server address and port
133133
username: # REDIS_USERNAME, Username for Redis authentication
134134
password: openIM123 # REDIS_PASSWORD, Password for Redis
135+
136+
# LiveKit configuration - used for video and audio rtc
137+
liveKit:
138+
liveKitUrl: "ws://172.28.0.1:7880" # LIVEKIT_URL, LiveKit server address and port
139+
key: "APIDXJxJeCL8haY" # LIVEKIT_API_KEY
140+
secret: "ak1qulJ3nfXeflQHWBdmQDc4js4ueMc5OnxoORVJC2xA" # LIVEKIT_API_SECRET

go.mod

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ require (
2727
require (
2828
github.com/OpenIMSDK/protocol v0.0.21
2929
github.com/OpenIMSDK/tools v0.0.31
30+
github.com/livekit/protocol v1.5.0
3031
github.com/redis/go-redis/v9 v9.2.1
3132
github.com/xuri/excelize/v2 v2.8.0
3233
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
@@ -93,6 +94,7 @@ require (
9394
github.com/rs/xid v1.5.0 // indirect
9495
github.com/sirupsen/logrus v1.9.3 // indirect
9596
github.com/tjfoc/gmsm v1.3.2 // indirect
97+
github.com/twitchtv/twirp v8.1.3+incompatible // indirect
9698
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
9799
github.com/ugorji/go/codec v1.2.11 // indirect
98100
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
@@ -102,7 +104,7 @@ require (
102104
github.com/xuri/nfp v0.0.0-20230819163627-dc951e3ffe1a // indirect
103105
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
104106
go.mongodb.org/mongo-driver v1.12.0 // indirect
105-
go.uber.org/atomic v1.9.0 // indirect
107+
go.uber.org/atomic v1.10.0 // indirect
106108
go.uber.org/multierr v1.7.0 // indirect
107109
go.uber.org/zap v1.24.0 // indirect
108110
golang.org/x/arch v0.3.0 // indirect
@@ -115,4 +117,5 @@ require (
115117
google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 // indirect
116118
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
117119
gopkg.in/ini.v1 v1.67.0 // indirect
120+
gopkg.in/square/go-jose.v2 v2.6.0 // indirect
118121
)

go.sum

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ github.com/alibabacloud-go/tea-xml v1.1.2/go.mod h1:Rq08vgCcCAjHyRi/M7xlHKUykZCE
3535
github.com/aliyun/credentials-go v1.1.2 h1:qU1vwGIBb3UJ8BwunHDRFtAhS6jnQLnde/yk0+Ih2GY=
3636
github.com/aliyun/credentials-go v1.1.2/go.mod h1:ozcZaMR5kLM7pwtCMEpVmQ242suV6qTJya2bDq4X1Tw=
3737
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
38+
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
3839
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
3940
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
4041
github.com/bwmarrin/snowflake v0.3.0 h1:xm67bEhkKh6ij1790JB83OujPR5CzNe8QuQqAgISZN0=
@@ -58,19 +59,22 @@ github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/r
5859
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
5960
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
6061
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
62+
github.com/eapache/channels v1.1.0 h1:F1taHcn7/F0i8DYqKXJnyhJcVpp2kgFcNePxXtnyu4k=
6163
github.com/eapache/go-resiliency v1.4.0 h1:3OK9bWpPk5q6pbFAaYSEwD9CLUSHG8bnZuqX2yMt3B0=
6264
github.com/eapache/go-resiliency v1.4.0/go.mod h1:5yPzW0MIvSe0JDsv0v+DvcjEv2FyD6iZYSs1ZI+iQho=
6365
github.com/eapache/go-xerial-snappy v0.0.0-20230731223053-c322873962e3 h1:Oy0F4ALJ04o5Qqpdz8XLIpNA3WM/iSIXqxtqo7UGVws=
6466
github.com/eapache/go-xerial-snappy v0.0.0-20230731223053-c322873962e3/go.mod h1:YvSRo5mw33fLEx1+DlK6L2VV43tJt5Eyel9n9XBcR+0=
6567
github.com/eapache/queue v1.1.0 h1:YOEu7KNc61ntiQlcEeUIoDTJ2o8mQznoNvUhiigpIqc=
6668
github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I=
6769
github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw=
70+
github.com/frostbyte73/core v0.0.4 h1:CwwoYfKPdNSO/QbOOMWMRSYoNW14ov4XHnt094AuMX8=
6871
github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU=
6972
github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA=
7073
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
7174
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
7275
github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg=
7376
github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU=
77+
github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0=
7478
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
7579
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
7680
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
@@ -133,6 +137,7 @@ github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/
133137
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
134138
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
135139
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
140+
github.com/jxskiss/base62 v1.1.0 h1:A5zbF8v8WXx2xixnAKD2w+abC+sIzYJX+nxmhA6HWFw=
136141
github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
137142
github.com/klauspost/compress v1.17.4 h1:Ej5ixsIri7BrIjBkRZLTo6ghwrEtHFk7ijlczPW4fZ4=
138143
github.com/klauspost/compress v1.17.4/go.mod h1:/dCuZOvVtNoHsyb+cuJD3itjs3NbnF6KH9zAO4BDxPM=
@@ -154,8 +159,13 @@ github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible h1:Y6sqxHMyB1D2YSzWkL
154159
github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible/go.mod h1:ZQnN8lSECaebrkQytbHj4xNgtg8CR7RYXnPok8e0EHA=
155160
github.com/lestrrat-go/strftime v1.0.6 h1:CFGsDEt1pOpFNU+TJB0nhz9jl+K0hZSLE205AhTIGQQ=
156161
github.com/lestrrat-go/strftime v1.0.6/go.mod h1:f7jQKgV5nnJpYgdEasS+/y7EsTb8ykN2z68n3TtcTaw=
162+
github.com/lithammer/shortuuid/v4 v4.0.0 h1:QRbbVkfgNippHOS8PXDkti4NaWeyYfcBTHtw7k08o4c=
163+
github.com/livekit/protocol v1.5.0 h1:jFGSkSEv0PTjUlrW/WnmERejwxyHOSE9If4VU33PYgk=
164+
github.com/livekit/protocol v1.5.0/go.mod h1:hkK/G0wwFiLUGp9F5kxeQxq2CQuIzkmfBwKhTsc71us=
165+
github.com/mackerelio/go-osstat v0.2.3 h1:jAMXD5erlDE39kdX2CU7YwCGRcxIO33u/p8+Fhe5dJw=
157166
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
158167
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
168+
github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo=
159169
github.com/minio/md5-simd v1.1.2 h1:Gdi1DZK69+ZVMoNHRXJyNcxrMA4dSxoYHZSQbirFg34=
160170
github.com/minio/md5-simd v1.1.2/go.mod h1:MzdKDxYpY2BT9XQFocsiZf/NKVtR7nkE4RoEpN+20RM=
161171
github.com/minio/minio-go/v7 v7.0.66 h1:bnTOXOHjOqv/gcMuiVbN9o2ngRItvqE774dG9nq0Dzw=
@@ -185,6 +195,10 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
185195
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
186196
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
187197
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
198+
github.com/prometheus/client_golang v1.16.0 h1:yk/hx9hDbrGHovbci4BY+pRMfSuuat626eFsHb7tmT8=
199+
github.com/prometheus/client_model v0.3.0 h1:UBgGFHqYdG/TPFD1B1ogZywDqEkwp3fBMvqdiQ7Xew4=
200+
github.com/prometheus/common v0.42.0 h1:EKsfXEYo4JpWMHH5cg+KOUWeuJSov1Id8zGR8eeI1YM=
201+
github.com/prometheus/procfs v0.10.1 h1:kYK1Va/YMlutzCGazswoHKo//tZVlFpKYh+PymziUAg=
188202
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 h1:N/ElC8H3+5XpJzTSTfLsJV/mx9Q9g7kxmchpfZyxgzM=
189203
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
190204
github.com/redis/go-redis/v9 v9.2.1 h1:WlYJg71ODF0dVspZZCpYmoF1+U1Jjk9Rwd7pq6QmlCg=
@@ -219,6 +233,8 @@ github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXl
219233
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
220234
github.com/tjfoc/gmsm v1.3.2 h1:7JVkAn5bvUJ7HtU08iW6UiD+UTmJTIToHCfeFzkcCxM=
221235
github.com/tjfoc/gmsm v1.3.2/go.mod h1:HaUcFuY0auTiaHB9MHFGCPx5IaLhTUd2atbCFBQXn9w=
236+
github.com/twitchtv/twirp v8.1.3+incompatible h1:+F4TdErPgSUbMZMwp13Q/KgDVuI7HJXP61mNV3/7iuU=
237+
github.com/twitchtv/twirp v8.1.3+incompatible/go.mod h1:RRJoFSAmTEh2weEqWtpPE3vFK5YBhA6bqp2l1kfCC5A=
222238
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
223239
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
224240
github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
@@ -243,8 +259,8 @@ github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5t
243259
go.mongodb.org/mongo-driver v1.12.0 h1:aPx33jmn/rQuJXPQLZQ8NtfPQG8CaqgLThFtqRb0PiE=
244260
go.mongodb.org/mongo-driver v1.12.0/go.mod h1:AZkxhPnFJUoH7kZlFkVKucV20K387miPfm7oimrSmK0=
245261
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
246-
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
247-
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
262+
go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ=
263+
go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
248264
go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI=
249265
go.uber.org/multierr v1.7.0 h1:zaiO/rmgFjbmCXdSYJWQcdvOCsthmdaHfr3Gm2Kx4Ec=
250266
go.uber.org/multierr v1.7.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak=
@@ -354,6 +370,8 @@ gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df/go.mod h1:LRQQ+SO6ZHR7tOkp
354370
gopkg.in/ini.v1 v1.56.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
355371
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
356372
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
373+
gopkg.in/square/go-jose.v2 v2.6.0 h1:NGk74WTnPKBNUhNzQX7PYcTLUjoq7mzKk2OKbvwk2iI=
374+
gopkg.in/square/go-jose.v2 v2.6.0/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI=
357375
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
358376
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
359377
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

internal/api/chat.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,10 @@ func (o *ChatApi) SearchUserPublicInfo(c *gin.Context) {
263263
a2r.Call(chat.ChatClient.SearchUserPublicInfo, o.chatClient, c)
264264
}
265265

266+
func (o *ChatApi) GetTokenForVideoMeeting(c *gin.Context) {
267+
a2r.Call(chat.ChatClient.GetTokenForVideoMeeting, o.chatClient, c)
268+
}
269+
266270
// ################## APPLET ##################
267271

268272
func (o *ChatApi) FindApplet(c *gin.Context) {

internal/api/router.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,12 @@ func NewChatRoute(router gin.IRouter, discov discoveryregistry.SvcDiscoveryRegis
4848
account.POST("/password/change", mw.CheckToken, chat.ChangePassword) // Change password
4949

5050
user := router.Group("/user", mw.CheckToken)
51-
user.POST("/update", chat.UpdateUserInfo) // Edit personal information
52-
user.POST("/find/public", chat.FindUserPublicInfo) // Get user's public information
53-
user.POST("/find/full", chat.FindUserFullInfo) // Get all information of the user
54-
user.POST("/search/full", chat.SearchUserFullInfo) // Search user's public information
55-
user.POST("/search/public", chat.SearchUserPublicInfo) // Search all information of the user
51+
user.POST("/update", chat.UpdateUserInfo) // Edit personal information
52+
user.POST("/find/public", chat.FindUserPublicInfo) // Get user's public information
53+
user.POST("/find/full", chat.FindUserFullInfo) // Get all information of the user
54+
user.POST("/search/full", chat.SearchUserFullInfo) // Search user's public information
55+
user.POST("/search/public", chat.SearchUserPublicInfo) // Search all information of the user
56+
user.POST("/rtc/get_token", chat.GetTokenForVideoMeeting) // Get token for video meeting for the user
5657

5758
router.POST("/friend/search", mw.CheckToken, chat.SearchFriend)
5859

internal/rpc/chat/user.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"context"
1919
"github.com/OpenIMSDK/chat/pkg/common/db/dbutil"
2020
chat2 "github.com/OpenIMSDK/chat/pkg/common/db/table/chat"
21+
"github.com/OpenIMSDK/chat/pkg/common/rtc"
2122
constant2 "github.com/OpenIMSDK/protocol/constant"
2223
"github.com/OpenIMSDK/tools/mcontext"
2324
"time"
@@ -281,6 +282,21 @@ func (o *chatSvr) SearchUserInfo(ctx context.Context, req *chat.SearchUserInfoRe
281282
}, nil
282283
}
283284

285+
func (o *chatSvr) GetTokenForVideoMeeting(ctx context.Context, req *chat.GetTokenForVideoMeetingReq) (*chat.GetTokenForVideoMeetingResp, error) {
286+
if _, _, err := mctx.Check(ctx); err != nil {
287+
return nil, err
288+
}
289+
serverUrl := rtc.GetLiveKitServerUrl()
290+
token, err := rtc.GetLiveKitToken(req.Room, req.Identity)
291+
if err != nil {
292+
return nil, err
293+
}
294+
return &chat.GetTokenForVideoMeetingResp{
295+
ServerUrl: serverUrl,
296+
Token: token,
297+
}, err
298+
}
299+
284300
func (o *chatSvr) checkTheUniqueness(ctx context.Context, req *chat.AddUserAccountReq) error {
285301
if req.User.PhoneNumber != "" {
286302
_, err := o.Database.TakeAttributeByPhone(ctx, req.User.AreaCode, req.User.PhoneNumber)

pkg/common/config/config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ var Config struct {
5050
Username string `yaml:"username"`
5151
Password string `yaml:"password"`
5252
} `yaml:"redis"`
53+
LiveKit struct {
54+
LiveKitUrl string `yaml:"liveKitUrl"`
55+
Key string `yaml:"key"`
56+
Secret string `yaml:"secret"`
57+
} `yaml:"liveKit"`
5358
RpcPort struct {
5459
OpenImAdminPort []int `yaml:"openImAdminPort"`
5560
OpenImChatPort []int `yaml:"openImChatPort"`

pkg/common/config/im.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ var imConfig struct {
4242
Password string `yaml:"password"`
4343
} `yaml:"redis"`
4444

45+
LiveKit struct {
46+
LiveKitUrl string `yaml:"liveKitUrl"`
47+
Key string `yaml:"key"`
48+
Secret string `yaml:"secret"`
49+
} `yaml:"liveKit"`
50+
4551
Rpc struct {
4652
RegisterIP string `yaml:"registerIP"`
4753
ListenIP string `yaml:"listenIP"`

pkg/common/config/parse.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,10 @@ func configGetEnv() error {
259259
Config.Redis.Password = getEnv("REDIS_PASSWORD", Config.Redis.Password)
260260
Config.Redis.Address = getArrPointEnv("REDIS_ADDRESS", "REDIS_PORT", *Config.Redis.Address)
261261

262+
Config.LiveKit.LiveKitUrl = getEnv("LIVEKIT_URL", Config.LiveKit.LiveKitUrl)
263+
Config.LiveKit.Key = getEnv("LIVEKIT_API_KEY", Config.LiveKit.Key)
264+
Config.LiveKit.Secret = getEnv("LIVEKIT_API_SECRET", Config.LiveKit.Secret)
265+
262266
var err error
263267
Config.TokenPolicy.Expire, err = getEnvIntPoint("TOKEN_EXPIRE", Config.TokenPolicy.Expire)
264268
if err != nil {

0 commit comments

Comments
 (0)