| Home | Trees | Indices | Help |
|
|---|
|
|
1 print('****************************************************************************');
2 print('SkypeKit Python Wrapper Tutorial: Making outgoing (conference) calls');
3 print('****************************************************************************');
4
5 # This example demonstrates, how to:
6 # 1. Make outgoing (multi-target) calls.
7 # 2. Catch voice activity events during calls.
8
9 # NB! You will need to launch the SkypeKit runtime before running this example.
10
11 #----------------------------------------------------------------------------------
12 # Importing necessary libraries. Note that you will need to set the keyFileName value
13 # in the keypair.py file.
14
15 import sys;
16 import keypair;
17 from time import sleep;
18
19 sys.path.append(keypair.distroRoot + '/ipc/python');
20 sys.path.append(keypair.distroRoot + '/interfaces/skype/python');
21
22 try:
23 import Skype;
24 except ImportError:
25 raise SystemExit('Program requires Skype and skypekit modules');
26
27 #----------------------------------------------------------------------------------
28 # Taking skypename and password arguments from command-line.
29
30 if len(sys.argv) < 4:
31 print('Usage: python autoanswer.py <skypename> <password> <call target>');
32 sys.exit();
33
34 accountName = sys.argv[1];
35 accountPsw = sys.argv[2];
36
37 # Collecting call target list from command-line arguments.
38 # 3rd and subsequent arguments are our call targets.
39 callTargets = [];
40 for i in range(3, len(sys.argv)):
41 callTargets.append(sys.argv[i]);
42
43 loggedIn = False;
44 isCallFinished = False;
45
46 #----------------------------------------------------------------------------------
47 # Defining our own Account property change callback and assigning it to the
48 # SkyLib.Account class.
49
51 global loggedIn;
52 if property_name == 'status':
53 if self.status == 'LOGGED_IN':
54 loggedIn = True;
55 print('Login complete.');
56
57 Skype.Account.OnPropertyChange = AccountOnChange;
58
59 Skype.isLiveSessionUp = False;
60 Skype.liveSession = 0;
61
62 #----------------------------------------------------------------------------------
63 # Defining our own Participant property change callback
64 # Unlike with incoming calls - we can assume that we already have the Conversation
65 # object - as we retrieved it ourselves when initiating the call. This makes our life
66 # much easier. So much so that we can make do without any Conversation callback
67 # at all and put all our logic into Participant class.
68 #
69 # We can use the self.voice_status == 'SPEAKING' property change to detect when
70 # any given participant reached live status and 'VOICE_STOPPED' for detecting when
71 # they left the call.
72 #
73 # When the self.voice_status == 'VOICE_STOPPED' fires for ourselves - the call has
74 # ended. Note that in case of conference call, the rest of the participants will
75 # drop too - when the conference host (us) went non-live.
76
78 if property_name == 'voice_status':
79
80 # It makes sense to only display 'joined call' and 'left call'
81 # feedback messages for people other than ourselves.
82 if self.identity != accountName:
83 if self.voice_status == 'SPEAKING':
84 print(self.identity + ' has joined the call.');
85
86 if self.voice_status == 'VOICE_STOPPED':
87 print(self.identity + ' has left the call.');
88
89 if (self.identity == accountName) and (self.voice_status == 'VOICE_STOPPED'):
90 global isCallFinished;
91 isCallFinished = True;
92
93 # This property enables you to have neat voice activity indicators in your UI.
94 if property_name == 'sound_level':
95 print(self.identity + ' sound level: ' + str(self.sound_level));
96
97 Skype.Participant.OnPropertyChange = ParticipantOnChange;
98
99
100 #----------------------------------------------------------------------------------
101 # Creating our main Skype object
102
103 try:
104 MySkype = Skype.GetSkype(keypair.keyFileName);
105 MySkype.Start();
106 except Exception:
107 raise SystemExit('Unable to create Skype instance');
108
109 #----------------------------------------------------------------------------------
110 # Retrieving account and logging in with it. Then waiting in loop.
111
112 account = MySkype.GetAccount(accountName);
113
114 print('Logging in with ' + accountName);
115 account.LoginWithPassword(accountPsw, False, False);
116
117 while loggedIn == False:
118 sleep(1);
119
120 liveConversation = MySkype.GetConversationByParticipants(callTargets, True, False);
121
122 # We need the Participant list to get Participant property change events firing.
123 # If we don't have the participant objects - no events for us.
124 callParticipants = liveConversation.GetParticipants('ALL');
125
126 # ..but as we already need to have this list, we might as well use it for feedback.
127 if len(callParticipants) > 0:
128 for P in callParticipants:
129 if P.identity != accountName:
130 print('Calling ' + P.identity + '..');
131
132 isCallFinished = False;
133 liveConversation.RingOthers(callTargets, False, '');
134
135 print('Press ENTER to finish the call and exit.');
136 raw_input('');
137
138 # Checking if the call was already finished (because of other participants dropping
139 # or whether we will need to drop the call ourselves. Going offline without properly
140 # shutting down the live session can cause confusion to remote clients.
141 if not isCallFinished:
142 liveConversation.LeaveLiveSession(False);
143 while not isCallFinished:
144 sleep(1);
145
146 print('The call has ended.');
147 print('Exiting..');
148 MySkype.stop();
149
| Home | Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Fri Mar 16 16:40:40 2012 | http://epydoc.sourceforge.net |