Package Skype4Py :: Module call
[frames] | no frames]

Source Code for Module Skype4Py.call

  1  '''Calls, conferences. 
  2  ''' 
  3   
  4  from utils import * 
  5  from enums import * 
  6   
  7   
8 -class ICall(Cached):
9 '''Represents a voice/video call. 10 ''' 11
12 - def __repr__(self):
13 return '<%s with Id=%s>' % (Cached.__repr__(self)[1:-1], repr(self.Id))
14
15 - def _Alter(self, AlterName, Args=None):
16 return self._Skype._Alter('CALL', self._Id, AlterName, Args)
17
18 - def _Init(self, Id, Skype):
19 self._Skype = Skype 20 self._Id = int(Id)
21
22 - def _Property(self, PropName, Set=None, Cache=True):
23 return self._Skype._Property('CALL', self._Id, PropName, Set, Cache)
24
25 - def Answer(self):
26 '''Answers the call. 27 ''' 28 self._Property('STATUS', 'INPROGRESS')
29
30 - def CanTransfer(self, Target):
31 '''Queries if a call can be transferred to a contact or phone number. 32 33 @param Target: Skypename or phone number the call is to be transfered to. 34 @type Target: unicode 35 @return: True if call can be transfered, False otherwise. 36 @rtype: bool 37 ''' 38 return self._Property('CAN_TRANSFER %s' % Target) == 'TRUE'
39
40 - def CaptureMicDevice(self, DeviceType=None, Set=None):
41 '''Queries or sets the mic capture device. 42 43 @param DeviceType: Mic capture device type or None. 44 @type DeviceType: L{Call IO device type<enums.callIoDeviceTypeUnknown>} or None 45 @param Set: Value the device should be set to or None. 46 @type Set: unicode, int or None 47 @return: If DeviceType and Set are None, returns a dictionary of device types and their 48 values. Dictionary contains only those device types, whose values were set. If the 49 DeviceType is not None but Set is None, returns the current value of the device or 50 None if the device wasn't set. If Set is not None, sets a new value for the device. 51 @rtype: unicode, dict or None 52 53 @note: This command functions for active calls only. 54 ''' 55 if Set == None: # get 56 args = args2dict(self._Property('CAPTURE_MIC', Cache=False)) 57 for t in args: 58 if t == callIoDeviceTypePort: 59 args[t] = int(args[t]) 60 if DeviceType == None: # get active devices 61 return args 62 return args.get(DeviceType, None) 63 elif DeviceType != None: # set 64 self._Alter('SET_CAPTURE_MIC', '%s=%s' % (DeviceType, quote(unicode(Set), True))) 65 else: 66 raise TypeError('DeviceType must be specified if Set is used')
67
68 - def Finish(self):
69 '''Ends the call. 70 ''' 71 self._Property('STATUS', 'FINISHED')
72
73 - def Forward(self):
74 '''Forwards a call. 75 ''' 76 self._Alter('END', 'FORWARD_CALL')
77
78 - def Hold(self):
79 '''Puts the call on hold. 80 ''' 81 self._Property('STATUS', 'ONHOLD')
82
83 - def InputDevice(self, DeviceType=None, Set=None):
84 '''Queries or sets the sound input device. 85 86 @param DeviceType: Sound input device type or None. 87 @type DeviceType: L{Call IO device type<enums.callIoDeviceTypeUnknown>} or None 88 @param Set: Value the device should be set to or None. 89 @type Set: unicode, int or None 90 @return: If DeviceType and Set are None, returns a dictionary of device types and their 91 values. Dictionary contains only those device types, whose values were set. If the 92 DeviceType is not None but Set is None, returns the current value of the device or 93 None if the device wasn't set. If Set is not None, sets a new value for the device. 94 @rtype: unicode, dict or None 95 96 @note: This command functions for active calls only. 97 ''' 98 if Set == None: # get 99 args = args2dict(self._Property('INPUT', Cache=False)) 100 for t in args: 101 if t == callIoDeviceTypePort: 102 args[t] = int(args[t]) 103 if DeviceType == None: # get active devices 104 return args 105 return args.get(DeviceType, None) 106 elif DeviceType != None: # set 107 self._Alter('SET_INPUT', '%s=%s' % (DeviceType, quote(unicode(Set), True))) 108 else: 109 raise TypeError('DeviceType must be specified if Set is used')
110
111 - def Join(self, Id):
112 '''Joins with another call to form a conference. 113 114 @param Id: Call Id of the other call to join to the conference. 115 @type Id: int 116 @return: Conference object. 117 @rtype: L{IConference} 118 ''' 119 reply = self._Skype._DoCommand('SET CALL %s JOIN_CONFERENCE %s' % (self._Id, Id), 120 'CALL %s CONF_ID' % self._Id) 121 return IConference(reply.split()[-1], self._Skype)
122
123 - def MarkAsSeen(self):
124 '''Marks the call as seen. 125 ''' 126 self.Seen = True
127
128 - def OutputDevice(self, DeviceType=None, Set=None):
129 '''Queries or sets the sound output device. 130 131 @param DeviceType: Sound output device type or None. 132 @type DeviceType: L{Call IO device type<enums.callIoDeviceTypeUnknown>} or None 133 @param Set: Value the device should be set to or None. 134 @type Set: unicode, int or None 135 @return: If DeviceType and Set are None, returns a dictionary of device types and their 136 values. Dictionary contains only those device types, whose values were set. If the 137 DeviceType is not None but Set is None, returns the current value of the device or 138 None if the device wasn't set. If Set is not None, sets a new value for the device. 139 @rtype: unicode, dict or None 140 141 @note: This command functions for active calls only. 142 ''' 143 if Set == None: # get 144 args = args2dict(self._Property('OUTPUT', Cache=False)) 145 for t in args: 146 if t == callIoDeviceTypePort: 147 args[t] = int(args[t]) 148 if DeviceType == None: # get active devices 149 return args 150 return args.get(DeviceType, None) 151 elif DeviceType != None: # set 152 self._Alter('SET_OUTPUT', '%s=%s' % (DeviceType, quote(unicode(Set), True))) 153 else: 154 raise TypeError('DeviceType must be specified if Set is used')
155
156 - def RedirectToVoicemail(self):
157 '''Redirects a call to voicemail. 158 ''' 159 self._Alter('END', 'REDIRECT_TO_VOICEMAIL')
160
161 - def Resume(self):
162 '''Resumes the held call. 163 ''' 164 self.Answer()
165
166 - def StartVideoReceive(self):
167 '''Starts video receive. 168 ''' 169 self._Alter('START_VIDEO_RECEIVE')
170
171 - def StartVideoSend(self):
172 '''Starts video send. 173 ''' 174 self._Alter('START_VIDEO_SEND')
175
176 - def StopVideoReceive(self):
177 '''Stops video receive. 178 ''' 179 self._Alter('STOP_VIDEO_RECEIVE')
180
181 - def StopVideoSend(self):
182 '''Stops video send. 183 ''' 184 self._Alter('STOP_VIDEO_SEND')
185
186 - def Transfer(self, *Targets):
187 '''Transfers a call to one or more contacts or phone numbers. 188 189 @param Targets: one or more phone numbers or Skypenames the call is beeing transferred to. 190 @type Targets: unicode 191 @see: L{CanTransfer} 192 193 @note: You can transfer an incoming call to a group by specifying more than one 194 target, first one of the group to answer will get the call. 195 ''' 196 self._Alter('TRANSFER', ', '.join(Targets))
197
198 - def _GetConferenceId(self):
199 return int(self._Property('CONF_ID'))
200 201 ConferenceId = property(_GetConferenceId, 202 doc='''ConferenceId. 203 204 @type: int 205 ''') 206
207 - def _GetDatetime(self):
208 from datetime import datetime 209 return datetime.fromtimestamp(self.Timestamp)
210 211 Datetime = property(_GetDatetime, 212 doc='''Date and time of the call. 213 214 @type: datetime.datetime 215 @see: L{Timestamp} 216 ''') 217
218 - def _SetDTMF(self, value):
219 self._Property('DTMF', value)
220 221 DTMF = property(fset=_SetDTMF, 222 doc='''Set this property to send DTMF codes. 223 224 @type: unicode 225 226 @note: This command functions for active calls only. 227 ''') 228
229 - def _GetDuration(self):
230 return int(self._Property('DURATION', Cache=False))
231 232 Duration = property(_GetDuration, 233 doc='''Duration of the call in seconds. 234 235 @type: int 236 ''') 237
238 - def _GetFailureReason(self):
239 return int(self._Property('FAILUREREASON'))
240 241 FailureReason = property(_GetFailureReason, 242 doc='''Call failure reason. Read if L{Status} == L{clsFailed<enums.clsFailed>}. 243 244 @type: L{Call failure reason<enums.cfrUnknown>} 245 ''') 246
247 - def _GetForwardedBy(self):
248 return self._Property('FORWARDED_BY')
249 250 ForwardedBy = property(_GetForwardedBy, 251 doc='''Skypename of the user who forwarded a call. 252 253 @type: unicode 254 ''') 255
256 - def _GetId(self):
257 return self._Id
258 259 Id = property(_GetId, 260 doc='''Call Id. 261 262 @type: int 263 ''') 264
265 - def _GetInputStatus(self):
266 return self._Property('VAA_INPUT_STATUS') == 'TRUE'
267 268 InputStatus = property(_GetInputStatus, 269 doc='''True if call voice input is enabled. 270 271 @type: bool 272 ''') 273
274 - def _GetParticipants(self):
275 count = int(self._Property('CONF_PARTICIPANTS_COUNT')) 276 return tuple([IParticipant((self._Id, x), self._Skype) for x in xrange(count)])
277 278 Participants = property(_GetParticipants, 279 doc='''Participants of a conference call not hosted by the user. 280 281 @type: tuple of L{IParticipant} 282 ''') 283
284 - def _GetPartnerDisplayName(self):
285 return self._Property('PARTNER_DISPNAME')
286 287 PartnerDisplayName = property(_GetPartnerDisplayName, 288 doc='''The DisplayName of the remote caller. 289 290 @type: unicode 291 ''') 292
293 - def _GetPartnerHandle(self):
294 return self._Property('PARTNER_HANDLE')
295 296 PartnerHandle = property(_GetPartnerHandle, 297 doc='''The Skypename of the remote caller. 298 299 @type: unicode 300 ''') 301
302 - def _GetPstnNumber(self):
303 return self._Property('PSTN_NUMBER')
304 305 PstnNumber = property(_GetPstnNumber, 306 doc='''PSTN number of the call. 307 308 @type: unicode 309 ''') 310
311 - def _GetPstnStatus(self):
312 return self._Property('PSTN_STATUS')
313 314 PstnStatus = property(_GetPstnStatus, 315 doc='''PSTN number status. 316 317 @type: unicode 318 ''') 319
320 - def _GetRate(self):
321 return int(self._Property('RATE'))
322 323 Rate = property(_GetRate, 324 doc='''Call rate. Expressed using L{RatePrecision}. If you're just interested in the call rate 325 expressed in current currency, use L{RateValue} instead. 326 327 @type: int 328 @see: L{RateCurrency}, L{RatePrecision}, L{RateToText}, L{RateValue} 329 ''') 330
331 - def _GetRateCurrency(self):
332 return self._Property('RATE_CURRENCY')
333 334 RateCurrency = property(_GetRateCurrency, 335 doc='''Call rate currency. 336 337 @type: unicode 338 @see: L{Rate}, L{RatePrecision}, L{RateToText}, L{RateValue} 339 ''') 340
341 - def _GetRatePrecision(self):
342 return int(self._Property('RATE_PRECISION'))
343 344 RatePrecision = property(_GetRatePrecision, 345 doc='''Call rate precision. Expressed as a number of times the call rate has to be divided by 10. 346 347 @type: int 348 @see: L{Rate}, L{RateCurrency}, L{RateToText}, L{RateValue} 349 ''') 350
351 - def _GetRateToText(self):
352 return (u'%s %.3f' % (self.RateCurrency, self.RateValue)).strip()
353 354 RateToText = property(_GetRateToText, 355 doc='''Returns the call rate as a text with currency and properly formatted value. 356 357 @type: unicode 358 @see: L{Rate}, L{RateCurrency}, L{RatePrecision}, L{RateValue} 359 ''') 360
361 - def _GetRateValue(self):
362 if self.Rate < 0: 363 return 0.0 364 return float(self.Rate) / (10 ** self.RatePrecision)
365 366 RateValue = property(_GetRateValue, 367 doc='''Call rate value. Expressed in current currency. 368 369 @type: float 370 @see: L{Rate}, L{RateCurrency}, L{RatePrecision}, L{RateToText} 371 ''') 372
373 - def _GetSeen(self):
374 return self._Property('SEEN') == 'TRUE'
375
376 - def _SetSeen(self, value):
377 self._Property('SEEN', cndexp(value, 'TRUE', 'FALSE'))
378 379 Seen = property(_GetSeen, _SetSeen, 380 doc='''Queries/sets the seen status of the call. True if the call was seen, False otherwise. 381 382 @type: bool 383 384 @note: You cannot alter the call seen status from seen to unseen. 385 ''') 386
387 - def _GetStatus(self):
388 return self._Property('STATUS')
389
390 - def _SetStatus(self, value):
391 self._Property('STATUS', str(value))
392 393 Status = property(_GetStatus, _SetStatus, 394 doc='''The call status. 395 396 @type: L{Call status<enums.clsUnknown>} 397 ''') 398
399 - def _GetSubject(self):
400 return self._Property('SUBJECT')
401 402 Subject = property(_GetSubject, 403 doc='''Call subject. 404 405 @type: unicode 406 ''') 407
408 - def _GetTargetIdentify(self):
409 return self._Property('TARGET_IDENTIFY')
410 411 TargetIdentify = property(_GetTargetIdentify, 412 doc='''Target number for incoming SkypeIn calls. 413 414 @type: unicode 415 ''') 416
417 - def _GetTimestamp(self):
418 return float(self._Property('TIMESTAMP'))
419 420 Timestamp = property(_GetTimestamp, 421 doc='''Call date and time expressed as a timestamp. 422 423 @type: float 424 @see: L{Datetime} 425 ''') 426
427 - def _GetTransferActive(self):
428 return self._Property('TRANSFER_ACTIVE') == 'TRUE'
429 430 TransferActive = property(_GetTransferActive, 431 doc='''Returns True if the call has been transfered. 432 433 @type: bool 434 ''') 435
436 - def _GetTransferredBy(self):
437 return self._Property('TRANSFERRED_BY')
438 439 TransferredBy = property(_GetTransferredBy, 440 doc='''Returns the Skypename of the user who transferred the call. 441 442 @type: unicode 443 ''') 444
445 - def _GetTransferredTo(self):
446 return self._Property('TRANSFERRED_TO')
447 448 TransferredTo = property(_GetTransferredTo, 449 doc='''Returns the Skypename of the user or phone number the call has been transferred to. 450 451 @type: unicode 452 ''') 453
454 - def _GetTransferStatus(self):
455 return self._Property('TRANSFER_STATUS')
456 457 TransferStatus = property(_GetTransferStatus, 458 doc='''Returns the call transfer status. 459 460 @type: L{Call status<enums.clsUnknown>} 461 ''') 462
463 - def _GetType(self):
464 return self._Property('TYPE')
465 466 Type = property(_GetType, 467 doc='''Call type. 468 469 @type: L{Call type<enums.cltUnknown>} 470 ''') 471
472 - def _GetVideoReceiveStatus(self):
473 return self._Property('VIDEO_RECEIVE_STATUS')
474 475 VideoReceiveStatus = property(_GetVideoReceiveStatus, 476 doc='''Call video receive status. 477 478 @type: L{Call video send status<enums.vssUnknown>} 479 ''') 480
481 - def _GetVideoSendStatus(self):
482 return self._Property('VIDEO_SEND_STATUS')
483 484 VideoSendStatus = property(_GetVideoSendStatus, 485 doc='''Call video send status. 486 487 @type: L{Call video send status<enums.vssUnknown>} 488 ''') 489
490 - def _GetVideoStatus(self):
491 return self._Property('VIDEO_STATUS')
492 493 VideoStatus = property(_GetVideoStatus, 494 doc='''Call video status. 495 496 @type: L{Call video status<enums.cvsUnknown>} 497 ''') 498
499 - def _GetVmAllowedDuration(self):
500 return int(self._Property('VM_ALLOWED_DURATION'))
501 502 VmAllowedDuration = property(_GetVmAllowedDuration, 503 doc='''Returns the permitted duration of a voicemail in seconds. 504 505 @type: int 506 ''') 507
508 - def _GetVmDuration(self):
509 return int(self._Property('VM_DURATION'))
510 511 VmDuration = property(_GetVmDuration, 512 doc='''Returns the duration of a voicemail. 513 514 @type: int 515 ''')
516 517
518 -class IParticipant(Cached):
519 '''Represents a conference call participant. 520 ''' 521
522 - def __repr__(self):
523 return '<%s with Id=%s, Idx=%s, Handle=%s>' % (Cached.__repr__(self)[1:-1], repr(self.Id), repr(self.Idx), repr(self.Handle))
524
525 - def _Init(self, Id_Idx, Skype):
526 self._Skype = Skype 527 Id, Idx = Id_Idx 528 self._Id = int(Id) 529 self._Idx = int(Idx)
530
531 - def _Property(self, Prop):
532 reply = self._Skype._Property('CALL', self._Id, 'CONF_PARTICIPANT %d' % self._Idx) 533 return chop(reply, 3)[Prop]
534
535 - def _GetCallStatus(self):
536 return self._Property(2)
537 538 CallStatus = property(_GetCallStatus, 539 doc='''Call status of a participant in a conference call. 540 541 @type: L{Call status<enums.clsUnknown>} 542 ''') 543
544 - def _GetCallType(self):
545 return self._Property(1)
546 547 CallType = property(_GetCallType, 548 doc='''Call type in a conference call. 549 550 @type: L{Call type<enums.cltUnknown>} 551 ''') 552
553 - def _GetDisplayName(self):
554 return self._Property(3)
555 556 DisplayName = property(_GetDisplayName, 557 doc='''DisplayName of a participant in a conference call. 558 559 @type: unicode 560 ''') 561
562 - def _GetHandle(self):
563 return self._Property(0)
564 565 Handle = property(_GetHandle, 566 doc='''Skypename of a participant in a conference call. 567 568 @type: unicode 569 ''') 570
571 - def _GetId(self):
572 return self._Id
573 574 Id = property(_GetId, 575 doc='''Call Id. 576 577 @type: int 578 ''') 579
580 - def _GetIdx(self):
581 return self._Idx
582 583 Idx = property(_GetIdx, 584 doc='''Call participant index. 585 586 @type: int 587 ''')
588 589
590 -class IConference(Cached):
591 '''Represents a conference call. 592 ''' 593
594 - def __repr__(self):
595 return '<%s with Id=%s>' % (Cached.__repr__(self)[1:-1], repr(self.Id))
596
597 - def _Init(self, Id, Skype):
598 self._Skype = Skype 599 self._Id = int(Id)
600
601 - def Finish(self):
602 '''Finishes a conference so all active calls have the status L{clsFinished<enums.clsFinished>}. 603 ''' 604 for c in self._GetCalls(): 605 c.Finish()
606
607 - def Hold(self):
608 '''Places all calls in a conference on hold so all active calls have the status L{clsLocalHold<enums.clsLocalHold>}. 609 ''' 610 for c in self._GetCalls(): 611 c.Hold()
612
613 - def Resume(self):
614 '''Resumes a conference that was placed on hold so all active calls have the status L{clsInProgress<enums.clsInProgress>}. 615 ''' 616 for c in self._GetCalls(): 617 c.Resume()
618
619 - def _GetActiveCalls(self):
620 return tuple([x for x in self._Skype.ActiveCalls if x.ConferenceId == self._Id])
621 622 ActiveCalls = property(_GetActiveCalls, 623 doc='''Active calls with the same conference ID. 624 625 @type: tuple of L{ICall} 626 ''') 627
628 - def _GetCalls(self):
629 return tuple([x for x in self._Skype.Calls() if x.ConferenceId == self._Id])
630 631 Calls = property(_GetCalls, 632 doc='''Calls with the same conference ID. 633 634 @type: tuple of L{ICall} 635 ''') 636
637 - def _GetId(self):
638 return self._Id
639 640 Id = property(_GetId, 641 doc='''Id of a conference. 642 643 @type: int 644 ''')
645