-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
51 lines (43 loc) · 1.39 KB
/
index.js
File metadata and controls
51 lines (43 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**
*
* Sails hook socket protobuf
*
*/
module.exports = function (app) {
var builder = require("protobufjs").newBuilder(),
protoModels = {};
return {
//Default settings
defaults: {
protobuf: require('./lib/defaults'),
},
//Initialize
initialize: function (done) {
app.log.verbose("socket_protobuf: Initialize sails-hook-socket-protobuf");
if (!app.hooks.sockets) {
return done(new Error('Cannot use sails-hook-protobuf `sockets` hook without the `sockets` hook.'));
}
//load models
protoModels = require('./lib/loadProtoModels')(app, builder);
if (app.hooks.grunt) {
//Add extention script to frontend
require('./lib/injectFrontendFile')(app);
}
// If sockets is enabled, wait until the sockets hook is loaded
// before trying to attach our hook.
app.after('hook:sockets:loaded', function () {
//Ovverride socket IO methods to support protobuf encoding
require('./lib/overrideSocketIoMethods')(app, builder, protoModels);
//Ovverride sails-hook-socket-io methods to support protobuf encoding
require('./lib/overrideSocketMethods')(app, builder, protoModels);
});
// Wait for orm to be loaded
app.on('hook:orm:loaded', function () {
// Augment/override models to do a Pub/Sub encoding
require('./lib/augmentModels')(app, protoModels);
// Indicate that the hook is fully loaded
return done();
});
}
};
};