@@ -35,6 +35,7 @@ import { MdnsIntroducer } from "./mdns-introducer";
3535import { PropertyElement , DataSchema , ActionElement , EventElement } from "wot-thing-description-types" ;
3636import { CoapServerConfig } from "./coap" ;
3737import { DataSchemaValue } from "wot-typescript-definitions" ;
38+ import { filterPropertyObserveOperations , getPropertyOpValues } from "./util" ;
3839
3940const { debug, warn, info, error } = createLoggers ( "binding-coap" , "coap-server" ) ;
4041
@@ -233,27 +234,42 @@ export default class CoapServer implements ProtocolServer {
233234 private addFormToAffordance ( form : TD . Form , affordance : AffordanceElement ) : void {
234235 const affordanceForms = affordance . forms ;
235236 if ( affordanceForms == null ) {
236- affordance . forms ?? = [ form ] ;
237+ affordance . forms = [ form ] ;
237238 } else {
238239 affordanceForms . push ( form ) ;
239240 }
240241 }
241242
242243 private fillInPropertyBindingData ( thing : ExposedThing , base : string , offeredMediaType : string ) {
243244 for ( const [ propertyName , property ] of Object . entries ( thing . properties ) ) {
244- const opValues = ProtocolHelpers . getPropertyOpValues ( property ) ;
245- const form = this . createAffordanceForm (
246- base ,
247- this . PROPERTY_DIR ,
248- offeredMediaType ,
249- opValues ,
250- thing . uriVariables ,
251- propertyName ,
252- property . uriVariables
253- ) ;
245+ const [ readWriteOpValues , observeOpValues ] = getPropertyOpValues ( property ) ;
246+ for ( const formOpValues of [ observeOpValues , readWriteOpValues ] ) {
247+ if ( formOpValues . length === 0 ) {
248+ continue ;
249+ }
254250
255- this . addFormToAffordance ( form , property ) ;
256- this . logHrefAssignment ( form , "Property" , propertyName ) ;
251+ let subprotocol : string | undefined ;
252+
253+ const observeOpValues = filterPropertyObserveOperations ( formOpValues ) ;
254+
255+ if ( observeOpValues . length > 0 ) {
256+ subprotocol = "cov:observe" ;
257+ }
258+
259+ const form = this . createAffordanceForm (
260+ base ,
261+ this . PROPERTY_DIR ,
262+ offeredMediaType ,
263+ formOpValues ,
264+ thing . uriVariables ,
265+ propertyName ,
266+ property . uriVariables ,
267+ subprotocol
268+ ) ;
269+
270+ this . addFormToAffordance ( form , property ) ;
271+ this . logHrefAssignment ( form , "Property" , propertyName ) ;
272+ }
257273 }
258274 }
259275
@@ -283,7 +299,8 @@ export default class CoapServer implements ProtocolServer {
283299 [ "subscribeevent" , "unsubscribeevent" ] ,
284300 thing . uriVariables ,
285301 eventName ,
286- event . uriVariables
302+ event . uriVariables ,
303+ "cov:observe"
287304 ) ;
288305
289306 this . addFormToAffordance ( form , event ) ;
@@ -298,7 +315,8 @@ export default class CoapServer implements ProtocolServer {
298315 opValues : string | string [ ] ,
299316 thingUriVariables : PropertyElement [ "uriVariables" ] ,
300317 affordanceName ?: string ,
301- affordanceUriVariables ?: PropertyElement [ "uriVariables" ]
318+ affordanceUriVariables ?: PropertyElement [ "uriVariables" ] ,
319+ subprotocol ?: string
302320 ) : TD . Form {
303321 const affordanceNamePattern = Helpers . updateInteractionNameWithUriVariablePattern (
304322 affordanceName ?? "" ,
@@ -314,6 +332,7 @@ export default class CoapServer implements ProtocolServer {
314332
315333 const form = new TD . Form ( href , offeredMediaType ) ;
316334 form . op = opValues ;
335+ form . subprotocol = subprotocol ;
317336
318337 return form ;
319338 }
0 commit comments