Socket
Socket
Sign inDemoInstall

@furystack/websocket-api

Package Overview
Dependencies
22
Maintainers
1
Versions
220
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @furystack/websocket-api

HTTP Api FuryStack package


Version published
Weekly downloads
37
decreased by-84.39%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

websocket-api

WebSocket implementation for FuryStack

Usage example

You can initialize the WebSocket package in the following way

const myInjector = new Injector()
  .useWebsockets({
    path: '/api/sockets',
    actions: [WhoAmI],
  })

Implement your own actions

You can implement a WebSocket action in the following way:

import { User } from '@furystack/core'
import { HttpUserContext } from '@furystack/http-api'
import { Injectable } from '@furystack/inject'
import { Data } from 'ws'
import * as ws from 'ws'
import { IWebSocketAction } from '../models/IWebSocketAction'

@Injectable({ lifetime: 'transient' })
export class WhoAmI implements WebSocketAction {
  public dispose() {
    /** */
  }
  public static canExecute(data: Data): boolean {
    return data.toString() === 'whoami' || data.toString() === 'whoami /claims'
  }

  public async execute() {
    const currentUser = await this.httpUserContext.getCurrentUser()
    this.websocket.send(JSON.stringify(currentUser))
  }

  constructor(private httpUserContext: HttpUserContext<User>, private websocket: ws) {}
}

Keywords

FAQs

Last updated on 16 May 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc