-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
162 lines (129 loc) · 5.58 KB
/
server.js
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end('Hello from Poker Node Server... :)');
}).listen(process.env.PORT || 8080);
// //# signalr-client
// //https://github.com/mwwhited/signalr-client-nodejs/tree/master/WhitedUS.SignalR/WhitedUS.signalR
// //By: [Matthew Whited](mailto:[email protected]?subject=signalr-client) (c) 2016
// // ## Usage
// var http = require('http');
// //### Create instance of signalR client
// //var signalR = require('signalr-client');
// var signalR = require('./signalr.js');
// var client = new signalR.client(
// "https://mppgs1mobile.valueactive.eu/pokerBabelFish", //signalR service URL
// ['TestHub'], // array of hubs to be supported in the connection
// 2, //optional: retry timeout in seconds (default: 10)
// true //optional: doNotStart default false
// );
// ////Use HTTP Proxy
// //client.proxy = {
// // host: "127.0.0.1",
// // port: "8888"
// //};
// ////Add Headers to HTTP Requests (this will be added to signalR negotiation and connect
// ////these now support a mergeable syntax
// //client.headers['X-MyTest-Header'] = 'Hello World!';
// //client.headers = {
// // 'X-Other-Header-1': 'Hello World 1',
// // 'X-Other-Header-2': 'Hello World 2'
// //};
// //client.headers['X-MyTest-Header'] = undefined; //Setting values to undefined will remove from from the collection
// //client.headers = {
// // 'X-Other-Header-1': undefined
// //};
// //console.log(client.headers);
// ////Add Variables to the connections query string
// //client.queryString.mVar1 = 'Hello World!';
// //client.queryString = {
// // mVar2: 'Hello World!',
// // mVar3: 'Hello World!'
// //};
// //client.queryString.mVar3 = undefined; // this works just like headers
// //### Binding callbacks from signalR hub
// ////#### Method pattern
// //client.on(
// // 'TestHub', // Hub Name (case insensitive)
// // 'addmessage', // Method Name (case insensitive)
// // function(name, message) { // Callback function with parameters matching call from hub
// // console.log("revc => " + name + ": " + message);
// // });
// //#### Direct pattern
// //If you bind directly to the hub handlers as show here any previous
// // handlers for that hub will be removed!
// client.handlers.testhub = { // hub name must be all lower case.
// addmessage: function(name, message) { // method name must be all lower case, function signature should match call from hub
// console.log("revc => " + name + ": " + message);
// }
// };
// //==== Optional function bindings to these names will allow for handling of these system events.
// client.serviceHandlers = { //Yep, I even added the merge syntax here.
// bound: function() { console.log("Websocket bound"); },
// connectFailed: function(error) { console.log("Websocket connectFailed: ", error); },
// connected: function(connection) { console.log("Websocket connected"); },
// disconnected: function() { console.log("Websocket disconnected"); },
// onerror: function (error) { console.log("Websocket onerror: ", error); },
// messageReceived: function (message) { console.log("Websocket messageReceived: ", message); return false; },
// bindingError: function (error) { console.log("Websocket bindingError: ", error); },
// connectionLost: function (error) { console.log("Connection Lost: ", error); },
// reconnecting: function (retry /* { inital: true/false, count: 0} */) {
// console.log("Websocket Retrying: ", retry);
// //return retry.count >= 3; /* cancel retry true */
// return true;
// }
// };
// //Handle Authentication
// client.serviceHandlers.onUnauthorized = function (res) {
// console.log("Websocket onUnauthorized:");
// //Do your Login Request
// var location = res.headers.location;
// var result = http.get(location, function (loginResult) {
// //Copy "set-cookie" to "client.header.cookie" for future requests
// client.headers.cookie = loginResult.headers['set-cookie'];
// });
// }
// //### Calling methods on the signalR hub
// //#### From the client instance
// setInterval(function () {
// console.log(client.state);
// client.invoke(
// 'TestHub', // Hub Name (case insensitive)
// 'Send', // Method Name (case insensitive)
// 'client', 'invoked from client' //additional parameters to match called signature
// );
// },2000);
// //#### From the hub instance
// setTimeout(function() {
// (function sendMessage() {
// console.log("Client State Code: ", client.state.code);
// console.log("Client State Description: ", client.state.desc);
// console.log("==>> try to get hub");
// var hub = client.hub('TestHub'); // Hub Name (case insensitive)
// // if not bound set the hub will be undefined
// if (!hub) {
// console.log("==>> hub not found. retry in 10 seconds");
// setTimeout(sendMessage, 10000);
// return;
// }
// console.log("==>> send message");
// hub.invoke(
// 'Send', // Method Name (case insensitive)
// 'hub', 'invoked from hub' //additional parameters to match called signature
// );
// })();
// },3000);
// console.log('Waiting!');
// process.stdin.resume();
// setTimeout(function() {
// // explicitly disconnect
// client.end();
// }, 1500);
// //Manually Start Client
// client.start();
// /*
// setTimeout(function() {
// console.log('Bye!');
// process.exit();
// }, 10000);
// */