Skip to content

Commit beddfbf

Browse files
committed
fix(typings): remove typings.d.ts which caused many problems
1 parent d49ad6c commit beddfbf

File tree

10 files changed

+40
-82
lines changed

10 files changed

+40
-82
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
],
3232
"scripts": {
3333
"build": "rm -rf dist && tsc -p tsconfig.dist.json && rollup --config",
34-
"postbuild": "cp src/misc/typings.d.ts dist/esm/misc && mkdir dist/esm/proto && cp src/proto/index.js src/proto/index.d.ts dist/esm/proto && uglifyjs -o dist/netflux.umd.min.js dist/netflux.umd.js",
34+
"postbuild": "mkdir dist/esm/proto && cp src/proto/index.js src/proto/index.d.ts dist/esm/proto && uglifyjs -o dist/netflux.umd.min.js dist/netflux.umd.js",
3535
"pretest": "rollup -c test/util/rollup.config.js && pm2 --silent restart test/util/process.yml --only netflux-test-signaling && pm2 restart test/util/process.yml --only netflux-test-bot ",
3636
"test": "karma start",
3737
"posttest": "pm2 --silent delete test/util/process.yml",

src/Bot.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { WebGroupState } from './index.common.doc'
2+
import { NodeJSHttpServer, NodeJSHttpsServer } from './misc/env'
23
import { IWebChannelOptions, WebChannel, webChannelDefaultOptions } from './WebChannel'
34
import { wcs, WebGroup } from './WebChannelFacade'
45
import { Route, WebSocketBuilder } from './WebSocketBuilder'

src/BotFacade.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Bot as BotServer, IBotOptions as BotOptions } from './Bot'
2+
import { NodeJSHttpServer, NodeJSHttpsServer } from './misc/env'
23
import { WebGroup } from './WebChannelFacade'
34

45
let botServer: BotServer

src/Channel.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { RTCDataChannel } from './misc/env'
12
import { isBrowser, log } from './misc/util'
23
import { channel as proto, IMessage, Message } from './proto'
34
import { UserMessage } from './service/UserMessage'

src/index.common.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/// <reference path="./misc/typings.d.ts" />
2-
31
export { LogLevel, setLogLevel } from './misc/util'
42
export { TopologyEnum as Topology } from './service/topology/Topology'
53
export { SignalingState } from './Signaling'

src/misc/env.ts

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,32 @@
1+
/* tslint:disable:interface-name */
2+
3+
export interface RTCDataChannelEvent {
4+
readonly channel: RTCDataChannel
5+
}
6+
7+
export interface RTCDataChannel extends EventTarget {
8+
label: string
9+
reliable: boolean
10+
readyState: string
11+
bufferedAmount: number
12+
binaryType: string
13+
onopen: (event: Event) => void
14+
onerror: (event: Event) => void
15+
onclose: (event: Event) => void
16+
onmessage: (event: Event) => void
17+
close(): void
18+
send(data: string | ArrayBuffer | Blob): void
19+
}
20+
21+
// Types for NodeJS environment, just for visual understanding
22+
export type NodeJSHttpServer = any // NodeJS http.Server
23+
export type NodeJSHttpsServer = any // NodeJS https.Server
24+
125
export interface IEnvironment {
2-
RTCPeerConnection: typeof RTCPeerConnection
3-
RTCIceCandidate: typeof RTCIceCandidate
4-
TextEncoder: typeof TextEncoder
5-
TextDecoder: typeof TextDecoder
26+
RTCPeerConnection: any
27+
RTCIceCandidate: any
28+
TextEncoder: any
29+
TextDecoder: any
630
WebSocket: typeof WebSocket
731
crypto: Crypto
832
cryptoNode: any

src/misc/typings.d.ts

Lines changed: 0 additions & 67 deletions
This file was deleted.

src/service/dataChannelBuilder/DataChannelBuilder.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Observable, Subject } from 'rxjs'
22

33
import { Channel, ChannelType } from '../../Channel'
44
import '../../misc/env'
5-
import { env } from '../../misc/env'
5+
import { env, RTCDataChannelEvent } from '../../misc/env'
66
import { log } from '../../misc/util'
77
import { dataChannelBuilder as proto } from '../../proto'
88
import { WebChannel } from '../../WebChannel'
@@ -121,7 +121,7 @@ export class DataChannelBuilder extends Service<proto.IMessage, proto.Message> {
121121
} else {
122122
remote = this.createRemote(streamId, id)
123123
}
124-
const dc = remote.pc.createDataChannel(this.wc.myId.toString())
124+
const dc = (remote.pc as any).createDataChannel(this.wc.myId.toString())
125125
const offerInit = await remote.pc.createOffer()
126126
await remote.pc.setLocalDescription(offerInit)
127127

@@ -148,8 +148,8 @@ export class DataChannelBuilder extends Service<proto.IMessage, proto.Message> {
148148
)
149149
if (passive) {
150150
log.webrtc(`create a new remote object with ${id} - PASSIVE`)
151-
152-
remote.pc.ondatachannel = ({ channel: dc }: RTCDataChannelEvent) => {
151+
const pc = remote.pc as any
152+
pc.ondatachannel = ({ channel: dc }: RTCDataChannelEvent) => {
153153
const peerId = Number.parseInt(dc.label, 10)
154154
let type: ChannelType
155155
if (streamId === this.wc.STREAM_ID) {

src/service/dataChannelBuilder/Remote.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ReplaySubject } from 'rxjs'
22

3-
import { env } from '../../misc/env'
3+
import { env, RTCDataChannel } from '../../misc/env'
44
import { log } from '../../misc/util'
55
import { dataChannelBuilder as proto } from '../../proto'
66

@@ -88,7 +88,7 @@ export class Remote {
8888
log.webrtc('CLEAN')
8989
this.pc.oniceconnectionstatechange = () => {}
9090
this.pc.onicecandidate = () => {}
91-
this.pc.ondatachannel = () => {}
91+
;(this.pc as any).ondatachannel = () => {}
9292
this._onError = () => {}
9393
this.candidates.complete()
9494
this.remotes.delete(this.id)
@@ -106,7 +106,7 @@ export class Remote {
106106
}
107107
this.pc.oniceconnectionstatechange = () => {}
108108
dc.onopen = () => {}
109-
this.pc.ondatachannel = () => {}
109+
;(this.pc as any).ondatachannel = () => {}
110110
this._onError = () => {}
111111
clearTimeout(this.timer)
112112
}

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"lib": ["es2017", "dom"],
66
"moduleResolution": "node",
77
"downlevelIteration": true,
8-
"typeRoots": ["src/misc/typings"],
8+
"types": [],
99
"strict": true,
1010
"noUnusedLocals": true,
1111
"noUnusedParameters": false,

0 commit comments

Comments
 (0)