This repository was archived by the owner on Dec 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
158 lines (131 loc) · 4.7 KB
/
main.py
File metadata and controls
158 lines (131 loc) · 4.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import sys
import pyVideoSDK
from pyVideoSDK.methods import Methods
from pyVideoSDK.consts import EVENT, METHOD_RESPONSE
import pyVideoSDK.consts as C
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
import screeninfo
import wstyle
# ========================
# Configuration
# ========================
ROOM_IP: str = "127.0.0.1"
ROOM_PORT: int = 2233
PIN: str = "123"
MINMAX_APPLICATION: bool = True
CALL_ID: str = "echotest_es@trueconf.com"
# ========================
TITLE: str = "Button Video Calling Demo"
BUTTON_WIDTH: int = 160
BUTTON_HEIGHT: int = 90
INDENT: int = 100
MONITOR: int = 0
IMAGE_BUTTON: str = "call.png"
ICON_SIZE: int = 64
sdk = pyVideoSDK.open_session(ip=ROOM_IP, port=ROOM_PORT, pin=PIN, debug=False)
methods = Methods(sdk)
class KioskButton(QWidget):
def __init__(self, monitor: int):
super().__init__()
self.layout = None
self.room = None
self.displayName = ""
self.buttonCall = None
self.buttonCallTag = False
if monitor >= len(screeninfo.get_monitors()) or monitor < 0:
monitor = 0
self.monitor = screeninfo.get_monitors()[monitor]
self.state = 0
self.initUI()
def initUI(self):
# Setting layout
self.layout = QVBoxLayout(self)
# Position
self.setPosition()
self.setWindowTitle(TITLE)
# Frameless window
self.setWindowFlags(Qt.WindowStaysOnTopHint
| Qt.X11BypassWindowManagerHint | Qt.FramelessWindowHint | Qt.Dialog)
self.setAttribute(Qt.WA_NoSystemBackground)
self.setAttribute(Qt.WA_TranslucentBackground)
# Show
self.show()
# connectToRoom
self.connectToRoom()
# Button
self.buttonCall = self.createCallButton(
style=wstyle.STYLE_GRAY_BUTTON, icon=IMAGE_BUTTON)
# flashing timer
self.timer = QTimer(self, interval=500)
self.timer.timeout.connect(self.flashing)
self.timer.start()
def createCallButton(self, style: str, icon: str) -> object:
button = QPushButton()
button.setStyleSheet(style)
button.setFixedWidth(BUTTON_WIDTH)
button.setFixedHeight(BUTTON_HEIGHT)
button.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
self.layout.addWidget(button)
self.layout.setAlignment(button, Qt.AlignRight | Qt.AlignBottom)
if icon:
button.setIcon(QIcon(icon))
button.setIconSize(QSize(ICON_SIZE, ICON_SIZE))
button.clicked.connect(self.on_click_call)
return button
def setPosition(self):
# calc window size & position
leftCoord: int = self.monitor.x + self.monitor.width - BUTTON_WIDTH - INDENT
topCoord: int = self.monitor.y + self.monitor.height - BUTTON_HEIGHT - INDENT
# set position
self.setGeometry(leftCoord, topCoord, BUTTON_WIDTH, BUTTON_HEIGHT)
def flashing(self):
if self.state == 3:
if self.buttonCallTag:
self.buttonCall.setStyleSheet(wstyle.STYLE_GREEN_BUTTON_FLASH)
else:
self.buttonCall.setStyleSheet(wstyle.STYLE_GREEN_BUTTON)
self.buttonCallTag = not self.buttonCallTag
def connectToRoom(self):
pass
def on_state_change(self, response):
# Get the current state
self.state = response["appState"]
# Set button color according to status
if self.state == 3:
style = wstyle.STYLE_GREEN_BUTTON
elif self.state in [4, 5]:
style = wstyle.STYLE_RED_BUTTON
else:
style = wstyle.STYLE_GRAY_BUTTON
self.buttonCall.setStyleSheet(style)
if MINMAX_APPLICATION:
if self.state in [4, 5]:
methods.showMainWindow(True, False) # Maximized
else:
methods.showMainWindow(False) # Minimized, Hiden
@pyqtSlot()
def on_click_call(self):
self.displayName = self.sender().text
if self.state == 3:
# Calling
methods.call(CALL_ID)
elif self.state in [4, 5]:
# Hang up
methods.hangUp(True)
else:
print("Warning. Please check connection.")
@sdk.handler(EVENT[C.EV_rejectReceived])
def on_reject_received(response):
print(C.CAUSE[response["cause"]])
if __name__ == '__main__':
app = QApplication(sys.argv)
call_button = KioskButton(MONITOR)
# Add handlers
sdk.add_handler(EVENT[C.EV_appStateChanged], call_button.on_state_change)
sdk.add_handler(METHOD_RESPONSE[C.M_getAppState],
call_button.on_state_change)
# Request the current state
methods.getAppState()
sys.exit(app.exec_())