CheckForUpdates
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
/osc/checkForUpdates
API 通过将客户端最近一次的已知 stateFingerprint
与相机的当前 fingerprint
进行比较来识别状态更新。
名称 |
类型 |
说明 |
stateFingerprint |
字符串 |
客户端上次调用 /osc/state 或 /osc/checkForUpdates 时的相机状态指纹。 |
waitTimeout |
整数(可选) |
在返回响应之前等待相机状态发生变化的秒数。waitTimeout 到期后,即使指纹没有更改,摄像头也应返回响应。如果在 waitTimeout 过期之前检测到状态变化,或者省略了 waitTimeout ,摄像头应立即返回响应。注意:即使指纹未更改,摄像头也可以在 waitTimeout 过期之前返回响应,但最佳实践是等待 waitTimeout 过期。 |
相机实现注意事项:
- 收到此调用后,相机会将其当前状态指纹与收到的
stateFingerprint
参数进行比较。如果指纹已更改,相机必须立即返回新的指纹。
输出
名称 |
类型 |
说明 |
stateFingerprint |
字符串 |
相机状态的新指纹(与 /osc/state API 中的相同)。 |
throttleTimeout |
整数 |
建议在下一次调用 checkForUpdates 之前等待的秒数。客户端可以在 throttleTimeout 到期之前发出请求,并且相机应尽可能允许这些提前的请求。 |
客户端实现注意事项:
- 收到响应后,客户端应将收到的
stateFingerprint
与其副本进行比较。如果不匹配,客户端应使用 _/osc/state
API 请求相机的当前状态。
- 无论相机响应如何,智能客户端都会限制请求。例如,如果相机返回非标准响应(立即返回没有变化且
throttleTimeout)
较低或为 0),那么客户端在从相机请求另一个 checkForUpdates
之前应强制实施自己的 throttleTimeout
。
相机实现注意事项:
- 在响应
checkForUpdates
时,相机应确定合理的 throttleTimeout
。如果相机支持长期请求逻辑(仅在状态未更改时在 waitTimeout
后响应),则可以作为 0
返回 throttleTimeout
。在此情况下,客户端可以立即请求更新。
- 如果相机仅支持快速响应(不推荐),则应返回合理的
throttleTimeout
,以避免来自客户端的持续请求/响应流量。例如,合理的 throttleTimeout
为 60 秒,以允许每分钟一个客户端请求。
- 最佳实践是返回适合相机功能的
throttleTimeout
。如果服务器因服务器问题而无法确定适当的 throttleTimeout
,相机应以 5XX 状态代码和包含 serverError
错误代码的 JSON 正文进行响应。
错误
错误代码 |
说明 |
missingParameter |
未指定 stateFingerprint 。 |
invalidParameterName |
一个或多个输入参数名称无法识别。 |
invalidParameterValue |
参数名称已被识别,但一个或多个值无效;例如,waitTimeout 超出范围或其类型不正确。 |
serverError |
服务器无法为其响应确定合适的 throttleTimeout 值。服务器问题由响应中返回的 5XX 值确定。相机制造商应提供一个 5XX 代码表,以及可能会引发此错误的相应服务器状态。 |
示例 |
请求 |
POST /osc/checkForUpdates HTTP/1.1
Host: [camera ip address]:[httpUpdatesPort]
Content-Type: application/json;charset=utf-8
Accept: application/jsonContent-Length: {CONTENT_LENGTH}
X-XSRF-Protected: 1
{
"stateFingerprint": "12EGA33",
"waitTimeout": 300
} |
答案 |
HTTP/1.1 200 OK
Content-Type: application/json;charset=utf-8
Content-Length: {CONTENT_LENGTH}
X-Content-Type-Options: nosniff
{
"stateFingerprint": "12EGA86",
"throttleTimeout": 60
} |
请求 |
POST /osc/checkForUpdates HTTP/1.1
Host: [camera ip address]:[httpUpdatesPort]
Content-Type: application/json;charset=utf-8
Accept: application/jsonContent-Length: {CONTENT_LENGTH}
X-XSRF-Protected: 1
{
"stateFingerprint": "12EGA33",
"waitTimeout": 300
} |
答案 |
HTTP/1.1 400 Bad Request
Content-Type: application/json;charset=utf-8
Content-Length: {CONTENT_LENGTH}
X-Content-Type-Options: nosniff
{
"name": "camera.checkForUpdates",
"state": "error",
"error": {
"code": "missingParameter",
"message": "parameter stateFingerprint is missing."
}
} |
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-25。
[null,null,["最后更新时间 (UTC):2025-07-25。"],[[["\u003cp\u003eThe \u003ccode\u003e/osc/checkForUpdates\u003c/code\u003e API allows clients to efficiently check for camera state changes without repeatedly requesting the full state.\u003c/p\u003e\n"],["\u003cp\u003eClients provide their last known state fingerprint, and the camera responds with a new fingerprint if the state has changed.\u003c/p\u003e\n"],["\u003cp\u003eA \u003ccode\u003ethrottleTimeout\u003c/code\u003e value is provided to guide clients on how frequently to check for updates, optimizing network traffic.\u003c/p\u003e\n"],["\u003cp\u003eIf the camera's state has not changed, it may wait for a specified \u003ccode\u003ewaitTimeout\u003c/code\u003e before responding to avoid unnecessary updates.\u003c/p\u003e\n"],["\u003cp\u003eErrors are provided if parameters are missing, invalid, or if the server encounters an issue determining an appropriate \u003ccode\u003ethrottleTimeout\u003c/code\u003e.\u003c/p\u003e\n"]]],["The `/osc/checkForUpdates` API checks for camera state changes. The client sends its `stateFingerprint` and an optional `waitTimeout`. The camera compares the received `stateFingerprint` with its current one, immediately returning the new fingerprint if changed. The camera also returns a `throttleTimeout` suggesting how long the client should wait before its next check. If the fingerprints match or after the wait time expires, a response is sent. Clients then request the current state if fingerprints don't match.\n"],null,["# CheckForUpdates\n\nThe `/osc/checkForUpdates` API identifies state updates by comparing the client's last known `stateFingerprint` to the camera's current `fingerprint`.\n\nInput\n-----\n\n| **Name** | **Type** | **Description** |\n|--------------------|--------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `stateFingerprint` | String | Camera state fingerprint from the last time the client called `/osc/state` or `/osc/checkForUpdates`. |\n| `waitTimeout` | Integer (optional) | Number of seconds to wait for state change on the camera to occur before returning the response. When `waitTimeout` expires, the camera should return a response even if the fingerprint hasn't changed. If a state change is detected before `waitTimeout` expires, or if `waitTimeout` is omitted, the camera should immediately return the response.**Note:** the camera can return a response before `waitTimeout` has expired even if the fingerprint hasn't changed, but the ***best practice*** is to wait until `waitTimeout` expires. |\n\n### Camera implementation notes:\n\n- Upon receiving this call, the camera compares its current state fingerprint with the received `stateFingerprint` parameter. If the fingerprint has changed, the camera must immediately return the new fingerprint.\n\nOutput\n------\n\n| **Name** | **Type** | **Description** |\n|--------------------|----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `stateFingerprint` | String | New fingerprint of the camera state (same as in `/osc/state` API). |\n| `throttleTimeout` | Integer | Recommended number of seconds for client to wait before next `checkForUpdates` call. Clients can make requests before `throttleTimeout` expires, and cameras should allow these early requests if possible. |\n\n### Client implementation notes:\n\n- Upon receiving a response, the client should compare the received `stateFingerprint` with its copy. If they don't match, the client should request the camera's current state using the `_/osc/state` API.\n- Smart clients will throttle requests regardless of the camera response. For example, if a camera returns a non-standard response (immediately, with *no change* and a low or 0 `throttleTimeout)`, the client should impose its own `throttleTimeout` before requesting another `checkForUpdates` from the camera.\n\n### Camera implementation notes:\n\n- When responding to `checkForUpdates`, the camera should determine a reasonable `throttleTimeout`. If the camera supports long standing request logic (respond only after `waitTimeout` if state hasn't changed), it is OK to return `throttleTimeout` as `0`. In this case, clients can immediately request updates.\n- If the camera supports only fast responses (*not recommended* ), it should return a reasonable `throttleTimeout` to avoid constant request/response traffic with the client. For example, a reasonable `throttleTimeout` would be 60 seconds, to allow one client request per minute.\n- The ***best practice*** is to return a `throttleTimeout` appropriate for the camera's capabilities. If the server cannot determine an appropriate `throttleTimeout` due to a server issue, the camera should respond with a 5XX status code and a JSON body containing `serverError` error code.\n\nError\n-----\n\n| **Error code** | **Description** |\n|-------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `missingParameter` | `stateFingerprint` is not specified. |\n| `invalidParameterName` | One or more input parameter names is unrecognized. |\n| `invalidParameterValue` | The parameter names are recognized, but one or more values is invalid; for example, `waitTimeout` is out of range or its type is incorrect. |\n| `serverError` | The server was unable to determine an appropriate `throttleTimeout` value for its response. The server problem will be identified by the 5XX value returned in the response. Camera manufacturers should supply a table of 5XX codes and corresponding server states that can throw this error. |\n\n| Example ------- ||\n|--------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| **Request** | ```http POST /osc/checkForUpdates HTTP/1.1 Host: [camera ip address]:[httpUpdatesPort] Content-Type: application/json;charset=utf-8 Accept: application/jsonContent-Length: {CONTENT_LENGTH} X-XSRF-Protected: 1 { \"stateFingerprint\": \"12EGA33\", \"waitTimeout\": 300 } ``` |\n| **Response** | ```http HTTP/1.1 200 OK Content-Type: application/json;charset=utf-8 Content-Length: {CONTENT_LENGTH} X-Content-Type-Options: nosniff { \"stateFingerprint\": \"12EGA86\", \"throttleTimeout\": 60 } ``` |\n| **Request** | ```http POST /osc/checkForUpdates HTTP/1.1 Host: [camera ip address]:[httpUpdatesPort] Content-Type: application/json;charset=utf-8 Accept: application/jsonContent-Length: {CONTENT_LENGTH} X-XSRF-Protected: 1 { \"stateFingerprint\": \"12EGA33\", \"waitTimeout\": 300 } ``` |\n| **Response** | ```http HTTP/1.1 400 Bad Request Content-Type: application/json;charset=utf-8 Content-Length: {CONTENT_LENGTH} X-Content-Type-Options: nosniff { \"name\": \"camera.checkForUpdates\", \"state\": \"error\", \"error\": { \"code\": \"missingParameter\", \"message\": \"parameter stateFingerprint is missing.\" } } ``` |"]]