-
Notifications
You must be signed in to change notification settings - Fork 239
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
typings for embedded:network (io) modules
- Loading branch information
Showing
11 changed files
with
565 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"include": [ | ||
"$(MODDABLE)/examples/io/tcp/mqttclient/manifest_mqttclient.json" | ||
], | ||
"modules": { | ||
"embedded:network/mqtt/mqtt": [ | ||
"./mqtt" | ||
] | ||
}, | ||
"preload": [ | ||
"embedded:network/mqtt/mqtt" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
declare module "embedded:io/socket/tlssocket" { | ||
import { Options as TCPOptions } from "embedded:io/socket/tcp" | ||
export type Options = TCPOptions & { | ||
host: string | ||
secure: Record<string, any> // should be called "tls" according to std? | ||
} | ||
export default class TLSSocket { | ||
constructor(options: Options) | ||
close(): undefined | ||
read(count: number|ArrayBufferLike) : undefined|ArrayBufferLike | ||
write(buffer: ArrayBufferLike) : number | ||
set format(format: string) | ||
get format() : string | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright (c) 2022 Shinya Ishikawa | ||
* | ||
* This file is part of the Moddable SDK Tools. | ||
* | ||
* The Moddable SDK Tools is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* The Moddable SDK Tools is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with the Moddable SDK Tools. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
declare module "embedded:network/dns/resolver/udp" { | ||
|
||
interface Options { | ||
host: string | ||
onResolved: ((host:string, address:any) => null) | ||
onError: ((host:string) => null) | ||
} | ||
|
||
class Resolver { | ||
constructor(options: Record<string, any>) | ||
close(): null | ||
resolve(options: Options): null | ||
|
||
} | ||
|
||
export default Resolver | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright (c) 2022 Shinya Ishikawa | ||
* | ||
* This file is part of the Moddable SDK Tools. | ||
* | ||
* The Moddable SDK Tools is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* The Moddable SDK Tools is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with the Moddable SDK Tools. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
declare module "embedded:network/http/client" { | ||
import type { Buffer } from "embedded:io/_common" | ||
|
||
export interface ClientOptions { | ||
socket: any | ||
port?:number | ||
host: string | ||
dns: any | ||
onError: (err:any)=>void | ||
} | ||
|
||
export interface RequestOptions { | ||
method?: string | ||
path?: string | ||
headers?: Map<string, string|string[]> | ||
onHeaders?: (this: HTTPRequest, status:number, headers:Record<string, string>) => void | ||
onReadable?: (this: HTTPRequest, count: number) => void | ||
onWritable?: (this: HTTPRequest, count: number) => void | ||
onDone?: (this: HTTPRequest, error: Error|null) => void // note: error is empty Error object | ||
} | ||
|
||
export interface HTTPRequest { | ||
read(byteLength?: number): ArrayBuffer|undefined; | ||
read(buffer: Buffer): void; | ||
write(value: Buffer|undefined): void; | ||
} | ||
|
||
export default class HTTPClient { | ||
constructor(options: ClientOptions) | ||
request(options: RequestOptions): HTTPRequest | ||
close(): void | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
declare module "embedded:network/mqtt/client" { | ||
import type { Buffer } from "embedded:io/_common" | ||
|
||
interface onReadableOptions { | ||
more: boolean, | ||
topic?: string, | ||
QoS?: number, | ||
byteLength?: number, | ||
} | ||
|
||
interface onControlMessage { | ||
operation: number, // MQTTClient.CONNACK, etc... | ||
id: number, | ||
payload?: Buffer, // for SUBACK | ||
} | ||
|
||
interface Will { | ||
topic?: string, | ||
message?: string|Buffer, | ||
QoS?: number, | ||
retain?: boolean, | ||
} | ||
|
||
interface Options { | ||
host: string, | ||
port?: number, | ||
user?: string, | ||
password?: string, | ||
id?: string, | ||
clean?: boolean, | ||
will?: any, | ||
keepAlive?: number, // milliseconds | ||
onReadable?: (count: number, options: onReadableOptions) => void, | ||
onWritable?: (count: number) => void, | ||
onControl?: (opcode: number, message: onControlMessage) => void, | ||
onClose?: () => void, | ||
onError?: (error: any) => void, | ||
dns: Record<string, any>, | ||
socket: Record<string, any>, | ||
} | ||
|
||
interface WriteOptions { | ||
operation?: number, | ||
id?: number, | ||
topic: string, | ||
QoS?: number, | ||
retain?: boolean, | ||
duplicate?: boolean, | ||
byteLength?: number, | ||
items?: any[], // being lazy here | ||
} | ||
|
||
export default class MQTTClient { | ||
constructor(options: Options) | ||
read(count: number): ArrayBuffer | ||
write(data: Buffer, options: WriteOptions): number | ||
close(): void | ||
|
||
static CONNECT: 1 | ||
static CONNACK: 2 | ||
static PUBLISH: 3 | ||
static PUBACK: 4 | ||
static PUBREC: 5 | ||
static PUBREL: 6 | ||
static PUBCOMP: 7 | ||
static SUBSCRIBE: 8 | ||
static SUBACK: 9 | ||
static UNSUBSCRIBE: 10 | ||
static UNSUBACK: 11 | ||
static PINGREQ: 12 | ||
static PINGRESP: 13 | ||
static DISCONNECT: 14 | ||
} | ||
} |
Oops, something went wrong.