import gi
gi.require_version("Gtk", "4.0")
from gi.repository import GLib, Gtk
import cairo
from daily import *
class DailyGtkApp(Gtk.Application):
def __init__(self, meeting_url, participant_id, save_audio, screen_share):
super().__init__(application_id="co.daily.DailyGtkApp")
self.__client = CallClient()
# Configure subscription profiles
self.__client.update_subscription_profiles({
"base": {
"microphone": "subscribed",
"camera": "unsubscribed" if screen_share else "subscribed",
"screenVideo": "subscribed" if screen_share else "unsubscribed",
}
})
self.__video_source = "screenVideo" if screen_share else "camera"
def join(self, meeting_url, participant_id):
if self.__save_audio:
self.__client.set_audio_renderer(
participant_id,
self.on_audio_data
)
self.__client.set_video_renderer(
participant_id,
self.on_video_frame,
video_source=self.__video_source,
color_format="BGRA"
)
self.__client.join(meeting_url, completion=self.on_joined)
def on_video_frame(self, participant_id, video_frame, video_source):
self.__frame_width = video_frame.width
self.__frame_height = video_frame.height
self.__frame = video_frame
self.__drawing_area.queue_draw()
def drawing_area_draw(self, area, context, w, h, data):
if self.__joined and self.__frame is not None:
image = bytearray(self.__frame.buffer)
width = self.__frame_width
height = self.__frame_height
stride = cairo.ImageSurface.format_stride_for_width(
cairo.FORMAT_ARGB32, width
)
cairo_surface = cairo.ImageSurface.create_for_data(
image, cairo.FORMAT_ARGB32, width, height, stride
)
# Scale to fit window
width_ratio = float(self.__width) / float(width)
height_ratio = float(self.__height) / float(height)
scale_xy = min(height_ratio, width_ratio)
context.scale(scale_xy, scale_xy)
context.set_source_surface(cairo_surface)
context.paint()