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

Source Code for Module Skype4Py.call

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