【发布时间】: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