feat: add client call feature switches
This commit is contained in:
@@ -20,6 +20,8 @@ const (
|
||||
imReasonCallNotFound = "CALL_NOT_FOUND"
|
||||
imReasonCallNotAllowed = "CALL_NOT_ALLOWED"
|
||||
imReasonCallStateInvalid = "CALL_STATE_INVALID"
|
||||
|
||||
imClientFeatureConfigGroup = "im_client_feature"
|
||||
)
|
||||
|
||||
type imCallRTCJoinRequest struct {
|
||||
@@ -189,6 +191,46 @@ func loadIMAgoraConfig() (imAgoraConfig, error) {
|
||||
return config, nil
|
||||
}
|
||||
|
||||
func imCallFeatureFlags() (bool, bool) {
|
||||
runtimeEnabled := imCallRuntimeEnabled()
|
||||
if !runtimeEnabled || store.ThirdPartyConfig == nil {
|
||||
return false, false
|
||||
}
|
||||
values, err := store.ThirdPartyConfig.Get(imClientFeatureConfigGroup, "audio_call_enabled", "video_call_enabled")
|
||||
if err != nil {
|
||||
return false, false
|
||||
}
|
||||
return imTruthy(values["audio_call_enabled"]), imTruthy(values["video_call_enabled"])
|
||||
}
|
||||
|
||||
func imCallRuntimeEnabled() bool {
|
||||
webrtcEnabled := len(globals.iceServers) > 0
|
||||
agoraEnabled := false
|
||||
if config, err := loadIMAgoraConfig(); err == nil {
|
||||
agoraEnabled = config.Enabled
|
||||
}
|
||||
return webrtcEnabled || agoraEnabled
|
||||
}
|
||||
|
||||
func imCallFeatureEnabled() bool {
|
||||
audioCall, videoCall := imCallFeatureFlags()
|
||||
return audioCall || videoCall
|
||||
}
|
||||
|
||||
func imCallTimeoutSeconds() int {
|
||||
if globals.callEstablishmentTimeout > 0 {
|
||||
return globals.callEstablishmentTimeout
|
||||
}
|
||||
if imCallFeatureEnabled() {
|
||||
return defaultCallEstablishmentTimeout
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func imCanCall(allowed bool) bool {
|
||||
return allowed && imCallFeatureEnabled()
|
||||
}
|
||||
|
||||
func findCallRecordForRTCJoin(tenantID types.TenantID, uid types.Uid, body imCallRTCJoinRequest) (*types.CallRecord, error) {
|
||||
if store.Calls == nil {
|
||||
return nil, types.ErrUnsupported
|
||||
|
||||
Reference in New Issue
Block a user