rodgc / ngx-socket-io

Socket.IO module for Angular
MIT License
261 stars 89 forks source link

Protractor E2E tests time out when setting up web sockets #67

Closed RogierdeRuijter closed 4 months ago

RogierdeRuijter commented 4 years ago

Hee,

I am currently facing the issue that my E2E tests in protractor time out. And I believe it is an issue related to Protractor, Angular, and SocketIO. Here is an old GitHub Issue mentioning the problem https://github.com/angular/angular/issues/11853.

There is also a fix for it, but this requires setting up the WebSocket connection 'outside of Angular' with the help of NgZone.

So my question is, is there a way to setup the WebSocket connection outside of Angular?

Cheers,

FYI: The library ng-socket-io has a PR open to setup the socket outside of Angular. https://github.com/bougarfaoui/ng-socket-io/pull/61

RihardKrauz commented 3 years ago

Found a quick workaround / solution:

const socketConfig: SocketIoConfig = {
    url: '/',
    options: {
        path: '/socket.io',
        transports: ['websocket'],
        secure: true,
    }
};

@Injectable()
export class SocketRunningOutsideOfAngular extends Socket {
    constructor() {
        super(socketConfig);
    }
}

@NgModule({
    declarations: [
            ...
    ],
    imports: [
             SocketIoModule
        ],
        providers: [
    {
        provide: SocketRunningOutsideOfAngular,
        useFactory: (ngZone: NgZone) => {
            return ngZone.runOutsideAngular(() => {
                return new SocketRunningOutsideOfAngular();
            });
        },
        deps: [NgZone]
    },
github-actions[bot] commented 4 months ago

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] commented 4 months ago

This issue was closed because it has been inactive for 7 days since being marked as stale.