@@ -128,7 +128,7 @@ public enum RequestType {
128
128
@ SuppressWarnings ("unused" )
129
129
private String imagingXAddr = "http://" + ipAddress + "/onvif/device_service" ;
130
130
private String ptzXAddr = "http://" + ipAddress + "/onvif/ptz_service" ;
131
- private String subscriptionXAddr = "http://" + ipAddress + "/onvif/device_service" ;
131
+ public String subscriptionXAddr = "http://" + ipAddress + "/onvif/device_service" ;
132
132
private boolean isConnected = false ;
133
133
private int mediaProfileIndex = 0 ;
134
134
private String rtspUri = "" ;
@@ -269,7 +269,7 @@ private String getXml(RequestType requestType) {
269
269
+ mediaProfileTokens .get (mediaProfileIndex )
270
270
+ "</ProfileToken><Translation><Zoom x=\" -0.0240506344\" xmlns=\" http://www.onvif.org/ver10/schema\" /></Translation></RelativeMove>" ;
271
271
case Renew :
272
- return "<Renew xmlns=\" http://docs.oasis-open.org/wsn/b-2\" ><TerminationTime>PT1M </TerminationTime></Renew>" ;
272
+ return "<Renew xmlns=\" http://docs.oasis-open.org/wsn/b-2\" ><TerminationTime>PT10S </TerminationTime></Renew>" ;
273
273
case GetConfigurations :
274
274
return "<GetConfigurations xmlns=\" http://www.onvif.org/ver20/ptz/wsdl\" ></GetConfigurations>" ;
275
275
case GetConfigurationOptions :
@@ -310,8 +310,8 @@ public void processReply(String message) {
310
310
logger .trace ("ONVIF reply is: {}" , message );
311
311
if (message .contains ("PullMessagesResponse" )) {
312
312
eventRecieved (message );
313
- } else if (message .contains ("RenewResponse" )) {
314
313
sendOnvifRequest (RequestType .PullMessages , subscriptionXAddr );
314
+ } else if (message .contains ("RenewResponse" )) {
315
315
} else if (message .contains ("GetSystemDateAndTimeResponse" )) {// 1st to be sent.
316
316
setIsConnected (true );// Instar profile T only cameras need this
317
317
parseDateAndTime (message );
@@ -380,6 +380,8 @@ public void processReply(String message) {
380
380
ipCameraHandler .rtspUri = rtspUri ;
381
381
}
382
382
}
383
+ } else {
384
+ logger .trace ("Unhandled ONVIF reply is: {}" , message );
383
385
}
384
386
}
385
387
@@ -568,7 +570,7 @@ public void sendOnvifRequest(RequestType requestType, String xAddr) {
568
570
569
571
@ Override
570
572
public void initChannel (SocketChannel socketChannel ) throws Exception {
571
- socketChannel .pipeline ().addLast ("idleStateHandler" , new IdleStateHandler (20 , 20 , 20 ));
573
+ socketChannel .pipeline ().addLast ("idleStateHandler" , new IdleStateHandler (0 , 0 , 18 ));
572
574
socketChannel .pipeline ().addLast ("HttpClientCodec" , new HttpClientCodec ());
573
575
socketChannel .pipeline ().addLast ("OnvifCodec" , new OnvifCodec (getHandle ()));
574
576
}
@@ -583,14 +585,14 @@ public void operationComplete(@Nullable ChannelFuture future) {
583
585
if (future == null ) {
584
586
return ;
585
587
}
586
- if (future .isSuccess ()) {
588
+ if (future .isDone () && future . isSuccess ()) {
587
589
Channel ch = future .channel ();
588
590
ch .writeAndFlush (request );
589
591
} else { // an error occurred
590
592
if (future .isDone () && !future .isCancelled ()) {
591
593
Throwable cause = future .cause ();
592
594
String msg = cause .getMessage ();
593
- logger .debug ("connect failed - cause {}" , cause .getMessage ());
595
+ logger .debug ("Connect failed - cause is: {}" , cause .getMessage ());
594
596
if (cause instanceof ConnectTimeoutException ) {
595
597
usingEvents = false ;// Prevent Unsubscribe from being sent
596
598
ipCameraHandler .cameraCommunicationError (
@@ -601,9 +603,8 @@ public void operationComplete(@Nullable ChannelFuture future) {
601
603
ipCameraHandler .cameraCommunicationError (
602
604
"Camera refused to connect when using ONVIF to port:" + port );
603
605
}
604
- }
605
- if (isConnected ) {
606
- disconnect ();
606
+ } else {
607
+ ipCameraHandler .cameraCommunicationError ("Camera failed to connect due to being cancelled" );
607
608
}
608
609
}
609
610
}
@@ -652,7 +653,7 @@ public void gotoPreset(int index) {
652
653
public void eventRecieved (String eventMessage ) {
653
654
String topic = Helper .fetchXML (eventMessage , "Topic" , "tns1:" );
654
655
if (topic .isEmpty ()) {
655
- sendOnvifRequest ( RequestType . Renew , subscriptionXAddr );
656
+ logger . debug ( "No ONVIF Events occured in the last 8 seconds" );
656
657
return ;
657
658
}
658
659
String dataName = Helper .fetchXML (eventMessage , "tt:Data" , "Name=\" " );
@@ -782,7 +783,6 @@ public void eventRecieved(String eventMessage) {
782
783
default :
783
784
logger .debug ("Please report this camera has an un-implemented ONVIF event. Topic: {}" , topic );
784
785
}
785
- sendOnvifRequest (RequestType .Renew , subscriptionXAddr );
786
786
}
787
787
788
788
public boolean supportsPTZ () {
0 commit comments