Skip to content

Commit

Permalink
Add video call support for open-im chat (#411)
Browse files Browse the repository at this point in the history
* 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"
  • Loading branch information
DanGiant authored Feb 27, 2024
1 parent a030b8a commit 4be1866
Show file tree
Hide file tree
Showing 16 changed files with 741 additions and 242 deletions.
157 changes: 157 additions & 0 deletions HOW_TO_ADD_REST_RPC_API.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
# How to add REST RPC API for OpenIM Chat
</br>

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.

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.

## Protobuf source file modifications

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.

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.

### chat.proto:

```proto
syntax = "proto3";
package OpenIMChat.chat;
import "pub/wrapperspb.proto";
import "pub/sdkws.proto";
import "common/common.proto";
option go_package = "github.com/OpenIMSDK/chat/pkg/proto/chat";
...
message GetTokenForVideoMeetingReq {
string room = 1;
string identity = 2;
}
message GetTokenForVideoMeetingResp {
string serverUrl = 1;
string token = 2;
}
service chat {
...
// Audio/video call and video meeting
rpc GetTokenForVideoMeeting(GetTokenForVideoMeetingReq) returns (GetTokenForVideoMeetingResp);
}
```

## Generate protobuf implementations
</br>

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.


## Add Check() method for the request message
</br>

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'.

```go
func (x *GetTokenForVideoMeetingReq) Check() error {
if x.Room == "" {
errs.ErrArgs.Wrap("Room is empty")
}
if x.Identity == "" {
errs.ErrArgs.Wrap("User Identity is empty")
}
return nil
}
```


## Add the URL for REST RPC API
</br>

Now, we should add a URL for REST RPC API.

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'.

This URL should be add to NewChatRoute() method in 'internal/api/router.go'.

```go
func NewChatRoute(router gin.IRouter, discov discoveryregistry.SvcDiscoveryRegistry) {
...

user := router.Group("/user", mw.CheckToken)
user.POST("/update", chat.UpdateUserInfo) // Edit personal information
user.POST("/find/public", chat.FindUserPublicInfo) // Get user's public information
user.POST("/find/full", chat.FindUserFullInfo) // Get all information of the user
user.POST("/search/full", chat.SearchUserFullInfo) // Search user's public information
user.POST("/search/public", chat.SearchUserPublicInfo) // Search all information of the user

// your added code begins here
user.POST("/rtc/get_token", chat.GetTokenForVideoMeeting) // Get token for video meeting

...
}
```

## Implement the REST service

### Implement the REST Service Api

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'.

```go
...
func (o *ChatApi) GetTokenForVideoMeeting(c *gin.Context)
{
a2r.Call(chat.ChatClient.GetTokenForVideoMeeting, o.chatClient, c)
}
...
```

### Implement the REST Service logic

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'.

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.

```go
package chat

import (
...
"github.com/OpenIMSDK/chat/pkg/common/rtc"
...
)

...

func (o *chatSvr) GetTokenForVideoMeeting(ctx context.Context, req *chat.GetTokenForVideoMeetingReq) (*chat.GetTokenForVideoMeetingResp, error)
{
if _, _, err := mctx.Check(ctx); err != nil {
return nil, err
}
serverUrl := rtc.GetLiveKitServerUrl()
token, err := rtc.GetLiveKitToken(req.Room, req.Identity)
if err != nil {
return nil, err
}
return &chat.GetTokenForVideoMeetingResp{
ServerUrl: serverUrl,
Token: token,
}, err
}
```

## Done

Now we have finished all the works to add an REST RPC API for OpenIM Chat. We may call

```shell
make build
```
to re-compile the chat project and call

```shell
make start
```
to start the OpenIM Chat server and test the <font color="#FF8000">chat</font> service's new REST RPC API.

###
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ $ make stop
# OR use scripts stop
$ ./scripts/stop_all.sh
```
## Add REST RPC API

Please refer to "[How to add REST RPC API for OpenIM Chat](./HOW_TO_ADD_REST_RPC_API.md)".

## Contributing

Expand Down
6 changes: 6 additions & 0 deletions deployments/templates/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,9 @@ redis:
address: [ 172.28.0.1:16379 ] # REDIS_ADDRESS and REDIS_PORT, Redis server address and port
username: # REDIS_USERNAME, Username for Redis authentication
password: openIM123 # REDIS_PASSWORD, Password for Redis

# LiveKit configuration - used for video and audio rtc
liveKit:
liveKitUrl: "ws://172.28.0.1:7880" # LIVEKIT_URL, LiveKit server address and port
key: "APIDXJxJeCL8haY" # LIVEKIT_API_KEY
secret: "ak1qulJ3nfXeflQHWBdmQDc4js4ueMc5OnxoORVJC2xA" # LIVEKIT_API_SECRET
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ require (
require (
github.com/OpenIMSDK/protocol v0.0.21
github.com/OpenIMSDK/tools v0.0.31
github.com/livekit/protocol v1.5.0
github.com/redis/go-redis/v9 v9.2.1
github.com/xuri/excelize/v2 v2.8.0
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
Expand Down Expand Up @@ -93,6 +94,7 @@ require (
github.com/rs/xid v1.5.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/tjfoc/gmsm v1.3.2 // indirect
github.com/twitchtv/twirp v8.1.3+incompatible // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
Expand All @@ -102,7 +104,7 @@ require (
github.com/xuri/nfp v0.0.0-20230819163627-dc951e3ffe1a // indirect
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
go.mongodb.org/mongo-driver v1.12.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.7.0 // indirect
go.uber.org/zap v1.24.0 // indirect
golang.org/x/arch v0.3.0 // indirect
Expand All @@ -115,4 +117,5 @@ require (
google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 // indirect
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/square/go-jose.v2 v2.6.0 // indirect
)
22 changes: 20 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ github.com/alibabacloud-go/tea-xml v1.1.2/go.mod h1:Rq08vgCcCAjHyRi/M7xlHKUykZCE
github.com/aliyun/credentials-go v1.1.2 h1:qU1vwGIBb3UJ8BwunHDRFtAhS6jnQLnde/yk0+Ih2GY=
github.com/aliyun/credentials-go v1.1.2/go.mod h1:ozcZaMR5kLM7pwtCMEpVmQ242suV6qTJya2bDq4X1Tw=
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
github.com/bwmarrin/snowflake v0.3.0 h1:xm67bEhkKh6ij1790JB83OujPR5CzNe8QuQqAgISZN0=
Expand All @@ -58,19 +59,22 @@ github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/r
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/eapache/channels v1.1.0 h1:F1taHcn7/F0i8DYqKXJnyhJcVpp2kgFcNePxXtnyu4k=
github.com/eapache/go-resiliency v1.4.0 h1:3OK9bWpPk5q6pbFAaYSEwD9CLUSHG8bnZuqX2yMt3B0=
github.com/eapache/go-resiliency v1.4.0/go.mod h1:5yPzW0MIvSe0JDsv0v+DvcjEv2FyD6iZYSs1ZI+iQho=
github.com/eapache/go-xerial-snappy v0.0.0-20230731223053-c322873962e3 h1:Oy0F4ALJ04o5Qqpdz8XLIpNA3WM/iSIXqxtqo7UGVws=
github.com/eapache/go-xerial-snappy v0.0.0-20230731223053-c322873962e3/go.mod h1:YvSRo5mw33fLEx1+DlK6L2VV43tJt5Eyel9n9XBcR+0=
github.com/eapache/queue v1.1.0 h1:YOEu7KNc61ntiQlcEeUIoDTJ2o8mQznoNvUhiigpIqc=
github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I=
github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw=
github.com/frostbyte73/core v0.0.4 h1:CwwoYfKPdNSO/QbOOMWMRSYoNW14ov4XHnt094AuMX8=
github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU=
github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg=
github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU=
github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0=
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
Expand Down Expand Up @@ -133,6 +137,7 @@ github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/jxskiss/base62 v1.1.0 h1:A5zbF8v8WXx2xixnAKD2w+abC+sIzYJX+nxmhA6HWFw=
github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
github.com/klauspost/compress v1.17.4 h1:Ej5ixsIri7BrIjBkRZLTo6ghwrEtHFk7ijlczPW4fZ4=
github.com/klauspost/compress v1.17.4/go.mod h1:/dCuZOvVtNoHsyb+cuJD3itjs3NbnF6KH9zAO4BDxPM=
Expand All @@ -154,8 +159,13 @@ github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible h1:Y6sqxHMyB1D2YSzWkL
github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible/go.mod h1:ZQnN8lSECaebrkQytbHj4xNgtg8CR7RYXnPok8e0EHA=
github.com/lestrrat-go/strftime v1.0.6 h1:CFGsDEt1pOpFNU+TJB0nhz9jl+K0hZSLE205AhTIGQQ=
github.com/lestrrat-go/strftime v1.0.6/go.mod h1:f7jQKgV5nnJpYgdEasS+/y7EsTb8ykN2z68n3TtcTaw=
github.com/lithammer/shortuuid/v4 v4.0.0 h1:QRbbVkfgNippHOS8PXDkti4NaWeyYfcBTHtw7k08o4c=
github.com/livekit/protocol v1.5.0 h1:jFGSkSEv0PTjUlrW/WnmERejwxyHOSE9If4VU33PYgk=
github.com/livekit/protocol v1.5.0/go.mod h1:hkK/G0wwFiLUGp9F5kxeQxq2CQuIzkmfBwKhTsc71us=
github.com/mackerelio/go-osstat v0.2.3 h1:jAMXD5erlDE39kdX2CU7YwCGRcxIO33u/p8+Fhe5dJw=
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo=
github.com/minio/md5-simd v1.1.2 h1:Gdi1DZK69+ZVMoNHRXJyNcxrMA4dSxoYHZSQbirFg34=
github.com/minio/md5-simd v1.1.2/go.mod h1:MzdKDxYpY2BT9XQFocsiZf/NKVtR7nkE4RoEpN+20RM=
github.com/minio/minio-go/v7 v7.0.66 h1:bnTOXOHjOqv/gcMuiVbN9o2ngRItvqE774dG9nq0Dzw=
Expand Down Expand Up @@ -185,6 +195,10 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_golang v1.16.0 h1:yk/hx9hDbrGHovbci4BY+pRMfSuuat626eFsHb7tmT8=
github.com/prometheus/client_model v0.3.0 h1:UBgGFHqYdG/TPFD1B1ogZywDqEkwp3fBMvqdiQ7Xew4=
github.com/prometheus/common v0.42.0 h1:EKsfXEYo4JpWMHH5cg+KOUWeuJSov1Id8zGR8eeI1YM=
github.com/prometheus/procfs v0.10.1 h1:kYK1Va/YMlutzCGazswoHKo//tZVlFpKYh+PymziUAg=
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 h1:N/ElC8H3+5XpJzTSTfLsJV/mx9Q9g7kxmchpfZyxgzM=
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
github.com/redis/go-redis/v9 v9.2.1 h1:WlYJg71ODF0dVspZZCpYmoF1+U1Jjk9Rwd7pq6QmlCg=
Expand Down Expand Up @@ -219,6 +233,8 @@ github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXl
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/tjfoc/gmsm v1.3.2 h1:7JVkAn5bvUJ7HtU08iW6UiD+UTmJTIToHCfeFzkcCxM=
github.com/tjfoc/gmsm v1.3.2/go.mod h1:HaUcFuY0auTiaHB9MHFGCPx5IaLhTUd2atbCFBQXn9w=
github.com/twitchtv/twirp v8.1.3+incompatible h1:+F4TdErPgSUbMZMwp13Q/KgDVuI7HJXP61mNV3/7iuU=
github.com/twitchtv/twirp v8.1.3+incompatible/go.mod h1:RRJoFSAmTEh2weEqWtpPE3vFK5YBhA6bqp2l1kfCC5A=
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
Expand All @@ -243,8 +259,8 @@ github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5t
go.mongodb.org/mongo-driver v1.12.0 h1:aPx33jmn/rQuJXPQLZQ8NtfPQG8CaqgLThFtqRb0PiE=
go.mongodb.org/mongo-driver v1.12.0/go.mod h1:AZkxhPnFJUoH7kZlFkVKucV20K387miPfm7oimrSmK0=
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ=
go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI=
go.uber.org/multierr v1.7.0 h1:zaiO/rmgFjbmCXdSYJWQcdvOCsthmdaHfr3Gm2Kx4Ec=
go.uber.org/multierr v1.7.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak=
Expand Down Expand Up @@ -354,6 +370,8 @@ gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df/go.mod h1:LRQQ+SO6ZHR7tOkp
gopkg.in/ini.v1 v1.56.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/square/go-jose.v2 v2.6.0 h1:NGk74WTnPKBNUhNzQX7PYcTLUjoq7mzKk2OKbvwk2iI=
gopkg.in/square/go-jose.v2 v2.6.0/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down
4 changes: 4 additions & 0 deletions internal/api/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,10 @@ func (o *ChatApi) SearchUserPublicInfo(c *gin.Context) {
a2r.Call(chat.ChatClient.SearchUserPublicInfo, o.chatClient, c)
}

func (o *ChatApi) GetTokenForVideoMeeting(c *gin.Context) {
a2r.Call(chat.ChatClient.GetTokenForVideoMeeting, o.chatClient, c)
}

// ################## APPLET ##################

func (o *ChatApi) FindApplet(c *gin.Context) {
Expand Down
11 changes: 6 additions & 5 deletions internal/api/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ func NewChatRoute(router gin.IRouter, discov discoveryregistry.SvcDiscoveryRegis
account.POST("/password/change", mw.CheckToken, chat.ChangePassword) // Change password

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

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

Expand Down
16 changes: 16 additions & 0 deletions internal/rpc/chat/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"github.com/OpenIMSDK/chat/pkg/common/db/dbutil"
chat2 "github.com/OpenIMSDK/chat/pkg/common/db/table/chat"
"github.com/OpenIMSDK/chat/pkg/common/rtc"
constant2 "github.com/OpenIMSDK/protocol/constant"
"github.com/OpenIMSDK/tools/mcontext"
"time"
Expand Down Expand Up @@ -281,6 +282,21 @@ func (o *chatSvr) SearchUserInfo(ctx context.Context, req *chat.SearchUserInfoRe
}, nil
}

func (o *chatSvr) GetTokenForVideoMeeting(ctx context.Context, req *chat.GetTokenForVideoMeetingReq) (*chat.GetTokenForVideoMeetingResp, error) {
if _, _, err := mctx.Check(ctx); err != nil {
return nil, err
}
serverUrl := rtc.GetLiveKitServerUrl()
token, err := rtc.GetLiveKitToken(req.Room, req.Identity)
if err != nil {
return nil, err
}
return &chat.GetTokenForVideoMeetingResp{
ServerUrl: serverUrl,
Token: token,
}, err
}

func (o *chatSvr) checkTheUniqueness(ctx context.Context, req *chat.AddUserAccountReq) error {
if req.User.PhoneNumber != "" {
_, err := o.Database.TakeAttributeByPhone(ctx, req.User.AreaCode, req.User.PhoneNumber)
Expand Down
5 changes: 5 additions & 0 deletions pkg/common/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ var Config struct {
Username string `yaml:"username"`
Password string `yaml:"password"`
} `yaml:"redis"`
LiveKit struct {
LiveKitUrl string `yaml:"liveKitUrl"`
Key string `yaml:"key"`
Secret string `yaml:"secret"`
} `yaml:"liveKit"`
RpcPort struct {
OpenImAdminPort []int `yaml:"openImAdminPort"`
OpenImChatPort []int `yaml:"openImChatPort"`
Expand Down
6 changes: 6 additions & 0 deletions pkg/common/config/im.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ var imConfig struct {
Password string `yaml:"password"`
} `yaml:"redis"`

LiveKit struct {
LiveKitUrl string `yaml:"liveKitUrl"`
Key string `yaml:"key"`
Secret string `yaml:"secret"`
} `yaml:"liveKit"`

Rpc struct {
RegisterIP string `yaml:"registerIP"`
ListenIP string `yaml:"listenIP"`
Expand Down
4 changes: 4 additions & 0 deletions pkg/common/config/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ func configGetEnv() error {
Config.Redis.Password = getEnv("REDIS_PASSWORD", Config.Redis.Password)
Config.Redis.Address = getArrPointEnv("REDIS_ADDRESS", "REDIS_PORT", *Config.Redis.Address)

Config.LiveKit.LiveKitUrl = getEnv("LIVEKIT_URL", Config.LiveKit.LiveKitUrl)
Config.LiveKit.Key = getEnv("LIVEKIT_API_KEY", Config.LiveKit.Key)
Config.LiveKit.Secret = getEnv("LIVEKIT_API_SECRET", Config.LiveKit.Secret)

var err error
Config.TokenPolicy.Expire, err = getEnvIntPoint("TOKEN_EXPIRE", Config.TokenPolicy.Expire)
if err != nil {
Expand Down
Loading

0 comments on commit 4be1866

Please sign in to comment.