Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support for moonraker socket connection identification #568

Merged
merged 4 commits into from
Mar 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/api/socketActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,18 @@ export const SocketActions = {
)
},

async identify () {
baseEmit('server.connection.identify', {
dispatch: 'socket/onConnectionId',
params: {
client_name: Globals.APP_NAME,
version: `${store.state.version?.fluidd.version || '0.0.0'}-${store.state.version?.fluidd.hash || 'unknown'}`.trim(),
type: 'web',
url: Globals.GITHUB_REPO
}
})
},

async serverConfig () {
baseEmit(
'server.config', {
Expand Down
3 changes: 2 additions & 1 deletion src/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ export const Globals = Object.freeze({
DOCS_MULTIPLE_INSTANCES: 'https://docs.fluidd.xyz/configuration/multiple_printers',
DOCS_MOONRAKER_COMPONENTS: 'https://docs.fluidd.xyz/configuration/moonraker',
DOCS_AUTH_LOST_PASSWORD: 'https://docs.fluidd.xyz/authorization#lost-password',
DOCS_AUTH: 'https://docs.fluidd.xyz/authorization'
DOCS_AUTH: 'https://docs.fluidd.xyz/authorization',
GITHUB_REPO: 'https://github.com/fluidd-core/fluidd'
})

export const Icons = Object.freeze({
Expand Down
13 changes: 12 additions & 1 deletion src/store/socket/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ export const actions: ActionTree<SocketState, RootState> = {
*/
async onSocketOpen ({ commit }, payload) {
commit('setSocketOpen', payload)
if (payload === true) SocketActions.serverInfo()
if (payload === true) {
SocketActions.serverInfo()
SocketActions.identify()
}
},

/**
Expand Down Expand Up @@ -106,6 +109,14 @@ export const actions: ActionTree<SocketState, RootState> = {
}
},

/**
* Fired when the socket [identifies](https://moonraker.readthedocs.io/en/latest/web_api/#identify-connection).
* Required for [HTTP-based subscriptions](https://moonraker.readthedocs.io/en/latest/web_api/#subscribe-to-printer-object-status).
*/
async onConnectionId ({ commit }, { connection_id }) {
commit('setConnectionId', connection_id)
},

/**
* ==========================================================================
* Automated notifications via socket
Expand Down
3 changes: 2 additions & 1 deletion src/store/socket/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export const defaultState = (): SocketState => {
disconnecting: false, // indicates we know a disconnect is coming, and to retry.
ready: false, // indicates the socket is ready (and has first dump of data...)
acceptingNotifications: false, // indicates we're accepting notification data because we've finished subscribing to objects
error: null // if the socket has an error or not
error: null, // if the socket has an error or not
connectionId: null // connection id assigned to the socket
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/store/socket/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,9 @@ export const mutations: MutationTree<SocketState> = {

setApiConnected (state, payload) {
state.apiConnected = payload
},

setConnectionId (state, payload) {
state.connectionId = payload
}
}
1 change: 1 addition & 0 deletions src/store/socket/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface SocketState {
ready: boolean;
acceptingNotifications: boolean;
error: SocketError | null;
connectionId: string | null;
}

export interface SocketError {
Expand Down