【问题标题】:SignalrR NativeScript androidSignalrR NativeScript 安卓
【发布时间】:2019-02-12 14:31:50
【问题描述】:

我一直在尝试使用 nativescript websockets 插件连接到信号器服务器并收到此错误,我需要帮助!这不是我尝试过的唯一方法: JS:ERROR 错误:addEventListener 传递了无效的事件类型 OpenWorkItem 这是我尝试过的代码之一。

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() {
     
    }


}

【问题讨论】:

    标签: android signalr nativescript


    【解决方案1】:

    此插件仅支持以下事件。如果添加任何其他自定义事件,则会引发相同的错误。

    • 打开
    • 关闭
    • 留言
    • 错误
    • 片段
    • 握手

    我猜你将不得不监听message 事件并依赖传入的数据来回调事件类型。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-27
      • 2011-11-24
      • 2017-12-05
      • 2012-04-08
      相关资源
      最近更新 更多