Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
contentFormat = ContentFormat.PlainText;
// fallthrough
case 'object':
if (response instanceof ArrayBuffer) {
response = session.createResponse(response, contentFormat);
}
break;
}
response.token = session.token;
if (!response.code) response.code = [2, 5];
if (!response.options) response.options = [];
if (session.confirmable && !session.response && !session.ackSent) {
response.type = Type.Ack;
response.messageId = session.messageId;
}
if (session._observeId) {
response.observeId = session.issueObserveId();
}
session.endpoint.send(response);
session.response = response;
}
(response, peer) => {
let request = this.findRequest(response);
let endpoint = this.endpoints[peer];
if (!request || !endpoint) {
this.transport.sendReset(response, peer);
return;
}
if (response.type == Type.Con) {
this.transport.sendAck(response, peer);
}
if (response.type === Type.Ack) {
if (!request['ack']) {
request['ack'] = Date.now();
if (request.onAck) {
request.onAck();
} else if (this.onAck) {
this.onAck(request);
}
endpoint.dequeue(request);
}
}
if (!isEmpty(response)) {
if (!request['response'] || request.observe) {
request['response'] = Date.now();