mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2026-01-19 03:11:30 +00:00
websocket online status discussion
This commit is contained in:
parent
16ecfab216
commit
91d0f9216a
@ -12,6 +12,7 @@ import { PubSub } from 'graphql-subscriptions'
|
||||
import Redis from 'ioredis'
|
||||
import bodyParser from 'body-parser'
|
||||
import { graphqlUploadExpress } from 'graphql-upload'
|
||||
import { randomInt } from 'crypto'
|
||||
|
||||
export const NOTIFICATION_ADDED = 'NOTIFICATION_ADDED'
|
||||
export const CHAT_MESSAGE_ADDED = 'CHAT_MESSAGE_ADDED'
|
||||
@ -59,14 +60,27 @@ export const context = async (options) => {
|
||||
}
|
||||
}
|
||||
|
||||
const webSocketList: Record<string,WebSocket> = {}
|
||||
|
||||
const createServer = (options?) => {
|
||||
const defaults = {
|
||||
context,
|
||||
schema: middleware(schema),
|
||||
subscriptions: {
|
||||
onConnect: (connectionParams, webSocket) => {
|
||||
const random = randomInt(9999)
|
||||
webSocket.identifier = `${connectionParams.authorization} ${random}`
|
||||
console.log('onConnect', webSocket.identifier)
|
||||
webSocketList[webSocket.identifier] = webSocket
|
||||
console.log('connected sockets: ', Object.keys(webSocketList).length)
|
||||
return getContext(connectionParams)
|
||||
},
|
||||
onDisconnect: (webSocket) => {
|
||||
console.log( 'onDisconnect', webSocket.identifier)
|
||||
delete webSocketList[webSocket.identifier]
|
||||
console.log('connected sockets: ', Object.keys(webSocketList).length)
|
||||
// console.log('onDisconnect', webSocket, webSocket.rawHeaders)
|
||||
},
|
||||
},
|
||||
debug: !!CONFIG.DEBUG,
|
||||
uploads: false,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user