我目前正在使用 websockets 并被迫使用默认库,并且一些基本事件(如 onmessage)对于处理来自服务器的消息很有用。
我想知道为什么 .NET 4.5 中的 ClientWebSocket 类没有像websocket-sharp 库中的客户端那样的 onmessage 事件?
问题描述: 这不是这个问题的重复。我不是要访问电子模块(我使用电子包装器来执行此操作),我试图在 angular 中使用 npm 本机模块,同时在电子内部运行 angular。
原始描述:
我有一个使用电子运行的 angular 应用程序(一个新应用程序,还没有做任何事情)。要访问蓝牙,我使用了noble和bleno,但是当它们在 Electron 中工作时(为了测试我添加noble = require('noble')到电子文件夹中的 index.js),当我将例如 noble 添加到 app.compoents.js 中时,它们不起作用棱角分明。
这是我的 app.component.ts
import { Component } from '@angular/core';
import {ElectronService} from 'ngx-electron';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title: String = 'Colaboration room';
noble = require('noble')
}
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
./node_modules/bindings/bindings.js 76:43-53 中的警告 关键依赖:依赖的请求是一个表达式
虽然这只是一个警告,但 angular 初始页面不再显示(它是空的)。
问题: 如何在 Angular 中访问节点本机模块(在电子中运行时)?
附加信息:
我使用 angulars 默认编译器webpack …
附加信息:
我知道访问cordova插件的常用方法:
(<any>window).plugins.myPlugin
or
declare var yourGloballyAccessablePlugin: any;
Run Code Online (Sandbox Code Playgroud)
但它与插件不同bluetoothle(通过离子3支持的本机蓝牙插件都不够好,因为它们不提供蓝牙功能peripherial如广告)
解决方案尝试:
我在离子论坛上找到了一个相关的问题,并询问他们是如何实现的,到目前为止,我未能重复该过程,到目前为止,没有人回答我的问题,这就是为什么要开放这个问题。
显然,蓝牙公开了一个全局可访问的变量。
如前所述,我在declaration.d.ts文件src夹中添加了以下内容:
declare module 'cordova-plugin-bluetoothle';
import 'cordova-plugin-bluetoothle';
declare var cordova: any;
Run Code Online (Sandbox Code Playgroud)
然后,我尝试像这样访问插件(在手机上对其进行了测试):
import { bluetoothle } from 'cordova-plugin-bluetoothle';
...
(<any>window).bluetoothle
Run Code Online (Sandbox Code Playgroud)
问题:
但是蓝牙对我来说始终是不确定的。由于我是Cordova,Ionic和TypeScript的新手,我想我使用clarifications.d.ts的方式有问题
那么,有人知道我在做什么错吗,如何在ionic 3中使用cordova原生插件bluetoothle?
更新,解决方案尝试2:
因此,我尝试按照app.component.ts@Webruster的建议在初始项目结构中运行此代码,并使用蓝牙文档中的init参数:
(这里的唯一目标是查看插件是否正常工作)
进口...
declare var cordova: any;
Run Code Online (Sandbox Code Playgroud)
@Component,类开始和属性...
constructor(private translate: TranslateService, platform: Platform, settings: Settings, private config: Config, private statusBar: StatusBar, private splashScreen: SplashScreen) {
platform.ready().then(() => …Run Code Online (Sandbox Code Playgroud) 按照此处的文档,可以轻松启用 HTTP REST 应用程序的 NestJS URI 版本控制。
然而,文档没有解释如何使 URI 版本控制成为可选。
例子:
/api/v1/users
/api/v2/users
/api/users-> 应映射到 v1 以允许现有的 webhooks 继续工作
问题:
我们如何在 NestJS REST 应用程序中使 URI 版本控制成为可选,以便旧版本(没有任何 api 版本)继续工作?
angular ×1
c# ×1
cordova ×1
electron ×1
ionic-native ×1
nestjs ×1
node-modules ×1
node.js ×1
typescript ×1
websocket ×1