index.d.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import SocketIOClient from "socket.io-client";
  2. import {
  3. DefaultComputed,
  4. DefaultData,
  5. DefaultMethods,
  6. DefaultProps,
  7. PropsDefinition,
  8. } from "vue/types/options";
  9. import { Vue } from "vue/types/vue";
  10. import { PluginFunction, PluginObject } from "vue";
  11. import { Store } from "vuex";
  12. interface socketHandler<T> {
  13. (this: T, ...args: any[]): void
  14. }
  15. interface Sockets<V> {
  16. [key: string]: socketHandler<V>
  17. }
  18. declare module 'vue/types/vue' {
  19. interface Vue {
  20. $socket: SocketIOClient.Socket,
  21. sockets: {
  22. subscribe(eventName: string, handler: socketHandler<Vue>): void,
  23. unsubscribe(eventName: string): void,
  24. }
  25. }
  26. }
  27. declare module 'vue/types/options' {
  28. interface ComponentOptions<
  29. V extends Vue,
  30. Data=DefaultData<V>,
  31. Methods=DefaultMethods<V>,
  32. Computed=DefaultComputed,
  33. PropsDef=PropsDefinition<DefaultProps>,
  34. Props=DefaultProps> {
  35. sockets?: Sockets<V>
  36. }
  37. }
  38. export interface VueSocketOptions {
  39. debug?: boolean;
  40. connection: string | SocketIOClient.Socket,
  41. vuex?: {
  42. store?: Store<any>,
  43. actionPrefix?: string,
  44. mutationPrefix?: string,
  45. options?: {
  46. useConnectionNamespace?: boolean
  47. }
  48. }
  49. }
  50. export default class VueSocketIO<T> implements PluginObject<T> {
  51. constructor (options: VueSocketOptions);
  52. install: PluginFunction<T>
  53. }