Giter Site home page Giter Site logo

socketio-client's Introduction

@feathersjs/socketio-client

Important: The code for this module has been moved into the main Feathers repository at feathersjs/feathers (package direct link). Please open issues and pull requests there. No changes in your existing Feathers applications are necessary.

Build Status

The client for Socket.io Feathers connections

Installation

npm install @feathersjs/socketio-client --save

Quick example

const feathers = require('@feathersjs/feathers');
const socketio = require('@feathersjs/socketio-client');
const io = require('socket.io-client');

const socket = io('http://api.feathersjs.com');
const app = feathers();

// Set up Socket.io client with the socket
app.configure(socketio(socket));

// Receive real-time events through Socket.io
app.service('messages')
  .on('created', message => console.log('New message created', message));

// Call the `messages` service
app.service('messages').create({
  text: 'A message from a REST client'
});

Documentation

Please refer to the @feathersjs/socketio-client documentation for more details.

License

Copyright (c) 2018

Licensed under the MIT license.

socketio-client's People

Contributors

daffl avatar greenkeeper[bot] avatar

Stargazers

Joel Boucher avatar Beep LIN avatar Frank Lemanschik avatar Huston Hedinger avatar Vladimir Krutov avatar

Watchers

 avatar James Cloos avatar F Lewis avatar Maicon Wagner avatar  avatar

Forkers

frank-dspeed

socketio-client's Issues

Error handling by Socketio is not handled the same way as Rest transport

When initiating feather with express the final step I add a custom error-handler module that will format the errors and translate them. It works just fine on the rest transport, but when I use @feathersjs/socketio transport it does not use the custom error-handler and bypasses it. Is there no way to fix this, does Socketio have a point to hookup error formatting any work around to have consistency. Am using i18n for the translation express gets the selected language from the request headers

Code used for initiating custom error-handler

static initErrorRoutes(app) {
   app.route('/:url(api|modules|lib)/*').get((req, res) => {
     res.status(404).json({message: res.__('pageNotFound')});
   });
   app.use(express.notFound());
   app.use(customErrors.getErrorMessage);
 }

Code of the custom error-handler

exports.getErrorMessage = function (err, req, res, next) {
  if (!err) {
        return next();
    }
    let message = '';
    switch (err.code) {
        case 400:
        case 409:
           // it parses mongoose errors and translates other error type 
            message = parseDataError(err, res);
            break;
        case 401:
            message = res.__('authorizationError');
            break;
        case 403:
            message = res.__(err.message);
            break;
        case 404:
            message = res.__('pageNotFound');
            break;
        default:
            console.error(err.stack);
            message = res.__('error');
    }
    return res.status(err.code).send({message: message});
};

Timeout error, why?

Hello,
I have two methods:

private initSocket(): void {
      this._socket = io('http://localhost:3030', {
          transports: ['websocket']
      });
      this._feathers
          .configure(socketio(this._socket));
      this._feathers
          .configure(auth({
              storage: window.localStorage
          }));
  }

  private initRest(): void {
      let restClient = rest();
      restClient = rest('http://localhost:3030')
      this._feathers.configure(restClient.fetch(window.fetch));
  }

and:

import * as feathers from '@feathersjs/feathers';
import * as io from 'socket.io-client';
import * as socketio from '@feathersjs/socketio-client';
import * as rest from '@feathersjs/rest-client';
import * as auth from '@feathersjs/authentication-client';

If i use initRest() services work wonderful, but if i use initSocket i have this error:
screenshot_21

You may suggest what's the problem? (in the old versions everything worked fine)
thank you in advance :)

Error: Timeout of 5000ms exceeded on create

When sending a create request to the Server, if the same application is logged with the same user it generates the error (Timeout of 5000ms exceeded calling create on comando) when sending the request.

I noticed that this happens only when there are 2 users connected with the same username.
I also noticed that the error happens on the client because the server does not receive this request, ie the client kind of loses the connection temporarily with the server socket.

To reproduce the error: Create an Angular application using SocketIO Client, perform authentication in 2 or more tabs and execute any POST (create) call to the server, one of them will hang generating the error (Timeout of 5000ms exceeded calling create on ...)

Timeout on chrome android

Steps to reproduce

  1. Set up feathers 3.0.0 server + feather-client 3.4.0 with socketio enabled.
  2. Make a request from client, times out 50% of the time.

Expected behavior

Should not time out.

Actual behavior

Times out.

Is there typical things people mess up when setting this up?
What's a good place I should be looking for how to do this correctly?

Non compatible with SSR

Hello, the socketio-client don't work on server side rendering.

