enhanced-datachannel
Advanced tools
Comparing version 1.2.0 to 1.2.1
# ChangeLlog | ||
## [1.2.1] - 2019-07-23 | ||
### Changed | ||
- Do not strict typing JSON argument | ||
## [1.2.0] - 2019-07-22 | ||
@@ -33,4 +39,6 @@ | ||
[1.2.1]: https://github.com/leader22/enhanced-datachannel/releases/tag/v1.2.1 | ||
[1.2.0]: https://github.com/leader22/enhanced-datachannel/releases/tag/v1.2.0 | ||
[1.1.0]: https://github.com/leader22/enhanced-datachannel/releases/tag/v1.1.0 | ||
[1.0.1]: https://github.com/leader22/enhanced-datachannel/releases/tag/v1.0.1 | ||
[1.0.0]: https://github.com/leader22/enhanced-datachannel/releases/tag/v1.0.0 |
import BasedDataChannel from "./based-datachannel"; | ||
declare type JSONValue = boolean | number | string | null | JSONArray | JSONObject; | ||
interface JSONObject { | ||
[key: string]: JSONValue; | ||
} | ||
interface JSONArray extends Array<JSONValue> { | ||
} | ||
declare class ChunkedDataChannel extends BasedDataChannel { | ||
@@ -17,5 +11,5 @@ private _sending; | ||
close(): void; | ||
send(data: Blob, meta?: JSONObject): Promise<void>; | ||
send(data: Blob, meta?: any): Promise<void>; | ||
protected _handleMessage(ev: MessageEvent): void; | ||
} | ||
export default ChunkedDataChannel; |
@@ -57,2 +57,8 @@ "use strict"; | ||
} | ||
try { | ||
JSON.stringify(meta); | ||
} | ||
catch (err) { | ||
throw new Error("Can not convert to JSON!"); | ||
} | ||
debug(`data has ${data.size}bytes`); | ||
@@ -59,0 +65,0 @@ return new Promise((resolve, reject) => { |
import BasedDataChannel from "./based-datachannel"; | ||
declare type JSONValue = boolean | number | string | null | JSONArray | JSONObject; | ||
interface JSONObject { | ||
[key: string]: JSONValue; | ||
} | ||
interface JSONArray extends Array<JSONValue> { | ||
} | ||
declare class PromisedDataChannel extends BasedDataChannel { | ||
@@ -12,4 +6,3 @@ private _sentRequests; | ||
close(): void; | ||
send(data: JSONValue): Promise<JSONValue>; | ||
private _sendMessage; | ||
send(data: any): Promise<any>; | ||
protected _handleMessage(ev: MessageEvent): void; | ||
@@ -16,0 +9,0 @@ private _handleRequest; |
@@ -41,3 +41,10 @@ "use strict"; | ||
}; | ||
this._sendMessage(request); | ||
let requestJSON; | ||
try { | ||
requestJSON = JSON.stringify(request); | ||
} | ||
catch (err) { | ||
throw new Error("Can not convert to JSON!"); | ||
} | ||
this._dc.send(requestJSON); | ||
return new Promise((resolve, reject) => { | ||
@@ -73,5 +80,2 @@ const timeout = 1000 + 500 * this._sentRequests.size; | ||
} | ||
_sendMessage(data) { | ||
this._dc.send(JSON.stringify(data)); | ||
} | ||
_handleMessage(ev) { | ||
@@ -90,21 +94,28 @@ const evData = JSON.parse(ev.data); | ||
this.emit("message", request.data, (data) => { | ||
this._sendMessage({ | ||
type: PAYLOAD_TYPES.SUCCESS_RESPONSE, | ||
id: request.id, | ||
data | ||
}); | ||
let responseJSON; | ||
try { | ||
responseJSON = JSON.stringify({ | ||
type: PAYLOAD_TYPES.SUCCESS_RESPONSE, | ||
id: request.id, | ||
data | ||
}); | ||
} | ||
catch (err) { | ||
throw new Error("Can not convert to JSON!"); | ||
} | ||
this._dc.send(responseJSON); | ||
}, (err) => { | ||
this._sendMessage({ | ||
this._dc.send(JSON.stringify({ | ||
type: PAYLOAD_TYPES.ERROR_RESPONSE, | ||
id: request.id, | ||
err: err.toString() | ||
}); | ||
})); | ||
}); | ||
} | ||
catch (err) { | ||
this._sendMessage({ | ||
this._dc.send(JSON.stringify({ | ||
type: PAYLOAD_TYPES.ERROR_RESPONSE, | ||
id: request.id, | ||
err: err.toString() | ||
}); | ||
})); | ||
} | ||
@@ -111,0 +122,0 @@ } |
{ | ||
"name": "enhanced-datachannel", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "Wanna `enhance(RTCDataChannel)` for general usage.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
21869
481