now sends messages correctly
This commit is contained in:
parent
850032bd03
commit
317a9f2189
5
dist/smartuniverse.classes.universe.js
vendored
5
dist/smartuniverse.classes.universe.js
vendored
@ -41,11 +41,14 @@ class Universe {
|
|||||||
port: portArg
|
port: portArg
|
||||||
});
|
});
|
||||||
// route handling
|
// route handling
|
||||||
|
// adds messages
|
||||||
const addMessageHandler = new smartexpress_1.Handler('PUT', request => {
|
const addMessageHandler = new smartexpress_1.Handler('PUT', request => {
|
||||||
const requestBody = request.body;
|
const requestBody = request.body;
|
||||||
this.universeStore.addMessage(requestBody.message, requestBody.payload);
|
this.universeStore.addMessage(requestBody.message, requestBody.payload);
|
||||||
|
console.log(requestBody);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
// gets messages
|
||||||
const readMessageHandler = new smartexpress_1.Handler('GET', request => {
|
const readMessageHandler = new smartexpress_1.Handler('GET', request => {
|
||||||
const requestBody = request.body;
|
const requestBody = request.body;
|
||||||
this.universeStore.readMessagesYoungerThan(requestBody.since);
|
this.universeStore.readMessagesYoungerThan(requestBody.since);
|
||||||
@ -63,4 +66,4 @@ class Universe {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.Universe = Universe;
|
exports.Universe = Universe;
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnR1bml2ZXJzZS5jbGFzc2VzLnVuaXZlcnNlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnR1bml2ZXJzZS5jbGFzc2VzLnVuaXZlcnNlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7QUFBQSxtREFBbUQ7QUFFbkQsK0NBQXNEO0FBRXRELG1GQUFrRTtBQUVsRSwrRkFBc0U7QUFDdEUsK0NBQStDO0FBZS9DO0lBVUUsSUFBWSxlQUFlO1FBQ3pCLEVBQUUsQ0FBQyxDQUFDLElBQUksQ0FBQyxv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ssRUFBRSxDQUFDO1FBQ3hDLENBQUM7S0FBQTtJQUVZLFVBQVU7O1lBQ3JCLE1BQU0sSUFBSSxDQUFDLGtCQUFrQixDQUFDLElBQUksRUFBRSxDQUFDO1FBQ3ZDLENBQUM7S0FBQTtDQUNGO0FBakVELDRCQWlFQyJ9
|
@ -4,6 +4,6 @@ export interface IClientOptions {
|
|||||||
export declare class UniverseClient {
|
export declare class UniverseClient {
|
||||||
options: any;
|
options: any;
|
||||||
constructor(optionsArg: IClientOptions);
|
constructor(optionsArg: IClientOptions);
|
||||||
sendMessage(message: any, messagePayload: any): void;
|
sendMessage(messageArg: any, payloadArg: any): Promise<void>;
|
||||||
getMessageObservable(): void;
|
getMessageObservable(): void;
|
||||||
}
|
}
|
||||||
|
22
dist/smartuniverse.classes.universeclient.js
vendored
22
dist/smartuniverse.classes.universeclient.js
vendored
@ -1,17 +1,31 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||||
|
return new (P || (P = Promise))(function (resolve, reject) {
|
||||||
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||||
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||||
|
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
||||||
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
|
});
|
||||||
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const plugins = require("./smartuniverse.plugins");
|
const plugins = require("./smartuniverse.plugins");
|
||||||
class UniverseClient {
|
class UniverseClient {
|
||||||
constructor(optionsArg) {
|
constructor(optionsArg) {
|
||||||
this.options = optionsArg;
|
this.options = optionsArg;
|
||||||
}
|
}
|
||||||
sendMessage(message, messagePayload) {
|
sendMessage(messageArg, payloadArg) {
|
||||||
plugins.smartrequest.post(this.options.serverAddress, {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
requestBody: messagePayload
|
const requestBody = {
|
||||||
|
message: messageArg,
|
||||||
|
payload: payloadArg
|
||||||
|
};
|
||||||
|
yield plugins.smartrequest.post(this.options.serverAddress, {
|
||||||
|
requestBody: requestBody
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
getMessageObservable() {
|
getMessageObservable() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.UniverseClient = UniverseClient;
|
exports.UniverseClient = UniverseClient;
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnR1bml2ZXJzZS5jbGFzc2VzLnVuaXZlcnNlY2xpZW50LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnR1bml2ZXJzZS5jbGFzc2VzLnVuaXZlcnNlY2xpZW50LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsbURBQW1EO0FBU25EO0lBR0UsWUFBWSxVQUEwQjtRQUNwQyxJQUFJLENBQUMsT0FBTyxHQUFHLFVBQVUsQ0FBQztJQUM1QixDQUFDO0lBRU0sV0FBVyxDQUFDLE9BQU8sRUFBRSxjQUFjO1FBQ3hDLE9BQU8sQ0FBQyxZQUFZLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUMsYUFBYSxFQUFFO1lBQ3BELFdBQVcsRUFBRSxjQUFjO1NBQzVCLENBQUMsQ0FBQTtJQUNKLENBQUM7SUFFTSxvQkFBb0I7SUFFM0IsQ0FBQztDQUNGO0FBaEJELHdDQWdCQyJ9
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnR1bml2ZXJzZS5jbGFzc2VzLnVuaXZlcnNlY2xpZW50LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnR1bml2ZXJzZS5jbGFzc2VzLnVuaXZlcnNlY2xpZW50LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7QUFBQSxtREFBbUQ7QUFTbkQ7SUFHRSxZQUFZLFVBQTBCO1FBQ3BDLElBQUksQ0FBQyxPQUFPLEdBQUcsVUFBVSxDQUFDO0lBQzVCLENBQUM7SUFFWSxXQUFXLENBQUMsVUFBVSxFQUFFLFVBQVU7O1lBQzdDLE1BQU0sV0FBVyxHQUFHO2dCQUNsQixPQUFPLEVBQUUsVUFBVTtnQkFDbkIsT0FBTyxFQUFFLFVBQVU7YUFDcEIsQ0FBQTtZQUNELE1BQU0sT0FBTyxDQUFDLFlBQVksQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQyxhQUFhLEVBQUU7Z0JBQzFELFdBQVcsRUFBRSxXQUFXO2FBQ3pCLENBQUMsQ0FBQTtRQUNKLENBQUM7S0FBQTtJQUVNLG9CQUFvQjtJQUUzQixDQUFDO0NBQ0Y7QUFwQkQsd0NBb0JDIn0=
|
@ -18,11 +18,17 @@ tap.test('add a message to the SmartUniverse', async () => {
|
|||||||
// testing message handling
|
// testing message handling
|
||||||
tap.test('create smartuniverse client', async () => {
|
tap.test('create smartuniverse client', async () => {
|
||||||
testUniverseClient = new smartuniverse.UniverseClient({
|
testUniverseClient = new smartuniverse.UniverseClient({
|
||||||
serverAddress: 'localhost:8765'
|
serverAddress: 'http://localhost:8765'
|
||||||
});
|
});
|
||||||
expect(testUniverseClient).to.be.instanceof(smartuniverse.UniverseClient)
|
expect(testUniverseClient).to.be.instanceof(smartuniverse.UniverseClient)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
tap.test('should send a message correctly', async () => {
|
||||||
|
await testUniverseClient.sendMessage('greeting', {
|
||||||
|
anyBool: true
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
tap.test('should end the server correctly', async () => {
|
tap.test('should end the server correctly', async () => {
|
||||||
await testUniverse.stopServer();
|
await testUniverse.stopServer();
|
||||||
})
|
})
|
||||||
|
@ -61,11 +61,15 @@ export class Universe {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// route handling
|
// route handling
|
||||||
|
// adds messages
|
||||||
const addMessageHandler = new Handler('PUT', request => {
|
const addMessageHandler = new Handler('PUT', request => {
|
||||||
const requestBody = request.body;
|
const requestBody = request.body;
|
||||||
this.universeStore.addMessage(requestBody.message, requestBody.payload);
|
this.universeStore.addMessage(requestBody.message, requestBody.payload);
|
||||||
|
console.log(requestBody);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// gets messages
|
||||||
const readMessageHandler = new Handler('GET', request => {
|
const readMessageHandler = new Handler('GET', request => {
|
||||||
const requestBody = request.body;
|
const requestBody = request.body;
|
||||||
this.universeStore.readMessagesYoungerThan(requestBody.since);
|
this.universeStore.readMessagesYoungerThan(requestBody.since);
|
||||||
|
@ -14,9 +14,13 @@ export class UniverseClient {
|
|||||||
this.options = optionsArg;
|
this.options = optionsArg;
|
||||||
}
|
}
|
||||||
|
|
||||||
public sendMessage(message, messagePayload) {
|
public async sendMessage(messageArg, payloadArg) {
|
||||||
plugins.smartrequest.post(this.options.serverAddress, {
|
const requestBody = {
|
||||||
requestBody: messagePayload
|
message: messageArg,
|
||||||
|
payload: payloadArg
|
||||||
|
}
|
||||||
|
await plugins.smartrequest.post(this.options.serverAddress, {
|
||||||
|
requestBody: requestBody
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user