-
Notifications
You must be signed in to change notification settings - Fork 7
/
SessionInfoController.py
833 lines (678 loc) · 36.6 KB
/
SessionInfoController.py
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
# Copyright (C) 2009-2011 AG Projects. See LICENSE for details.
#
from AppKit import NSDefaultRunLoopMode, NSForegroundColorAttributeName, NSModalPanelRunLoopMode
from Foundation import (NSAttributedString,
NSBezierPath,
NSBundle,
NSImage,
NSColor,
NSDictionary,
NSGradient,
NSGraphicsContext,
NSInsetRect,
NSLocalizedString,
NSObject,
NSRect,
NSRunLoop,
NSTimer,
NSView)
import objc
import datetime
import time
import re
from application.notification import IObserver, NotificationCenter
from application.python import Null
from sipsimple.configuration.settings import SIPSimpleSettings
from zope.interface import implementer
from sipsimple.util import ISOTimestamp
from MediaStream import STREAM_CONNECTED
from util import beautify_audio_codec, beautify_video_codec, run_in_gui_thread, format_size
ice_candidates= {'srflx': 'Server Reflexive',
'prflx': 'Peer Reflexive',
'host': 'Host',
'relay': 'Server Relay'
}
@implementer(IObserver)
class SessionInfoController(NSObject):
window = objc.IBOutlet()
sessionBox = objc.IBOutlet()
audioBox = objc.IBOutlet()
videoBox = objc.IBOutlet()
chatBox = objc.IBOutlet()
remote_party = objc.IBOutlet()
account = objc.IBOutlet()
duration = objc.IBOutlet()
remote_ua = objc.IBOutlet()
status = objc.IBOutlet()
remote_endpoint = objc.IBOutlet()
tls_lock = objc.IBOutlet()
audio_status = objc.IBOutlet()
audio_codec = objc.IBOutlet()
audio_remote_endpoint = objc.IBOutlet()
audio_ice_negotiation = objc.IBOutlet()
audio_rtt = objc.IBOutlet()
audio_rtt_graph = objc.IBOutlet()
audio_packet_loss_rx = objc.IBOutlet()
audio_packet_loss_tx = objc.IBOutlet()
audio_packet_loss_rx_graph = objc.IBOutlet()
audio_packet_loss_tx_graph = objc.IBOutlet()
audio_srtp_lock = objc.IBOutlet()
rx_speed_graph = objc.IBOutlet()
rx_speed = objc.IBOutlet()
tx_speed_graph = objc.IBOutlet()
tx_speed = objc.IBOutlet()
video_status = objc.IBOutlet()
video_codec = objc.IBOutlet()
video_remote_endpoint = objc.IBOutlet()
video_ice_negotiation = objc.IBOutlet()
video_srtp_lock = objc.IBOutlet()
video_rx_speed_graph = objc.IBOutlet()
video_rx_speed = objc.IBOutlet()
video_tx_speed_graph = objc.IBOutlet()
video_tx_speed = objc.IBOutlet()
chat_remote_endpoint = objc.IBOutlet()
chat_connection_mode = objc.IBOutlet()
chat_tls_lock = objc.IBOutlet()
def __new__(cls, *args, **kwargs):
return cls.alloc().init()
def __init__(self, sessionController):
self.notification_center = NotificationCenter()
self.notification_center.add_observer(self, name='CFGSettingsObjectDidChange')
self.sessionController = None
self.audio_stream = None
self.video_stream = None
self.chat_stream = None
self.add_session(sessionController)
self.add_audio_stream()
self.add_video_stream()
self.add_chat_stream()
self.timer = NSTimer.timerWithTimeInterval_target_selector_userInfo_repeats_(1.0, self, "updateTimer:", None, True)
NSRunLoop.currentRunLoop().addTimer_forMode_(self.timer, NSModalPanelRunLoopMode)
NSRunLoop.currentRunLoop().addTimer_forMode_(self.timer, NSDefaultRunLoopMode)
NSBundle.loadNibNamed_owner_("SessionInfoPanel", self)
sessionBoxTitle = NSAttributedString.alloc().initWithString_attributes_(NSLocalizedString("SIP Session", "Label"), NSDictionary.dictionaryWithObject_forKey_(NSColor.orangeColor(), NSForegroundColorAttributeName))
self.sessionBox.setTitle_(sessionBoxTitle)
audioBoxTitle = NSAttributedString.alloc().initWithString_attributes_(NSLocalizedString("Audio Stream", "Label"), NSDictionary.dictionaryWithObject_forKey_(NSColor.orangeColor(), NSForegroundColorAttributeName))
self.audioBox.setTitle_(audioBoxTitle)
videoBoxTitle = NSAttributedString.alloc().initWithString_attributes_(NSLocalizedString("Video Stream", "Label"), NSDictionary.dictionaryWithObject_forKey_(NSColor.orangeColor(), NSForegroundColorAttributeName))
self.videoBox.setTitle_(videoBoxTitle)
chatBoxTitle = NSAttributedString.alloc().initWithString_attributes_(NSLocalizedString("Chat Stream", "Label"), NSDictionary.dictionaryWithObject_forKey_(NSColor.orangeColor(), NSForegroundColorAttributeName))
self.chatBox.setTitle_(chatBoxTitle)
settings = SIPSimpleSettings()
self.audio_rtt_graph.setLineWidth_(1.0)
self.audio_rtt_graph.setLineSpacing_(1.0)
self.audio_rtt_graph.setAboveLimit_(settings.gui.rtt_threshold) # if higher show red color
self.audio_rtt_graph.setMinimumHeigth_(settings.gui.rtt_threshold)
self.audio_packet_loss_rx_graph.setLineWidth_(1.0)
self.audio_packet_loss_rx_graph.setLineSpacing_(1.0)
self.audio_packet_loss_rx_graph.setAboveLimit_(3) # if higher than 3% show red color
self.audio_packet_loss_rx_graph.setLineColor_(NSColor.greenColor())
self.audio_packet_loss_rx_graph.setMinimumHeigth_(5)
self.audio_packet_loss_tx_graph.setLineWidth_(1.0)
self.audio_packet_loss_tx_graph.setLineSpacing_(1.0)
self.audio_packet_loss_tx_graph.setAboveLimit_(3) # if higher than 3% show red color
self.audio_packet_loss_tx_graph.setLineColor_(NSColor.greenColor())
self.audio_packet_loss_tx_graph.setMinimumHeigth_(5)
self.rx_speed_graph.setLineWidth_(1.0)
self.rx_speed_graph.setLineSpacing_(0.0)
self.rx_speed_graph.setLineColor_(NSColor.greenColor())
self.rx_speed_graph.setMinimumHeigth_(100000)
self.rx_speed_graph.setAboveLimit_(120000)
self.tx_speed_graph.setLineWidth_(1.0)
self.tx_speed_graph.setLineSpacing_(0.0)
self.tx_speed_graph.setLineColor_(NSColor.blueColor())
self.tx_speed_graph.setMinimumHeigth_(100000)
self.tx_speed_graph.setAboveLimit_(120000)
self.video_rx_speed_graph.setLineWidth_(1.0)
self.video_rx_speed_graph.setLineSpacing_(0.0)
self.video_rx_speed_graph.setLineColor_(NSColor.greenColor())
self.video_rx_speed_graph.setMinimumHeigth_(100000)
self.video_rx_speed_graph.setAboveLimit_(99999999)
self.video_tx_speed_graph.setLineWidth_(1.0)
self.video_tx_speed_graph.setLineSpacing_(0.0)
self.video_tx_speed_graph.setLineColor_(NSColor.blueColor())
self.video_tx_speed_graph.setMinimumHeigth_(100000)
self.video_tx_speed_graph.setAboveLimit_(99999999)
self.resetSession()
self.updatePanelValues()
@objc.python_method
def add_session(self, sessionController):
if self.sessionController is None:
self.sessionController = sessionController
self.notification_center.add_observer(self, sender=self.sessionController)
@objc.python_method
def remove_session(self):
if self.sessionController is not None:
self.notification_center.remove_observer(self, sender=self.sessionController)
self.notification_center.remove_observer(self, name='CFGSettingsObjectDidChange')
self.sessionController = None
self.remove_audio_stream()
self.remove_video_stream()
self.remove_chat_stream()
@objc.python_method
def add_audio_stream(self):
if self.sessionController is not None and self.sessionController.hasStreamOfType("audio") and self.audio_stream is None:
self.audio_stream = self.sessionController.streamHandlerOfType("audio")
self.notification_center.add_observer(self, sender=self.audio_stream)
self.notification_center.add_observer(self, sender=self.audio_stream.stream)
@objc.python_method
def remove_audio_stream(self):
if self.audio_stream is not None:
self.notification_center.discard_observer(self, sender=self.audio_stream)
self.notification_center.discard_observer(self, sender=self.audio_stream.stream)
self.audio_stream = None
self.updateAudioStatus()
@objc.python_method
def add_video_stream(self):
if self.sessionController is not None and self.sessionController.hasStreamOfType("video") and self.video_stream is None:
self.video_stream = self.sessionController.streamHandlerOfType("video")
self.notification_center.add_observer(self, sender=self.video_stream)
self.notification_center.add_observer(self, sender=self.video_stream.stream)
@objc.python_method
def remove_video_stream(self):
if self.video_stream is not None:
self.notification_center.discard_observer(self, sender=self.video_stream)
self.notification_center.discard_observer(self, sender=self.video_stream.stream)
self.video_stream = None
self.resetVideo()
self.updateVideoStatus()
@objc.python_method
def add_chat_stream(self):
if self.sessionController is not None and self.sessionController.hasStreamOfType("chat") and self.chat_stream is None:
self.chat_stream = self.sessionController.streamHandlerOfType("chat")
@objc.python_method
def remove_chat_stream(self):
if self.chat_stream is not None:
self.chat_stream = None
@objc.python_method
def resetSession(self):
self.remote_endpoint.setStringValue_('')
self.remote_ua.setStringValue_('')
self.status.setStringValue_('')
self.duration.setStringValue_('')
self.resetAudio()
self.resetVideo()
self.resetChat()
@objc.python_method
def resetAudio(self):
self.audio_status.setStringValue_('')
self.audio_codec.setStringValue_('')
self.audio_remote_endpoint.setStringValue_('')
self.audio_ice_negotiation.setStringValue_('')
self.audio_rtt.setStringValue_('')
self.audio_packet_loss_rx.setStringValue_('')
self.audio_packet_loss_tx.setStringValue_('')
self.rx_speed.setStringValue_('')
self.tx_speed.setStringValue_('')
@objc.python_method
def resetVideo(self):
self.video_status.setStringValue_('')
self.video_codec.setStringValue_('')
self.video_remote_endpoint.setStringValue_('')
self.video_ice_negotiation.setStringValue_('')
self.video_rx_speed.setStringValue_('')
self.video_tx_speed.setStringValue_('')
@objc.python_method
def resetChat(self):
self.chat_remote_endpoint.setStringValue_('')
self.chat_connection_mode.setStringValue_('')
@objc.python_method
def updatePanelValues(self):
self.updateSession()
@objc.python_method
def updateSession(self):
if self.sessionController is None:
self.resetSession()
else:
self.updateSessionStatus()
self.remote_party.setStringValue_(self.sessionController.titleLong)
self.account.setStringValue_(str(self.sessionController.account.id))
if self.sessionController.conference_info is not None and self.sessionController.remote_focus:
pass
if hasattr(self.sessionController.session, 'remote_user_agent') and self.sessionController.session.remote_user_agent is not None:
self.remote_ua.setStringValue_(self.sessionController.session.remote_user_agent)
if self.sessionController.session is not None:
if self.sessionController.session.transport is not None:
transport = self.sessionController.session.transport
if self.sessionController.session.peer_address is not None:
self.remote_endpoint.setStringValue_('%s:%s' % (transport, self.sessionController.session.peer_address))
self.tls_lock.setHidden_(False if transport == 'tls' else True)
elif self.sessionController.routes:
route = self.sessionController.routes[0]
self.remote_endpoint.setStringValue_('%s:%s:%s' % (route.transport, route.address, route.port))
self.tls_lock.setHidden_(False if route.transport == 'tls' else True)
elif self.sessionController.routes:
route = self.sessionController.routes[0]
self.remote_endpoint.setStringValue_('%s:%s:%s' % (route.transport, route.address, route.port))
self.tls_lock.setHidden_(False if route.transport == 'tls' else True)
self.updateAudio()
self.updateVideo()
self.updateChat()
@objc.python_method
def updateSessionStatus(self, sub_state=None):
if self.sessionController.state is None:
self.status.setStringValue_("")
return
if sub_state is None:
sub_state = self.sessionController.session.state if self.sessionController.session is not None else 'none'
sub_state = re.sub("_", " ", sub_state.title()) if sub_state is not None else ''
state = self.sessionController.state.title()
self.status.setStringValue_('%s (%s)' % (state, sub_state) if state != sub_state and sub_state != 'None' else state)
@objc.python_method
def updateAudio(self):
if self.audio_status.stringValue() and (self.sessionController is None or self.audio_stream is None or self.audio_stream.stream is None):
self.resetAudio()
elif (self.sessionController is not None and self.audio_stream is not None and self.audio_stream.stream is not None):
self.updateAudioStatus()
self.audio_rtt_graph.setDataQueue_needsDisplay_(self.audio_stream.rtt_history, True if self.window.isVisible() else False)
self.rx_speed_graph.setDataQueue_needsDisplay_(self.audio_stream.rx_speed_history, True if self.window.isVisible() else False)
self.tx_speed_graph.setDataQueue_needsDisplay_(self.audio_stream.tx_speed_history, True if self.window.isVisible() else False)
self.audio_packet_loss_rx_graph.setDataQueue_needsDisplay_(self.audio_stream.loss_rx_history, True if self.window.isVisible() else False)
self.audio_packet_loss_tx_graph.setDataQueue_needsDisplay_(self.audio_stream.loss_tx_history, True if self.window.isVisible() else False)
rtt = self.audio_stream.statistics['rtt']
if rtt > 1000:
text = '%.1f s' % (float(rtt)/1000.0)
elif rtt > 100:
text = '%d ms' % rtt
elif rtt:
text = '%d ms' % rtt
else:
text = ''
self.rx_speed.setStringValue_('Rx %s/s' % format_size(self.audio_stream.statistics['rx_bytes'], bits=True))
self.tx_speed.setStringValue_('Tx %s/s' % format_size(self.audio_stream.statistics['tx_bytes'], bits=True))
self.audio_rtt.setStringValue_(text)
if self.audio_stream.statistics['loss_rx'] > 3:
self.audio_packet_loss_rx.setStringValue_('Local: %.1f %%' % self.audio_stream.statistics['loss_rx'])
else:
self.audio_packet_loss_rx.setStringValue_('')
if self.audio_stream.statistics['loss_tx'] > 3:
self.audio_packet_loss_tx.setStringValue_('Remote: %.1f %%' % self.audio_stream.statistics['loss_tx'])
else:
self.audio_packet_loss_tx.setStringValue_('')
if self.audio_stream.stream.codec and self.audio_stream.stream.sample_rate:
codec = beautify_audio_codec(self.audio_stream.stream.codec)
try:
settings = SIPSimpleSettings()
sample_rate = self.audio_stream.stream.sample_rate/1000
codec = codec + " %0.fkHz" % sample_rate
except TypeError:
pass
self.audio_codec.setStringValue_(codec)
self.audio_srtp_lock.setHidden_(False if self.audio_stream.encryption_active else True)
if self.audio_stream.zrtp_active:
if self.audio_stream.zrtp_verified:
image = 'locked-green'
else:
image = 'locked-orange'
elif self.audio_stream.srtp_active:
image = 'locked-green'
else:
image = 'unlocked-darkgray'
self.audio_srtp_lock.setImage_(NSImage.imageNamed_(image))
else:
self.audio_codec.setStringValue_('')
self.audio_srtp_lock.setHidden_(True)
self.audio_remote_endpoint.setStringValue_('%s:%s' % (self.audio_stream.stream.remote_rtp_address, self.audio_stream.stream.remote_rtp_port) if self.audio_stream.stream.remote_rtp_address else '')
if self.audio_stream.stream.ice_active:
ice_status = self.audio_stream.ice_negotiation_status if self.audio_stream.ice_negotiation_status is not None else ''
if self.audio_stream.stream.ice_active:
if self.audio_stream.stream.local_rtp_candidate and self.audio_stream.stream.remote_rtp_candidate:
if self.audio_stream.stream.local_rtp_candidate.type.lower() != 'relay' and self.audio_stream.stream.remote_rtp_candidate.type.lower() != 'relay':
if self.audio_stream.stream.local_rtp_candidate.type.lower() == 'host' and self.audio_stream.stream.remote_rtp_candidate.type.lower() == 'host':
ice_status = NSLocalizedString("Host to Host", "Label")
else:
ice_status = NSLocalizedString("Peer to Peer", "Label")
else:
ice_status = NSLocalizedString("Server Relayed", "Label")
else:
ice_status = self.audio_stream.ice_negotiation_status if self.audio_stream.ice_negotiation_status is not None else ''
if ice_status == b"All ICE checklists failed (PJNATH_EICEFAILED)":
ice_status = NSLocalizedString("Probing Failed", "Label")
elif ice_status == b"Remote answer doesn't support ICE":
ice_status = NSLocalizedString("Not Supported", "Label")
self.audio_ice_negotiation.setStringValue_(ice_status)
@objc.python_method
def updateVideo(self):
if self.video_status.stringValue() and (self.sessionController is None or self.video_stream is None or self.video_stream.stream is None):
self.resetVideo()
elif (self.sessionController is not None and self.video_stream is not None and self.video_stream.stream is not None):
self.updateVideoStatus()
self.video_rx_speed_graph.setDataQueue_needsDisplay_(self.video_stream.rx_speed_history, True if self.window.isVisible() else False)
self.video_tx_speed_graph.setDataQueue_needsDisplay_(self.video_stream.tx_speed_history, True if self.window.isVisible() else False)
rtt = self.video_stream.statistics['rtt']
if rtt > 1000:
text = '%.1f s' % (float(rtt)/1000.0)
elif rtt > 100:
text = '%d ms' % rtt
elif rtt:
text = '%d ms' % rtt
else:
text = ''
self.video_rx_speed.setStringValue_('Rx %s/s' % format_size(self.video_stream.statistics['rx_bytes'], bits=True))
self.video_tx_speed.setStringValue_('Tx %s/s' % format_size(self.video_stream.statistics['tx_bytes'], bits=True))
if self.video_stream.stream.codec and self.video_stream.stream.sample_rate:
codec = beautify_video_codec(self.video_stream.stream.codec)
try:
settings = SIPSimpleSettings()
sample_rate = self.video_stream.stream.sample_rate/1000
codec = codec + " @%d fps" % self.video_stream.statistics['fps']
except TypeError:
pass
self.video_codec.setStringValue_(codec)
self.video_srtp_lock.setHidden_(False if self.video_stream.encryption_active else True)
if self.video_stream.encryption_active:
if self.video_stream.zrtp_active:
self.video_srtp_lock.setImage_(NSImage.imageNamed_("locked-green") if self.video_stream.zrtp_verified else NSImage.imageNamed_("locked-red"))
else:
self.video_srtp_lock.setImage_(NSImage.imageNamed_("srtp"))
else:
self.video_codec.setStringValue_('')
self.video_srtp_lock.setHidden_(True)
self.video_remote_endpoint.setStringValue_('%s:%s' % (self.video_stream.stream.remote_rtp_address, self.video_stream.stream.remote_rtp_port) if self.video_stream.stream.remote_rtp_address else '')
if self.video_stream.stream.ice_active:
ice_status = self.video_stream.ice_negotiation_status if self.video_stream.ice_negotiation_status is not None else ''
if self.video_stream.stream.ice_active:
if self.video_stream.stream.local_rtp_candidate and self.video_stream.stream.remote_rtp_candidate:
if self.video_stream.stream.local_rtp_candidate.type.lower() != 'relay' and self.video_stream.stream.remote_rtp_candidate.type.lower() != 'relay':
if self.video_stream.stream.local_rtp_candidate.type.lower() == 'host' and self.video_stream.stream.remote_rtp_candidate.type.lower() == 'host':
ice_status = NSLocalizedString("Host to Host", "Label")
else:
ice_status = NSLocalizedString("Peer to Peer", "Label")
else:
ice_status = NSLocalizedString("Server Relayed", "Label")
else:
ice_status = self.video_stream.ice_negotiation_status if self.video_stream.ice_negotiation_status is not None else ''
if ice_status == "All ICE checklists failed (PJNATH_EICEFAILED)":
ice_status = NSLocalizedString("Probing Failed", "Label")
elif ice_status == "Remote answer doesn't support ICE":
ice_status = NSLocalizedString("Not Supported", "Label")
self.video_ice_negotiation.setStringValue_(ice_status)
@objc.python_method
def updateChat(self):
if self.sessionController is None or self.chat_stream is None or self.chat_stream.stream is None or self.chat_stream.stream.msrp is None:
self.resetChat()
else:
if self.chat_stream and self.chat_stream.stream and self.chat_stream.stream.msrp:
if len(self.chat_stream.stream.msrp.full_local_path) > 1:
self.chat_remote_endpoint.setStringValue_(str(self.chat_stream.stream.msrp.full_local_path[0]))
else:
self.chat_remote_endpoint.setStringValue_(str(self.chat_stream.stream.msrp.full_remote_path[0]))
if self.chat_stream and self.chat_stream.stream:
self.chat_connection_mode.setStringValue_(self.chat_stream.stream.local_role.title())
def updateTimer_(self, timer):
if self.sessionController is not None:
self.updateDuration()
self.updateAudio()
self.updateVideo()
@objc.python_method
def updateDuration(self):
if self.sessionController is not None and self.sessionController.session is not None:
if self.sessionController.session.end_time:
now = self.sessionController.session.end_time
else:
now = ISOTimestamp.now()
if self.sessionController.session.start_time and now >= self.sessionController.session.start_time:
elapsed = now - self.sessionController.session.start_time
h = elapsed.days * 24 + elapsed.seconds / (60*60)
m = (elapsed.seconds / 60) % 60
s = elapsed.seconds % 60
text = "%02i:%02i:%02i"%(h,m,s)
self.duration.setStringValue_(text)
else:
self.duration.setStringValue_('')
@objc.python_method
def updateAudioStatus(self):
if self.sessionController is None or self.audio_stream is None:
self.audio_status.setStringValue_("")
else:
if self.audio_stream.holdByLocal:
self.audio_status.setStringValue_(NSLocalizedString("On Hold", "Label"))
elif self.audio_stream.holdByRemote:
self.audio_status.setStringValue_(NSLocalizedString("Hold by Remote", "Label"))
elif self.audio_stream.status == STREAM_CONNECTED:
if self.audio_stream.encryption_active:
stype = self.audio_stream.stream.encryption.type
if stype.startswith('SRTP/SDES'):
stype = stype[5:]
cipher = self.audio_stream.stream.encryption.cipher
cipher = cipher.decode() if isinstance(cipher, bytes) else cipher
title = '%s (%s)' % (stype, cipher)
else:
title = NSLocalizedString("Not Encrypted", "Label")
self.audio_status.setStringValue_(title)
else:
self.audio_status.setStringValue_("")
@objc.python_method
def updateVideoStatus(self):
if self.sessionController is None or self.video_stream is None:
self.video_status.setStringValue_("")
else:
if self.audio_stream and self.audio_stream.holdByLocal:
self.video_status.setStringValue_(NSLocalizedString("On Hold", "Label"))
elif self.audio_stream and self.audio_stream.holdByRemote:
self.video_status.setStringValue_(NSLocalizedString("Hold by Remote", "Label"))
elif self.video_stream.status == STREAM_CONNECTED:
if self.video_stream.encryption_active:
stype = self.video_stream.stream.encryption.type
if stype.startswith('SRTP/SDES'):
stype = stype[5:]
cipher = self.video_stream.stream.encryption.cipher
cipher = cipher.decode() if isinstance(cipher, bytes) else cipher
title = '%s (%s)' % (stype, cipher)
else:
title = NSLocalizedString("Not Encrypted", "Label")
self.video_status.setStringValue_(title)
else:
self.video_status.setStringValue_("")
@objc.python_method
@run_in_gui_thread
def handle_notification(self, notification):
handler = getattr(self, '_NH_%s' % notification.name, Null)
handler(notification)
@objc.python_method
def _NH_BlinkDidRenegotiateStreams(self, notification):
for stream in notification.data.removed_streams:
if stream.type == 'audio':
self.remove_audio_stream()
elif stream.type == 'chat':
self.remove_chat_stream()
elif stream.type == 'video':
self.remove_video_stream()
for stream in notification.data.added_streams:
if stream.type == 'audio':
self.add_audio_stream()
elif stream.type == 'chat':
self.add_chat_stream()
elif stream.type == 'video':
self.add_video_stream()
self.updatePanelValues()
@objc.python_method
def _NH_CFGSettingsObjectDidChange(self, notification):
settings = SIPSimpleSettings()
if "gui.rtt_threshold" in notification.data.modified:
self.audio_rtt_graph.setAboveLimit_(settings.gui.rtt_threshold)
self.audio_rtt_graph.setMinimumHeigth_(settings.gui.rtt_threshold)
@objc.python_method
def _NH_BlinkSessionGotRingIndication(self, notification):
self.updateSessionStatus(sub_state=NSLocalizedString("Ringing...", "Label"))
@objc.python_method
def _NH_BlinkSessionGotProvisionalResponse(self, notification):
self.updateSessionStatus(sub_state=notification.data.reason)
@objc.python_method
def _NH_BlinkSessionDidProcessTransaction(self, notification):
self.updateSessionStatus()
@objc.python_method
def _NH_BlinkSentAddProposal(self, notification):
self.updateSessionStatus()
@objc.python_method
def _NH_BlinkSentRemoveProposal(self, notification):
self.updateSessionStatus()
@objc.python_method
def _NH_BlinkGotProposal(self, notification):
self.updateSessionStatus()
@objc.python_method
def _NH_BlinkProposalGotRejected(self, notification):
self.updateSessionStatus()
@objc.python_method
def _NH_BlinkStreamHandlersChanged(self, notification):
self.updatePanelValues()
@objc.python_method
def _NH_BlinkSessionWillStart(self, notification):
self.updatePanelValues()
@objc.python_method
def _NH_BlinkSessionDidStart(self, notification):
self.add_audio_stream()
self.add_video_stream()
self.add_chat_stream()
self.updatePanelValues()
@objc.python_method
def _NH_BlinkSessionDidEnd(self, notification):
self.stopTimer()
@objc.python_method
def _NH_BlinkConferenceGotUpdate(self, notification):
if self.sessionController is not None and self.sessionController.session is not None and hasattr(notification.data, 'conference_info'):
pass
# todo: the ICE negotiation notification handlers below are never executed (check observers), yet the values in the GUI are updated (from somewhere else?) -Dan
@objc.python_method
def _NH_RTPStreamICENegotiationDidFail(self, notification):
if notification.sender.type == 'audio' and self.audio_stream is not None:
self.audio_ice_negotiation.setStringValue_(self.audio_stream.ice_negotiation_status if self.audio_stream.ice_negotiation_status is not None else '')
elif notification.sender.type == 'video' and self.video_stream is not None:
self.video_ice_negotiation.setStringValue_(self.video_stream.ice_negotiation_status if self.video_stream.ice_negotiation_status is not None else '')
@objc.python_method
def _NH_RTPStreamICENegotiationDidSucceed(self, notification):
if notification.sender.type == 'audio' and self.audio_stream is not None:
self.audio_ice_negotiation.setStringValue_(self.audio_stream.ice_negotiation_status if self.audio_stream.ice_negotiation_status is not None else '')
elif notification.sender.type == 'video' and self.video_stream is not None:
self.video_ice_negotiation.setStringValue_(self.video_stream.ice_negotiation_status if self.video_stream.ice_negotiation_status is not None else '')
@objc.python_method
def _NH_RTPStreamDidChangeHoldState(self, notification):
self.updateAudioStatus()
@objc.python_method
def show(self):
self.window.orderFront_(None)
@objc.python_method
def hide(self):
self.window.orderOut_(None)
@objc.python_method
def toggle(self):
if self.window.isVisible():
self.hide()
else:
self.show()
def windowShouldClose_(self, sender):
self.window.orderOut_(None)
@objc.python_method
def close(self):
self.stopTimer()
self.remove_session()
self.window.orderOut_(None)
@objc.python_method
def stopTimer(self):
if self.timer:
self.timer.invalidate()
self.timer = None
def dealloc(self):
self.audio_packet_loss_rx_graph.removeFromSuperview()
self.audio_packet_loss_tx_graph.removeFromSuperview()
self.audio_rtt_graph.removeFromSuperview()
self.rx_speed_graph.removeFromSuperview()
self.tx_speed_graph.removeFromSuperview()
self.video_rx_speed_graph.removeFromSuperview()
self.video_tx_speed_graph.removeFromSuperview()
objc.super(SessionInfoController, self).dealloc()
class CBGraphView(NSView):
#
# CBGraphView.py
# CBGraphView
#
# Created by boB Rudis on 1/6/09.
# Copyright (c) 2009 RUDIS DOT NET. All rights reserved.
#
dataQueue = None # holds the data we'll be graphing
gradientGray = None # the gray color of the black->gray gradient we are using
lineColor = None # the color to make the bars
grad = None # the gradient object
lineWidth = 1.0 # default bar width (1 "pixel")
lineSpacing = 0.0 # default spacing between bars to no space
limit = 1000
minHeigth = None
def initWithFrame_(self, frame):
""" basic constructor for views. here we init colors and gradients """
self = objc.super(CBGraphView, self).initWithFrame_(frame)
if self:
self.gradientGray = NSColor.colorWithCalibratedRed_green_blue_alpha_(50/255.0, 50/255.0, 50/255.0, 1.0)
self.lineColor = NSColor.colorWithCalibratedRed_green_blue_alpha_(33/255.0, 104/255.0, 198/255.0, 1.0)
self.lineColorAboveLimit = NSColor.redColor()
self.borderColor = NSColor.whiteColor()
self.grad = NSGradient.alloc().initWithStartingColor_endingColor_(NSColor.blackColor(), self.gradientGray)
self.grad.retain()
return self
def setDataQueue_needsDisplay_(self, dq, needs_display=False):
""" set the data object we are graphig """
self.dataQueue = dq
self.setNeedsDisplay_(needs_display)
def setLineWidth_(self, width):
""" let user change line (bar) width """
self.lineWidth = width
def setAboveLimit_(self, limit):
""" show red color above limit """
self.limit = limit
def setMinimumHeigth_(self, heigth):
""" show red color above limit """
self.minHeigth = heigth
def setLineSpacing_(self, spacing):
""" let user change spacing bewteen bars (lines) """
self.lineSpacing = spacing
def setLineColor_(self, color):
""" let user change line (bar) color """
self.lineColor = color
def setBorderColor_(self, color):
""" let user change border color """
self.borderColor = color
def setBackgroundGradientStart_andEnd_(self, startColor, endColor):
""" let user change the gradient colors """
self.grad.release()
self.grad = NSGradient.alloc().initWithStartingColor_endingColor_(startColor, endColor)
self.grad.retain()
def isOpaque(self):
""" are we opaque? why, of course we are! """
return True
def dealloc(self):
""" default destructor """
self.grad.release()
self.dataQueue = None
objc.super(CBGraphView, self).dealloc()
def drawRect_(self, rect):
""" we raw the background gradient and graph outline then clip the inner rect
and draw the bars """
bounds = self.bounds() # get our view bounds
insetBounds = NSInsetRect(bounds, 2, 2) # set the inside ortion
r = NSBezierPath.bezierPathWithRect_(bounds) # create a new bezier rect
self.grad.drawInBezierPath_angle_(r, 90.0) # and draw gradient in it
self.borderColor.set() # set border to white
NSBezierPath.setDefaultLineWidth_(1.0) # set line width for outline
NSBezierPath.strokeRect_(bounds) # draw outline
NSBezierPath.clipRect_(insetBounds) # set the clipping path
insetBounds.size.height -= 2 # leave room at the top (purely my personal asthetic
if self.dataQueue:
barRect = NSRect() # init the rect
# find out the max value so we can scale the graph
maxB = max(max(self.dataQueue), self.minHeigth or 1)
# disable anti-aliasing since it looks bad
shouldAA = NSGraphicsContext.currentContext().shouldAntialias()
NSGraphicsContext.currentContext().setShouldAntialias_(False)
# draw each bar
barRect.origin.x = insetBounds.size.width - self.lineWidth + 2
for sample in reversed(self.dataQueue):
# set drawing color
if sample >= self.limit:
self.lineColorAboveLimit.set()
else:
self.lineColor.set()
barRect.origin.y = insetBounds.origin.y
barRect.size.width = self.lineWidth
barRect.size.height = ((int(sample) * insetBounds.size.height) / maxB)
NSBezierPath.fillRect_(barRect)
barRect.origin.x = barRect.origin.x - self.lineWidth - self.lineSpacing
NSGraphicsContext.currentContext().setShouldAntialias_(shouldAA)