首页 > 解决方案 > 如何在 Twilio 视频会议中启用录制?

问题描述

我在启用“RecordParticipantsOnConnect”时遇到问题,如此处所述:https : //www.twilio.com/docs/video/api/recordings-resource 在我的 twilio 实现中,但我似乎无法让它工作,我在哪里将 RecordParticipantsOnConnect 设置为 true?

他们说你在创建房间时需要传递这个选项,但我没有创建任何房间,它是自动完成的,我只是将房间名称作为字符串传递,我得到了令牌:

class TwilioServices
  ACCOUNT_SID     = ENV['TWILIO_ACCOUNT_SID']
  API_KEY_SID     = ENV['TWILIO_API_KEY_SID']
  API_KEY_SECRET  = ENV['TWILIO_API_KEY_SECRET']

  def self.get_token(type, room)
    # Create an Access Token
    token = Twilio::JWT::AccessToken.new ACCOUNT_SID, API_KEY_SID, API_KEY_SECRET, ttl: 7200, identity: type,

    # Grant access to Video
    grant = Twilio::JWT::AccessToken::VideoGrant.new
    grant.room = room
    token.add_grant grant
    # Serialize the token as a JWT
    token.to_jwt
  end
end

我该如何解决这个问题?

标签: ruby-on-railstwiliotwilio-api

解决方案


Twilio 开发人员布道者在这里。

如果您在加入时让 SDK 动态创建房间,那么您将无法在代码中设置录制标志。相反,您有两种选择:

  1. 您可以在 Twilio 控制台中配置您的房间默认设置。在这里,您可以将房间设置为默认分组房间并打开录制。(您无法录制点对点房间,因为媒体不通过 Twilio 服务器。)

  2. 您可以使用Video Rooms REST API 预先创建您的房间。自己创建房间时,还可以设置类型和是否录制。为此,您需要将get_token方法更新为:

    class TwilioServices
      ACCOUNT_SID     = ENV['TWILIO_ACCOUNT_SID']
      API_KEY_SID     = ENV['TWILIO_API_KEY_SID']
      API_KEY_SECRET  = ENV['TWILIO_API_KEY_SECRET']
    
      def self.get_token(type, room)
        # Create an Access Token
        token = Twilio::JWT::AccessToken.new ACCOUNT_SID, API_KEY_SID, API_KEY_SECRET, ttl: 7200, identity: type,
    
        client = Twilio::REST::Client.new(API_KEY_SID, API_KEY_SECRET, ACCOUNT_SID)
        video_room = client.video.rooms.create(
          unique_name: room,
          record_participants_on_connect: true,
          type: 'group'
        )
    
        # Grant access to Video
        grant = Twilio::JWT::AccessToken::VideoGrant.new
        grant.room = room
        token.add_grant grant
        # Serialize the token as a JWT
        token.to_jwt
      end
    end
    

让我知道这是否有帮助。


推荐阅读