Dyte client:
import requestsfrom requests.auth import HTTPBasicAuth from django.conf import settings from dj.apps.g12f.models import Creatorfrom .models import CreatorMeeting class DyteClient(object): def __init__(self, org): self.org = org def get_participants_count3(self, meeting_id) -> int: url = f"https://api.cluster.dyte.in/v2/meetings/{meeting_id}/participants" auth = HTTPBasicAuth(self.org, settings.DYTE_KEY) headers = { "Content-Type": "application/json", } response = requests.get(url, headers=headers, auth=auth) return response.json() def get_participants_count2(self, meeting_id) -> int: url = f"https://api.cluster.dyte.in/v2/meetings/{meeting_id}/active-session" auth = HTTPBasicAuth(self.org, settings.DYTE_KEY) headers = { "Content-Type": "application/json", } response = requests.get(url, headers=headers, auth=auth) return response.json().get("data", {}).get("total_participants", 0) def get_participants_count(self, meeting_id) -> int: url = f"https://api.cluster.dyte.in/v1/organizations/{self.org}/meetings/{meeting_id}/participants" headers = { "Content-Type": "application/json", "Authorization": settings.DYTE_KEY } response = requests.get(url, headers=headers) # print(response.json()) # print(len(response.json().get("data", {}).get("participants", []))) return len(response.json().get("data", {}).get("participants", [])) def is_live2(self, meeting_id) -> bool: # print(meeting_id) url = f"https://api.cluster.dyte.in/v2/meetings/{meeting_id}/active-livestream" # print(url) basic = HTTPBasicAuth(self.org, settings.DYTE_KEY) headers = { "Content-Type": "application/json", # "Authorization": "Basic undefined", # "Authorization": settings.DYTE_KEY, } response = requests.get(url, headers=headers, auth=basic) # print(response.json()) return response.json().get("success", False) def is_live(self, meeting_id) -> bool: url = f"https://api.cluster.dyte.in/v1/organizations/{self.org}/meetings/{meeting_id}" headers = { "Content-Type": "application/json", "Authorization": settings.DYTE_KEY, } resp = requests.get(url, headers=headers) # print(resp.json()) return resp.json().get( "data", {} ).get("meeting", {}).get("status", "") == "LIVE" def create_meeting(self, title) -> requests.Response: url = f"https://api.cluster.dyte.in/v1/organizations/{self.org}/meeting" payload = { "title": title, # "presetName": "string", "authorization": { # "waitingRoom": False, "closed": True, }, "recordOnStart": False, # ? "liveStreamOnStart": False } headers = { "Content-Type": "application/json", "Authorization": settings.DYTE_KEY, } response = requests.post( url, json=payload, headers=headers ) return response def add_participant(self, creator: Creator, meeting_id: str) -> requests.Response: # https://docs.dyte.io/api#/operations/add_participant url = f"https://api.cluster.dyte.in/v1/organizations/{self.org}/meetings/{meeting_id}/participant" cm = CreatorMeeting.objects.get(meeting_id=meeting_id) # TODO: experiment with presets if cm.creator.username == creator.username: preset = "webinar1" else: preset = "webinar-member" payload = { # this is required but not sure about it "clientSpecificId": creator.username, "userDetails": { "name": creator.username, # not allowed to be empty "picture": creator.get_thumbnail(), }, "presetName": preset, } headers = { "Content-Type": "application/json", "Authorization": settings.DYTE_KEY, } response = requests.post( url, json=payload, headers=headers) return response
I was using get_participants_count2 successfully for a while (you can see I've had to move to new ways once before)... I thought I would try to do a new way (the old way?) with get_participants_count3. But, the response from the call in 2 is now like:
{'success': True, 'data': {'id': '29ca222b-9512-40db-a1e5-f873a1c4e542', 'associated_id': '2d7cff9e-0ece-4280-922c-05d11913a9a9', 'type': 'meeting', 'meeting_display_name': 'free2z', 'status': 'LIVE', 'live_participants': 1, 'max_concurrent_participants': 1, 'recording_status': 'NOT_RECORDED', 'livestream_status': 'NOT_LIVESTREAMED', 'total_participants': 1, 'minutes_consumed': 1.239, 'organization_id': '7dba0970-3d0b-45e4-97dc-17029162fcc5', 'started_at': '2023-10-10T01:04:36.824Z', 'ended_at': None, 'created_at': '2023-10-10T01:04:36.892Z', 'updated_at': '2023-10-10T01:04:38.256Z', 'meta': {'room_name': 'ivnxhz-bikrde'}}}
The "live_participants" which I used use was stuck on 0 when it should be one ... and seems to be stuck on 1 if there is more than 1 ... I haven't figured it out but it used to give decent results and now it doesn't.
Working on get_participants_count3 I get
{'success': False, 'error': {'code': 404, 'message': 'No meeting found for meeting 2d7cff9e-0ece-4280-922c-05d11913a9a9 in organization 7dba0970-3d0b-45e4-97dc-17029162fcc5'}}
Even when I have a meeting going. What's a simple way to get a count of participants (including the host)?
