I have been trying to connect to signalr server with nativescript websockets plugin and been receiving this error, I need help! it is not the only way I have tried: JS: ERROR Error: addEventListener passed an invalid event type OpenWorkItem this is one of the codes I have tried.

import { Component, OnInit, OnDestroy, NgZone } from "@angular/core";
import { HttpClientModule } from '@angular/common/http';
import {Observable} from 'rxjs';

require("nativescript-websockets");
@Component({
    selector: "ns-app",
    moduleId: module.id,
    templateUrl: "./app.component.html"
})
export class AppComponent { 
    private socket: any;
    public messages: Array<any>;
    public chatBox: string;
    private socketUrl: any = 'ws://localhost:57688/hub?deviceId=2';
    private websocket: any; 
    equipID: any;
    inspID: any;
    inspView: any;
    fileURL: any;
    public constructor(private zone: NgZone) {
        const url ="/signalr/negotiate?clientProtocol=1.5&connectionData=[{'name':'hub'}]";
        //http.get(url);
        this.socket = new WebSocket(this.socketUrl, []);

        ///signalr/connect?transport=webSockets&clientProtocol=1.5&connectionToken= &connectionData=
        console.log("websockets");

    }

    public ngOnInit() {
    //    this.connection = new signalR.HubConnectionBuilder()
   //     .withUrl('http://localhost:57688/hub?deviceId=2',  signalR.HttpTransportType.WebSockets )
    //    .build();
    this.socket.on('OpenWorkItem', function(socket, message) { 
        console.log("Got a message", message); });

   /* this.socket.addEventListener('OpenWorkItem', (eID: any, iID: any, iV: any, file: any, wID: any) => {
        this.zone.run(() => {
        this.equipID = eID;
        this.inspID =  iID;
        console.log("workitem" + eID);
        this.inspView = iV;
        if (file.lenght > 0) {
          this.fileURL = file;
        } else {
          this.fileURL = '/assets/images/bp_waiting.png';
        }
    });
       });*/

    }

    public ngOnDestroy() {
        this.socket.close();
    }

    public send() {
     
    }


}

Related posts

Recent Viewed