Total Complexity | 7 |
Complexity/F | 1.17 |
Lines of Code | 46 |
Function Count | 6 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | import feathers from 'feathers' |
||
2 | import feathersClient from 'feathers/client' |
||
3 | import feathersSocketIOclient from 'feathers-socketio/client' |
||
4 | import localSocketer from './feathers-socket' |
||
5 | import {SocketIO} from './mock-socket' |
||
6 | |||
7 | function localClient(url) { |
||
8 | const connection = new SocketIO(url) |
||
9 | // fool feathers into thinking it's socketio |
||
10 | connection.io = true |
||
11 | |||
12 | return feathersSocketIOclient(connection) |
||
13 | } |
||
14 | |||
15 | let instance = 8901 |
||
16 | |||
17 | export default function () { |
||
18 | const server = feathers() |
||
19 | const url = 'http://localtest:' + instance++ |
||
20 | |||
21 | server.configure(localSocketer(url)) |
||
22 | |||
23 | // Services can be bound late |
||
24 | |||
25 | // Manually call server setup method |
||
26 | server.setup() |
||
27 | |||
28 | return { |
||
29 | server, |
||
30 | getClient: (awaiting = true) => { |
||
31 | const client = feathersClient().configure(localClient(url)) |
||
32 | if (awaiting) { |
||
33 | return new Promise((resolve, reject) => { |
||
34 | client.io.on('connect', () => { |
||
35 | resolve(client) |
||
36 | }) |
||
37 | client.io.on('close', error => { |
||
38 | reject(error) |
||
39 | }) |
||
40 | }) |
||
41 | } |
||
42 | |||
43 | return client |
||
44 | } |
||
45 | } |
||
46 | } |
||
47 |