use-go / onvif

full and enhanced onvif protocol stack in golang.
MIT License
384 stars 180 forks source link

Override endpoint url for Unsubscribe method #41

Closed zebox closed 7 months ago

zebox commented 7 months ago

Unsubscribe method use endpoint from response of Subscribe method in the SubscriptionReference->Address field (not root onvif endpoint). E.g. subscription endpoint: http://{onvif_ip_address}/onvif/Events/SubManager_20231117T152334Z_2.

Correct endpoint for Unsubscribe can be pass with request arg at Any field of event.Unsubscribe and override endpoint when method calls.

Simple example based on event example:

ep, err := cam.Subscribe(ctx, "http://{onvif_ip_address}:3030", onvifcam.TopicMotionAlarm, "2023-11-207T15:05:00.00000Z")
if err != nil {
    fmt.Printf("%v\n", err)
    return
}

// Unsubscribe with correct endpoint
req:=event.Unsubscribe{
    Any: string(ep.SubscriptionReference.Address),
}

res,err:=sevent.Call_Unsubscribe(ctx,c.d,req)
if err != nil {
    return "", fmt.Errorf("%s: %w", "Unsubscribe", err)
}

return string(res.Any), nil
tarancss commented 7 months ago

Simple example based on event example:

Please note that the example you refer to is for ONVIF Basic Notification Interface (WS-BaseNotification) for which the ONVIF protocol does not specify an Unsubscribe method, although it is specified in the web services spec.

The ONVIF Unsubscribe method applies to PullPointSubscriptions.

zebox commented 7 months ago

PullPointSubscriptions also required SubscriptionReference->Address for Unsubscribe. I have three different ONVIF cameras and they support Basic Subscription (web services spec) and Unsubscribe method as shown in the my example.

zebox commented 7 months ago

I found errors in other parts of code and this PR doesn't metter now. I will create issue for errors