TrueConf SDK for Windows use case in Python
This example demonstrates basic operations with the component:
- How to create ActiveX and bind Python functions to events.
- How to connect and authorize on TrueConf Server.
- How to select equipment: camera, microphone, speakers.
- How to receive incoming calls.
- How to receive incoming chat messages.
This example uses 32-bit Python v. 3.6.7. Bit count is critically important.
Additional
You will need Qt5 module.
Here is its installation command:
1 |
pip install pyqt5 |
Indicate the following values:
1 2 3 4 5 6 |
... # connection parameters: server, user_id (TrueConf ID), password SERVER = '-server IP-' USER = '-trueconf id-' PASSWORD = '-password-' ... |
Source code
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 |
# coding=utf8 from PyQt5.QAxContainer import QAxWidget from PyQt5.QtWidgets import QApplication, QWidget, QHBoxLayout from PyQt5.QtCore import QObject import sys # window title TITLE = "CallX Python Example: accept any calls" # Component’s GUID ActiveX TrueConfCallX_Class = '{27EF4BA2-4500-4839-B88A-F2F4744FE56A}' # connection parameters: server, user_id (TrueConf ID), password SERVER = '-server IP-' USER = '-trueconf id-' PASSWORD = '-password-' # main window class class CallXWindow(QWidget): def __init__(self): QAxWidget.__init__(self) self.initUI() def initUI(self): self.setWindowTitle(TITLE) # layout self.layout = QHBoxLayout(self) self.setLayout(self.layout) # CallX self.axwin = ActiveXExtend(self) self.layout.addWidget(self.axwin.ocx) # end of class CallXWindow(QWidget) # container class for ActiveX class ActiveXExtend(QObject): def __init__(self, view: CallXWindow): super().__init__() self.view = view # Create "TrueConf SDK for Windows" component aka CallX self.ocx = QAxWidget(TrueConfCallX_Class) # ===================================================================== # bind certain ActiveX events of the CallX component # ===================================================================== # Event No 1: indicates if the component initialization has been completed. # This event shows if CallX is ready for operation self.ocx.OnXAfterStart.connect(self._OnXAfterStart) # Connect to the server self.ocx.OnServerConnected[str].connect(self._OnServerConnected) # Authorize with login and password self.ocx.OnLogin[str].connect(self._OnLogin) # Call alert # This event handler encapsulates logic # Accept or decline incoming call or conference invitation self.ocx.OnInviteReceived[str].connect(self._OnInviteReceived) # Error message self.ocx.OnXError[int, str].connect(self._OnXError) # Authorization error self.ocx.OnXLoginError[int].connect(self._OnXLoginError) # Incoming message is received in chat self.ocx.OnIncomingChatMessage[str, str, str, 'qulonglong'].connect(self._OnIncomingChatMessage) # Events def _OnXAfterStart(self): print("**OnXAfterStart") # Select device: simply choose the first ones in the list of equipment self.ocx.XSetCameraByIndex(0) self.ocx.XSelectMicByIndex(0) self.ocx.XSelectSpeakerByIndex(0) # Connect to server self.ocx.connectToServer(SERVER) def _OnServerConnected(self, eventDetails): print("**OnServerConnected") print(eventDetails) # Authorize self.ocx.login(USER, PASSWORD) def _OnLogin(self, eventDetails): print("**OnLogin") def _OnInviteReceived(self, eventDetails): print("**OnInviteReceived") print(eventDetails) # Accept the call self.ocx.accept() def _OnXError(self, errorCode, errorMsg): print("**OnXError") print('{}. Code: {}'.format(errorMsg, errorCode)) def _OnXLoginError(self, errorCode): print("**OnXLoginError") if errorCode == 8: print('Support for SDK Applications is not enabled on this server') else: print('Login error. Code: {}'.format(errorCode)) def _OnIncomingChatMessage(self, peerId, peerDn, message, time): print("**OnIncomingChatMessage") print('From userID "{}" Display name "{}": "{}"'.format(peerId, peerDn, message)) # end of class ActiveXExtend(QObject) if __name__ == '__main__': app = QApplication(sys.argv) MainWindow = CallXWindow() MainWindow.show() sys.exit(app.exec_()) |