diff --git a/lib/src/binding_coap/coap_client.dart b/lib/src/binding_coap/coap_client.dart index d3c3777f..424507ab 100644 --- a/lib/src/binding_coap/coap_client.dart +++ b/lib/src/binding_coap/coap_client.dart @@ -96,7 +96,7 @@ class CoapClient extends ProtocolClient { final ClientSecurityProvider? _clientSecurityProvider; Future _createRequest( - coap.CoapCode code, + coap.RequestMethod requestMethod, Uri uri, { Content? content, coap.CoapMediaType? format, @@ -109,7 +109,7 @@ class CoapClient extends ProtocolClient { payload.addAll((await content.byteBuffer).asUint8List()); } - final request = coap.CoapRequest(code) + final request = coap.CoapRequest(requestMethod) ..payload = payload ..uriPath = uri.path ..accept = accept @@ -145,7 +145,7 @@ class CoapClient extends ProtocolClient { // limitations of the CoAP library Future _sendRequest( Uri uri, - coap.CoapCode method, { + coap.RequestMethod method, { Content? content, required Form? form, coap.CoapMediaType? format, @@ -156,7 +156,7 @@ class CoapClient extends ProtocolClient { }) async { final coapClient = coap.CoapClient( uri, - _InternalCoapConfig(_coapConfig ?? CoapConfig(), form), + config: _InternalCoapConfig(_coapConfig ?? CoapConfig(), form), pskCredentialsCallback: _createPskCallback(uri, form, _clientSecurityProvider), ); @@ -199,7 +199,7 @@ class CoapClient extends ProtocolClient { Future _sendDiscoveryRequest( Uri uri, - coap.CoapCode method, { + coap.RequestMethod method, { Content? content, required Form? form, coap.CoapMediaType? format, @@ -240,7 +240,7 @@ class CoapClient extends ProtocolClient { final coapClient = coap.CoapClient( creationHintUri, - _InternalCoapConfig(_coapConfig ?? CoapConfig(), form), + config: _InternalCoapConfig(_coapConfig ?? CoapConfig(), form), ); final response = await coapClient.send(request); @@ -314,7 +314,7 @@ class CoapClient extends ProtocolClient { final client = coap.CoapClient( request.uri.replace(scheme: 'coaps'), - coap.CoapConfigTinydtls(), + config: coap.CoapConfigTinydtls(), pskCredentialsCallback: (identityHint) => pskCredentials, ); @@ -429,14 +429,12 @@ class CoapClient extends ProtocolClient { final coapClient = coap.CoapClient( form.resolvedHref, - _InternalCoapConfig(_coapConfig ?? CoapConfig(), form), + config: _InternalCoapConfig(_coapConfig ?? CoapConfig(), form), ); if (subprotocol == CoapSubprotocol.observe) { final observeClientRelation = await coapClient.observe(request); - observeClientRelation.stream.listen((event) { - handleResponse(event.resp); - }); + observeClientRelation.listen(handleResponse); return CoapSubscription(coapClient, observeClientRelation, complete); } @@ -460,7 +458,7 @@ class CoapClient extends ProtocolClient { final streamController = StreamController(); final multicastResponseHandler = coap.CoapMulticastResponseHandler( (data) { - streamController.add(data.resp.determineDiscoveryContent(uri.scheme)); + streamController.add(data.determineDiscoveryContent(uri.scheme)); }, onError: streamController.addError, onDone: () async { @@ -470,7 +468,7 @@ class CoapClient extends ProtocolClient { final content = _sendDiscoveryRequest( uri, - coap.CoapCode.get, + coap.RequestMethod.get, form: null, accept: coap.CoapMediaType.applicationTdJson, multicastResponseHandler: multicastResponseHandler, @@ -485,7 +483,7 @@ class CoapClient extends ProtocolClient { ) async* { yield await _sendDiscoveryRequest( uri, - coap.CoapCode.get, + coap.RequestMethod.get, form: null, accept: coap.CoapMediaType.applicationTdJson, ); @@ -496,8 +494,7 @@ class CoapClient extends ProtocolClient { Uri uri, { bool disableMulticast = false, }) async* { - final config = CoapConfigDefault(); - final client = coap.CoapClient(uri, config); + final client = coap.CoapClient(uri); if (uri.isMulticastAddress) { if (!disableMulticast) { @@ -517,7 +514,7 @@ class CoapClient extends ProtocolClient { if (uri.isMulticastAddress) { multicastResponseHandler = coap.CoapMulticastResponseHandler( (data) { - streamController.add(data.resp.determineDiscoveryContent(uri.scheme)); + streamController.add(data.determineDiscoveryContent(uri.scheme)); }, onError: streamController.addError, onDone: () async { @@ -528,7 +525,7 @@ class CoapClient extends ProtocolClient { final content = await _sendDiscoveryRequest( uri, - coap.CoapCode.get, + coap.RequestMethod.get, form: null, accept: coap.CoapMediaType.applicationLinkFormat, multicastResponseHandler: multicastResponseHandler, diff --git a/lib/src/binding_coap/coap_definitions.dart b/lib/src/binding_coap/coap_definitions.dart index f08270ec..721ecf46 100644 --- a/lib/src/binding_coap/coap_definitions.dart +++ b/lib/src/binding_coap/coap_definitions.dart @@ -18,31 +18,31 @@ final coapPrefixMapping = /// Defines the available CoAP request methods. enum CoapRequestMethod { /// Corresponds with the GET request method. - get(CoapCode.get), + get(RequestMethod.get), /// Corresponds with the PUT request method. - put(CoapCode.put), + put(RequestMethod.put), /// Corresponds with the POST request method. - post(CoapCode.post), + post(RequestMethod.post), /// Corresponds with the DELETE request method. - delete(CoapCode.delete), + delete(RequestMethod.delete), /// Corresponds with the FETCH request method. - fetch(CoapCode.fetch), + fetch(RequestMethod.fetch), /// Corresponds with the PATCH request method. - patch(CoapCode.patch), + patch(RequestMethod.patch), /// Corresponds with the iPATCH request method. - ipatch(CoapCode.ipatch); + ipatch(RequestMethod.ipatch); /// Constructor const CoapRequestMethod(this.code); /// The numeric code of this [CoapRequestMethod]. - final CoapCode code; + final RequestMethod code; static final _registry = HashMap.fromEntries( values.map((e) => MapEntry(e.code.description, e)), diff --git a/lib/src/binding_coap/coap_extensions.dart b/lib/src/binding_coap/coap_extensions.dart index 00c2b07d..dc703970 100644 --- a/lib/src/binding_coap/coap_extensions.dart +++ b/lib/src/binding_coap/coap_extensions.dart @@ -178,9 +178,9 @@ extension ResponseExtension on CoapResponse { AuthServerRequestCreationHint? get creationHint { const unauthorizedAceCodes = [ // TODO: Should other response codes be included as well? - CoapCode.unauthorized, - CoapCode.methodNotAllowed, - CoapCode.forbidden, + ResponseCode.unauthorized, + ResponseCode.methodNotAllowed, + ResponseCode.forbidden, ]; final responsePayload = payload; diff --git a/lib/src/core/codecs/link_format_codec.dart b/lib/src/core/codecs/link_format_codec.dart index f7481aaf..45b9b399 100644 --- a/lib/src/core/codecs/link_format_codec.dart +++ b/lib/src/core/codecs/link_format_codec.dart @@ -24,7 +24,7 @@ class LinkFormatCodec extends ContentCodec { ) { // TODO(JKRhb): The question which value types are allowed needs to be // revisited. - if (value is CoapIResource) { + if (value is CoapResource) { return Uint8List.fromList(CoapLinkFormat.serialize(value).codeUnits) .buffer; }