You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm not sure if this would be currently possible, but It would be nice to allow for the config to specify an initialisation Context, one that is available across the entire socket handling mechanism. This could be an expansion upon the current way that the logger is passed around, and its in fact just generalised to handle any shape of data, not only just a logger. So for example:
constcontext=createContext({ ... })// Returns the shape of something like `{ logger: Logger } & UserDefinedContext`attachSockets({
io,target: server,config: socketConfig,
actions,
context,});
Furthermore, it could be useful to add client-specific contexts, that can be initialised per-client connection:
typeContext{
...,userService: UserService,// parameterised over the client information sent across (perhaps even auth handling...)}/** Of course, this `Context` type can probably be inferred in most cases */exportconstconfig=createSimpleConfig<Context>({
...,hooks: {createContext: async(params: ClientContext): Context=>{return{user: newUserService(client.handshake), ... }}});
When should you initialise the context?
This could be achieved either one of the ideas:
Either make it so that the onStartup hook actually requires you to return a Context, and hence this is the initialisation mechanism for context.
Completely abstract context initialisation, and add a new hook, createContext()
Other thoughts
Perhaps its better to add a createContext hook because it can be parameterised over client, making it possible to construct a Context that is client specific.
Perhaps split context into just the current instance context, and a per-client context. The instance context, can be constructed when you call attachSockets (exactly as the current mechanism to pass in the logger).
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm not sure if this would be currently possible, but It would be nice to allow for the
config
to specify an initialisationContext
, one that is available across the entire socket handling mechanism. This could be an expansion upon the current way that thelogger
is passed around, and its in fact just generalised to handle any shape of data, not only just a logger. So for example:Furthermore, it could be useful to add client-specific contexts, that can be initialised per-client connection:
When should you initialise the context?
This could be achieved either one of the ideas:
onStartup
hook actually requires you to return aContext
, and hence this is the initialisation mechanism for context.createContext()
Other thoughts
Perhaps its better to add a
createContext
hook because it can be parameterised overclient
, making it possible to construct aContext
that is client specific.Perhaps split context into just the current instance context, and a per-client context. The instance context, can be constructed when you call
attachSockets
(exactly as the current mechanism to pass in the logger).Beta Was this translation helpful? Give feedback.
All reactions