Skip to content

Commit

Permalink
fixed send on server unary decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
iangeckeler committed Aug 6, 2019
1 parent 175d10c commit 47015f7
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 18 deletions.
7 changes: 4 additions & 3 deletions examples/firecomm/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ const firecomm = require("../../index");

let certificate = path.join(__dirname, "/server.crt");

const stub = new firecomm.Stub(routeguide.RouteGuide, "localhost:3000", {
certificate
});
const stub = new firecomm.Stub(routeguide.RouteGuide, "localhost:3000");
// {
// certificate
// }

// stub.openChannel('localhost:3000');

Expand Down
23 changes: 14 additions & 9 deletions examples/firecomm/methodHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ const grpc = require("grpc");
function unaryChat(ctx) {
// ctx.setStatus({'trailer': 'value'});
// ctx.throw(new Error('custom error message'));
console.log(ctx.metadata);
console.log(ctx.body);
// console.log(ctx.metadata);
// console.log(ctx.body);
console.log({ ctx });
ctx.on(data => console.log({ data }));
ctx.set({ hello: "world" });
ctx.send({ message: "message body" });
// ctx.setTrailer({'hello': 'trailer'})
// ctx.setMeta({'hello': 'world'})
// ctx.send({message: 'what\'s up'});
throw new Error("uncaught error");
// throw new Error("uncaught error");
}

function serverStream(context) {
Expand All @@ -17,19 +21,20 @@ function serverStream(context) {

function clientStream(context) {
// console.log('serverStream context: ', context);
context.on('data', data => {console.log(data)});
context.send({message: 'world'})
}

context.on("data", data => {
console.log(data);
});
context.send({ message: "world" });
}

function bidiChat(context) {
// console.log('context', context);
// console.log('context keys', Object.keys(context));
// console.log('context proto', context.__proto__)

context.on('data', data => {
context.on("data", data => {
// console.log('data:', data);
context.write({message: data.message + ' World'});
context.write({ message: data.message + " World" });
});
context.throw(new Error("error"));
setTimeout(() => {
Expand Down
9 changes: 5 additions & 4 deletions examples/firecomm/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ server.addService(

// {private_key: (__dirname + '/server.crt'), certificate: (__dirname +
// '/server.key')}
server.bind("0.0.0.0:3000", {
privateKey: __dirname + "/server.key",
certificate: __dirname + "/server.crt"
});
server.bind("0.0.0.0:3000");
// {
// privateKey: __dirname + "/server.key",
// certificate: __dirname + "/server.crt"
// }
// console.log({server})
// console.log(new grpc.Server().__proto__)

Expand Down
4 changes: 2 additions & 2 deletions lib/callFactories/callDecorators/serverUnaryDecorator.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ module.exports = function serverUnaryDecorator(customCall, sendCallback) {
customCall.metadata = undefined;
customCall.sendCallback = sendCallback;

customCall.send = function(message) {
customCall.send = function(message, flags) {
if (this.metadata) {
this.sendMetadata(this.metadata);
}
this.sendCallback(undefined);
this.sendCallback(null, message, null, flags);
};

customCall.set = function(object) {
Expand Down

0 comments on commit 47015f7

Please sign in to comment.