index.d.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. // type declarations for optional options
  50. options?:{
  51. path?: string;
  52. }
  53. }
  54. export default class VueSocketIO<T> implements PluginObject<T> {
  55. constructor (options: VueSocketOptions);
  56. install: PluginFunction<T>
  57. }