-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
54 lines (45 loc) · 1.49 KB
/
index.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
import State from 'statesync'
import Actions from './libs/Actions.js'
import Socket from './libs/Socket.js'
import UserState from './libs/UserState'
import Authenticate from './libs/Authenticate'
import ServerState from './libs/ServerState'
const SOCKET_URL = 'https://socket.chips.gg'
const AUTHSERVER_URL = 'https://auth.chips.gg'
export default async (socketURL = SOCKET_URL, authURL = AUTHSERVER_URL) => {
const socket = await Socket(socketURL)
let actions = await Actions(socket)
// initialize server state, authenticate the user
const state = await ServerState(socket, actions)
let authenticated = await Authenticate(socket, actions)
// let userState = State({})
let userState = null
if (authenticated) {
userState = await UserState(socket, actions)
actions = await Actions(socket)
}
// reconnect and authenticate
socket.on('reconnect', async err => {
authenticated = await Authenticate(socket, actions)
})
// TODO: do somthing with this later...
actions.loginSteam = function() {
var token = localStorage.getItem('token')
window.location.href = `${authURL}/steam/auth?access_token=${token}`
}
actions.loginOpskins = function() {
var token = localStorage.getItem('token')
window.location.href = `${authURL}/opskins/auth?access_token=${token}`
}
actions.logout = function() {
localStorage.removeItem('token')
window.location.href = '/'
}
return {
_socket: socket,
state,
actions,
authenticated,
userState,
}
}