You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
3.0 KiB

  1. import os
  2. import sys
  3. from collections import OrderedDict
  4. from .AccessToken import *
  5. Role_Attendee = 0 # depreated, same as publisher
  6. Role_Publisher = 1 # for live broadcaster
  7. Role_Subscriber = 2 # default, for live audience
  8. Role_Admin = 101 # deprecated, same as publisher
  9. class RtcTokenBuilder:
  10. # appID: The App ID issued to you by Agora. Apply for a new App ID from
  11. # Agora Dashboard if it is missing from your kit. See Get an App ID.
  12. # appCertificate: Certificate of the application that you registered in
  13. # the Agora Dashboard. See Get an App Certificate.
  14. # channelName:Unique channel name for the AgoraRTC session in the string format
  15. # uid: User ID. A 32-bit unsigned integer with a value ranging from
  16. # 1 to (232-1). optionalUid must be unique.
  17. # role: Role_Publisher = 1: A broadcaster (host) in a live-broadcast profile.
  18. # Role_Subscriber = 2: (Default) A audience in a live-broadcast profile.
  19. # privilegeExpireTs: represented by the number of seconds elapsed since
  20. # 1/1/1970. If, for example, you want to access the
  21. # Agora Service within 10 minutes after the token is
  22. # generated, set expireTimestamp as the current
  23. # timestamp + 600 (seconds)./
  24. @staticmethod
  25. def buildTokenWithUid(appId, appCertificate, channelName, uid, role, privilegeExpiredTs):
  26. return RtcTokenBuilder.buildTokenWithAccount(appId, appCertificate, channelName, uid, role, privilegeExpiredTs)
  27. # appID: The App ID issued to you by Agora. Apply for a new App ID from
  28. # Agora Dashboard if it is missing from your kit. See Get an App ID.
  29. # appCertificate: Certificate of the application that you registered in
  30. # the Agora Dashboard. See Get an App Certificate.
  31. # channelName:Unique channel name for the AgoraRTC session in the string format
  32. # userAccount: The user account.
  33. # role: Role_Publisher = 1: A broadcaster (host) in a live-broadcast profile.
  34. # Role_Subscriber = 2: (Default) A audience in a live-broadcast profile.
  35. # privilegeExpireTs: represented by the number of seconds elapsed since
  36. # 1/1/1970. If, for example, you want to access the
  37. # Agora Service within 10 minutes after the token is
  38. # generated, set expireTimestamp as the current
  39. @staticmethod
  40. def buildTokenWithAccount(appId, appCertificate, channelName, account, role, privilegeExpiredTs):
  41. token = AccessToken(appId, appCertificate, channelName, account)
  42. token.addPrivilege(kJoinChannel, privilegeExpiredTs)
  43. if (role == Role_Attendee) | (role == Role_Admin) | (role == Role_Publisher):
  44. token.addPrivilege(kPublishVideoStream, privilegeExpiredTs)
  45. token.addPrivilege(kPublishAudioStream, privilegeExpiredTs)
  46. token.addPrivilege(kPublishDataStream, privilegeExpiredTs)
  47. return token.build()