-
Notifications
You must be signed in to change notification settings - Fork 0
/
SessionInfoController.py
780 lines (625 loc) · 34.4 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
# Copyright (C) 2009-2011 AG Projects. See LICENSE for details.
#
from AppKit import NSDefaultRunLoopMode, NSForegroundColorAttributeName, NSModalPanelRunLoopMode
from Foundation import (NSAttributedString,
NSBezierPath,
NSBundle,
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 implements
from MediaStream import STREAM_CONNECTED
from util import allocate_autorelease_pool, 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'
}
class SessionInfoController(NSObject):
implements(IObserver)
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_ice_local_candidate = objc.IBOutlet()
audio_ice_remote_candidate = objc.IBOutlet()
audio_rtt = objc.IBOutlet()
audio_packet_loss = objc.IBOutlet()
audio_rtt_graph = objc.IBOutlet()
audio_packet_loss_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_ice_local_candidate = objc.IBOutlet()
video_ice_remote_candidate = 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_graph.setLineWidth_(1.0)
self.audio_packet_loss_graph.setLineSpacing_(1.0)
self.audio_packet_loss_graph.setAboveLimit_(3) # if higher than 3% show red color
self.audio_packet_loss_graph.setLineColor_(NSColor.greenColor())
self.audio_packet_loss_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_(1200000)
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_(1200000)
self.resetSession()
self.updatePanelValues()
def add_session(self, sessionController):
if self.sessionController is None:
self.sessionController = sessionController
self.notification_center.add_observer(self, sender=self.sessionController)
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()
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)
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()
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)
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()
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")
def remove_chat_stream(self):
if self.chat_stream is not None:
self.chat_stream = None
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()
def _NH_CFGSettingsObjectDidChange(self, notification):
settings = SIPSimpleSettings()
if notification.data.modified.has_key("gui.rtt_threshold"):
self.audio_rtt_graph.setAboveLimit_(settings.gui.rtt_threshold)
self.audio_rtt_graph.setMinimumHeigth_(settings.gui.rtt_threshold)
@allocate_autorelease_pool
def handle_notification(self, notification):
handler = getattr(self, '_NH_%s' % notification.name, Null)
handler(notification)
def resetSession(self):
self.remote_endpoint.setStringValue_('')
self.remote_ua.setStringValue_('')
self.status.setStringValue_('')
self.duration.setStringValue_('')
self.resetAudio()
self.resetVideo()
self.resetChat()
def resetAudio(self):
self.audio_status.setStringValue_('')
self.audio_codec.setStringValue_('')
self.audio_remote_endpoint.setStringValue_('')
self.audio_ice_negotiation.setStringValue_('')
self.audio_ice_local_candidate.setStringValue_('')
self.audio_ice_remote_candidate.setStringValue_('')
self.audio_rtt.setStringValue_('')
self.audio_packet_loss.setStringValue_('')
self.rx_speed.setStringValue_('')
self.tx_speed.setStringValue_('')
def resetVideo(self):
self.video_status.setStringValue_('')
self.video_codec.setStringValue_('')
self.video_remote_endpoint.setStringValue_('')
self.video_ice_negotiation.setStringValue_('')
self.video_ice_local_candidate.setStringValue_('')
self.video_ice_remote_candidate.setStringValue_('')
self.video_rx_speed.setStringValue_('')
self.video_tx_speed.setStringValue_('')
def resetChat(self):
self.chat_remote_endpoint.setStringValue_('')
self.chat_connection_mode.setStringValue_('')
def updatePanelValues(self):
self.updateSession()
def updateSession(self):
if self.sessionController is None:
self.resetSession()
else:
self.updateSessionStatus()
self.remote_party.setStringValue_(self.sessionController.getTitleFull())
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, str(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()
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.encode('utf-8').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)
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_graph.setDataQueue_needsDisplay_(self.audio_stream.loss_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)
self.audio_packet_loss.setStringValue_('%.1f %%' % self.audio_stream.statistics['loss'] if self.audio_stream.statistics['loss'] else '')
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.stream.srtp_active else True)
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:
if self.audio_stream.stream.local_rtp_candidate is not None:
try:
candidate = ice_candidates[self.audio_stream.stream.local_rtp_candidate.type.lower()]
except KeyError:
candidate = self.audio_stream.stream.local_rtp_candidate.type.capitalize()
else:
candidate = ''
self.audio_ice_local_candidate.setStringValue_(candidate)
if self.audio_stream.stream.remote_rtp_candidate is not None:
try:
candidate = ice_candidates[self.audio_stream.stream.remote_rtp_candidate.type.lower()]
except KeyError:
candidate = self.audio_stream.stream.remote_rtp_candidate.type.capitalize()
else:
candidate = ''
self.audio_ice_remote_candidate.setStringValue_(candidate)
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':
ice_status += ' ('+ NSLocalizedString("Peer to Peer", "Label")+')'
else:
ice_status += ' ('+ NSLocalizedString("Server Relayed", "Label") + ')'
else:
self.audio_ice_local_candidate.setStringValue_('')
self.audio_ice_remote_candidate.setStringValue_('')
ice_status = self.audio_stream.ice_negotiation_status if self.audio_stream.ice_negotiation_status is not None else ''
self.audio_ice_negotiation.setStringValue_(ice_status)
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.clock_rate:
codec = beautify_video_codec(self.video_stream.stream.codec)
try:
settings = SIPSimpleSettings()
sample_rate = self.video_stream.stream.clock_rate/1000
codec = codec + " %0.fkHz" % sample_rate
except TypeError:
pass
self.video_codec.setStringValue_(codec)
self.video_srtp_lock.setHidden_(False if self.video_stream.stream.srtp_active else True)
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:
if self.video_stream.stream.local_rtp_candidate is not None:
try:
candidate = ice_candidates[self.video_stream.stream.local_rtp_candidate.type.lower()]
except KeyError:
candidate = self.video_stream.stream.local_rtp_candidate.type.capitalize()
else:
candidate = ''
self.video_ice_local_candidate.setStringValue_(candidate)
if self.video_stream.stream.remote_rtp_candidate is not None:
try:
candidate = ice_candidates[self.video_stream.stream.remote_rtp_candidate.type.lower()]
except KeyError:
candidate = self.video_stream.stream.remote_rtp_candidate.type.capitalize()
else:
candidate = ''
self.video_ice_remote_candidate.setStringValue_(candidate)
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':
ice_status += ' ('+ NSLocalizedString("Peer to Peer", "Label")+')'
else:
ice_status += ' ('+ NSLocalizedString("Server Relayed", "Label") + ')'
else:
self.video_ice_local_candidate.setStringValue_('')
self.video_ice_remote_candidate.setStringValue_('')
ice_status = self.video_stream.ice_negotiation_status if self.video_stream.ice_negotiation_status is not None else ''
self.video_ice_negotiation.setStringValue_(ice_status)
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()
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 = datetime.datetime(*time.localtime()[:6])
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 = u"%02i:%02i:%02i"%(h,m,s)
self.duration.setStringValue_(text)
else:
self.duration.setStringValue_('')
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:
title = NSLocalizedString("Active", "Label")
if self.audio_stream.stream.srtp_active:
title = title + ' ' + NSLocalizedString("Encrypted", "Label")
title = title + ' (SDES)'
self.audio_status.setStringValue_(title)
else:
self.audio_status.setStringValue_("")
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:
title = NSLocalizedString("Active", "Label")
if self.video_stream.stream.srtp_active:
title = title + ' ' + NSLocalizedString("Encrypted", "Label")
title = title + ' (SDES)'
self.video_status.setStringValue_(title)
else:
self.video_status.setStringValue_("")
def _NH_BlinkSessionGotRingIndication(self, notification):
self.updateSessionStatus(sub_state=NSLocalizedString("Ringing...", "Label"))
def _NH_BlinkSessionGotProvisionalResponse(self, notification):
self.updateSessionStatus(sub_state=notification.data.reason)
def _NH_BlinkSessionDidProcessTransaction(self, notification):
self.updateSessionStatus()
def _NH_BlinkSentAddProposal(self, notification):
self.updateSessionStatus()
def _NH_BlinkSentRemoveProposal(self, notification):
self.updateSessionStatus()
def _NH_BlinkGotProposal(self, notification):
self.updateSessionStatus()
def _NH_BlinkProposalGotRejected(self, notification):
self.updateSessionStatus()
def _NH_BlinkStreamHandlersChanged(self, notification):
self.updatePanelValues()
def _NH_BlinkSessionWillStart(self, notification):
self.updatePanelValues()
def _NH_BlinkSessionDidStart(self, notification):
self.add_audio_stream()
self.add_video_stream()
self.add_chat_stream()
self.updatePanelValues()
def _NH_BlinkSessionDidEnd(self, notification):
self.stopTimer()
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
@run_in_gui_thread
def _NH_AudioStreamICENegotiationDidFail(self, notification):
if 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 '')
@run_in_gui_thread
def _NH_AudioStreamICENegotiationDidSucceed(self, notification):
if 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 '')
@run_in_gui_thread
def _NH_VideoStreamICENegotiationDidFail(self, notification):
if 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 '')
@run_in_gui_thread
def _NH_VideoStreamICENegotiationDidSucceed(self, notification):
if 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 '')
def _NH_AudioStreamDidChangeHoldState(self, notification):
self.updateAudioStatus()
def show(self):
self.window.orderFront_(None)
def hide(self):
self.window.orderOut_(None)
def toggle(self):
if self.window.isVisible():
self.hide()
else:
self.show()
def windowShouldClose_(self, sender):
self.window.orderOut_(None)
def close(self):
self.stopTimer()
self.remove_session()
self.window.orderOut_(None)
def stopTimer(self):
if self.timer:
self.timer.invalidate()
self.timer = None
def dealloc(self):
self.audio_packet_loss_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()
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 = 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
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)