Error:
ERROR { Error: Uncaught (in promise): Error: NotYetImplemented
Error: NotYetImplemented
    at Document.exports.nyi (E:\YandexDisk\domains\plus-ssr\server.js:27067:9)
    at Passport.getCookie (E:\YandexDisk\domains\plus-ssr\server.js:169509:32)
    at Promise.resolve.then.jwt (E:\YandexDisk\domains\plus-ssr\server.js:168913:35)
    at ZoneDelegate.invoke (E:\YandexDisk\domains\plus-ssr\server.js:142830:26)
    at Object.onInvoke (E:\YandexDisk\domains\plus-ssr\server.js:5022:33)
    at ZoneDelegate.invoke (E:\YandexDisk\domains\plus-ssr\server.js:142829:32)
    at Zone.run (E:\YandexDisk\domains\plus-ssr\server.js:142580:43)
    at E:\YandexDisk\domains\plus-ssr\server.js:143300:57
    at ZoneDelegate.invokeTask (E:\YandexDisk\domains\plus-ssr\server.js:142863:31)
    at Object.onInvokeTask (E:\YandexDisk\domains\plus-ssr\server.js:5013:33)
    at resolvePromise (E:\YandexDisk\domains\plus-ssr\server.js:143251:31)
    at resolvePromise (E:\YandexDisk\domains\plus-ssr\server.js:143217:17)
    at E:\YandexDisk\domains\plus-ssr\server.js:143300:17
    at ZoneDelegate.invokeTask (E:\YandexDisk\domains\plus-ssr\server.js:142863:31)
    at Object.onInvokeTask (E:\YandexDisk\domains\plus-ssr\server.js:5013:33)
    at ZoneDelegate.invokeTask (E:\YandexDisk\domains\plus-ssr\server.js:142862:36)
    at Zone.runTask (E:\YandexDisk\domains\plus-ssr\server.js:142630:47)
    at drainMicroTaskQueue (E:\YandexDisk\domains\plus-ssr\server.js:143037:35)
    at ZoneTask.invokeTask (E:\YandexDisk\domains\plus-ssr\server.js:142942:21)
    at Server.ZoneTask.invoke (E:\YandexDisk\domains\plus-ssr\server.js:142927:48)
  rejection:
   Error: NotYetImplemented
       at Document.exports.nyi (E:\YandexDisk\domains\plus-ssr\server.js:27067:9)
       at Passport.getCookie (E:\YandexDisk\domains\plus-ssr\server.js:169509:32)
       at Promise.resolve.then.jwt (E:\YandexDisk\domains\plus-ssr\server.js:168913:35)
       at ZoneDelegate.invoke (E:\YandexDisk\domains\plus-ssr\server.js:142830:26)
       at Object.onInvoke (E:\YandexDisk\domains\plus-ssr\server.js:5022:33)
       at ZoneDelegate.invoke (E:\YandexDisk\domains\plus-ssr\server.js:142829:32)
       at Zone.run (E:\YandexDisk\domains\plus-ssr\server.js:142580:43)
       at E:\YandexDisk\domains\plus-ssr\server.js:143300:57
       at ZoneDelegate.invokeTask (E:\YandexDisk\domains\plus-ssr\server.js:142863:31)
       at Object.onInvokeTask (E:\YandexDisk\domains\plus-ssr\server.js:5013:33),
  promise:
   ZoneAwarePromise {
     __zone_symbol__state: 0,
     __zone_symbol__value:
      Error: NotYetImplemented
          at Document.exports.nyi (E:\YandexDisk\domains\plus-ssr\server.js:27067:9)
          at Passport.getCookie (E:\YandexDisk\domains\plus-ssr\server.js:169509:32)
          at Promise.resolve.then.jwt (E:\YandexDisk\domains\plus-ssr\server.js:168913:35)
          at ZoneDelegate.invoke (E:\YandexDisk\domains\plus-ssr\server.js:142830:26)
          at Object.onInvoke (E:\YandexDisk\domains\plus-ssr\server.js:5022:33)
          at ZoneDelegate.invoke (E:\YandexDisk\domains\plus-ssr\server.js:142829:32)
          at Zone.run (E:\YandexDisk\domains\plus-ssr\server.js:142580:43)
          at E:\YandexDisk\domains\plus-ssr\server.js:143300:57
          at ZoneDelegate.invokeTask (E:\YandexDisk\domains\plus-ssr\server.js:142863:31)
          at Object.onInvokeTask (E:\YandexDisk\domains\plus-ssr\server.js:5013:33) },
  zone:
   Zone {
     _properties: { isAngularZone: true },
     _parent:
      Zone {
        _properties: {},
        _parent: null,
        _name: '<root>',
        _zoneDelegate: [Object] },
     _name: 'angular',
     _zoneDelegate:
      ZoneDelegate {
        _taskCounts: [Object],
        zone: [Circular],
        _parentDelegate: [Object],
        _forkZS: null,
        _forkDlgt: null,
        _forkCurrZone: [Object],
        _interceptZS: null,
        _interceptDlgt: null,
        _interceptCurrZone: [Object],
        _invokeZS: [Object],
        _invokeDlgt: [Object],
        _invokeCurrZone: [Circular],
        _handleErrorZS: [Object],
        _handleErrorDlgt: [Object],
        _handleErrorCurrZone: [Circular],
        _scheduleTaskZS: [Object],
        _scheduleTaskDlgt: [Object],
        _scheduleTaskCurrZone: [Circular],
        _invokeTaskZS: [Object],
        _invokeTaskDlgt: [Object],
        _invokeTaskCurrZone: [Circular],
        _cancelTaskZS: [Object],
        _cancelTaskDlgt: [Object],
        _cancelTaskCurrZone: [Circular],
        _hasTaskZS: [Object],
        _hasTaskDlgt: [Object],
        _hasTaskDlgtOwner: [Circular],
        _hasTaskCurrZone: [Circular] } },
  task:
   ZoneTask {
     _zone:
      Zone {
        _properties: [Object],
        _parent: [Object],
        _name: 'angular',
        _zoneDelegate: [Object] },
     runCount: 0,
     _zoneDelegates: null,
     _state: 'notScheduled',
     type: 'microTask',
     source: 'Promise.then',
     data: undefined,
     scheduleFn: undefined,
     cancelFn: null,
     callback: [Function],
     invoke: [Function] } }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.