-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·100 lines (72 loc) · 2.34 KB
/
index.js
File metadata and controls
executable file
·100 lines (72 loc) · 2.34 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
var io = require('socket.io')
var FacebookClient = require('facebook-client').FacebookClient;
var facebook = new FacebookClient();
var uuid = require('node-uuid');
var _debug = false;
function setup_sockets() {
// create a socket.io backend for sending facebook graph data
// to the browser as we receive it
io = require('socket.io').listen(app);
// wrap socket.io with basic identification and message queueing
// code is in lib/socket_manager.js
socket_manager = require('./lib/socket_manager').create(io);
// use xhr-polling as the transport for socket.io
io.configure(function () {
io.set("transports", ["xhr-polling"]);
io.set("polling duration", 10);
io.set('log level', 0);
});
};
exports.init = function initFbApi () {
setup_sockets();
if(_debug) console.log('FB-API: Started')
railway.tools.fbapi =
{
friends: function (request,_args){
if (request.session.auth) {
var token = request.session.auth.facebook.accessToken;
if(!_args) {
var socket_id = uuid();
}
facebook.getSessionByAccessToken(token)(function(session) {
session.graphCall('/me/friends')(function(result) {
if(_args) {_args(result);return 0;}
else
{
result.data.forEach(function(friend) {
console.log('Emiting socket, uuid: '+socket_id);
socket_manager.send(socket_id, 'friend', friend);
});
}
});
});
if(!_args) return socket_id;
}
else {
if(_debug) console.log('FB-API: Not logged in Facebook!'); return "undefined";
}
}
};
};
/* Implementation Notes
Two paths :
action: function (request,_args){
// Commmon PreConds
function sync(cb)
{
//Sync Process (with cb)
};
function async()
{
//Async Process
}
return _args == null ? async() : sync(_args); //Args check
}
--
Small variations :
action: function (request,_args){
if(!_args) {.. modifiers}
if(_args) {_args(result);return 0;}
if(!_args) return socket_id;
}
*/