@geckos.io/client
Advanced tools
Comparing version 1.6.0 to 1.6.1
import * as Types from '@geckos.io/common/lib/types'; | ||
export declare class ClientChannel { | ||
maxMessageSize: number | undefined; | ||
userData: {}; | ||
private peerConnection; | ||
@@ -5,0 +6,0 @@ private connectionsManager; |
@@ -50,2 +50,3 @@ "use strict"; | ||
var _this = this; | ||
this.userData = {}; | ||
// stores all reliable messages for about 15 seconds | ||
@@ -142,3 +143,3 @@ this.receivedReliableMessages = []; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var error; | ||
var response; | ||
return __generator(this, function (_b) { | ||
@@ -150,6 +151,9 @@ switch (_b.label) { | ||
case 1: | ||
error = _b.sent(); | ||
if (error) | ||
callback(error); | ||
response = _b.sent(); | ||
if (response.error) | ||
callback(response.error); | ||
else { | ||
// set the userData | ||
if (response.userData) | ||
this.userData = response.userData; | ||
// keep track of the maxMessageSize | ||
@@ -156,0 +160,0 @@ this.maxMessageSize = this.connectionsManager.maxMessageSize = (_a = this.peerConnection.localPeerConnection.sctp) === null || _a === void 0 ? void 0 : _a.maxMessageSize; |
@@ -23,5 +23,13 @@ import { Bridge } from '@geckos.io/common/lib/bridge'; | ||
connect(): Promise<{ | ||
error: any; | ||
userData?: undefined; | ||
localPeerConnection?: undefined; | ||
dataChannel?: undefined; | ||
id?: undefined; | ||
} | { | ||
userData: {}; | ||
localPeerConnection: RTCPeerConnection; | ||
dataChannel: RTCDataChannel; | ||
id: string | undefined; | ||
error?: undefined; | ||
}>; | ||
@@ -28,0 +36,0 @@ } |
@@ -112,7 +112,7 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var host, headers, res, _a, error_1, _b, id, localDescription, configuration, RTCPc, showBackOffIntervals, originalAnswer, updatedAnswer, error_2, waitForDataChannel, error_3; | ||
var _c; | ||
var host, headers, userData, res, json, error_1, _a, id, localDescription, configuration, RTCPc, showBackOffIntervals, originalAnswer, updatedAnswer, error_2, waitForDataChannel, error_3; | ||
var _b; | ||
var _this = this; | ||
return __generator(this, function (_d) { | ||
switch (_d.label) { | ||
return __generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
@@ -122,6 +122,7 @@ host = this.url + "/.wrtc/v1"; | ||
if (this.authorization) | ||
headers = __assign(__assign({}, headers), (_c = {}, _c['Authorization'] = this.authorization, _c)); | ||
_d.label = 1; | ||
headers = __assign(__assign({}, headers), (_b = {}, _b['Authorization'] = this.authorization, _b)); | ||
userData = {}; | ||
_c.label = 1; | ||
case 1: | ||
_d.trys.push([1, 4, , 5]); | ||
_c.trys.push([1, 4, , 5]); | ||
return [4 /*yield*/, fetch(host + "/connections", { | ||
@@ -132,14 +133,15 @@ method: 'POST', | ||
case 2: | ||
res = _d.sent(); | ||
_a = this; | ||
res = _c.sent(); | ||
return [4 /*yield*/, res.json()]; | ||
case 3: | ||
_a.remotePeerConnection = _d.sent(); | ||
json = _c.sent(); | ||
userData = json.userData; | ||
this.remotePeerConnection = json; | ||
return [3 /*break*/, 5]; | ||
case 4: | ||
error_1 = _d.sent(); | ||
error_1 = _c.sent(); | ||
console.error(error_1.message); | ||
return [3 /*break*/, 5]; | ||
return [2 /*return*/, { error: error_1 }]; | ||
case 5: | ||
_b = this.remotePeerConnection, id = _b.id, localDescription = _b.localDescription; | ||
_a = this.remotePeerConnection, id = _a.id, localDescription = _a.localDescription; | ||
configuration = __assign({ | ||
@@ -168,12 +170,12 @@ // @ts-ignore | ||
}); | ||
_d.label = 6; | ||
_c.label = 6; | ||
case 6: | ||
_d.trys.push([6, 16, , 17]); | ||
_c.trys.push([6, 16, , 17]); | ||
return [4 /*yield*/, this.localPeerConnection.setRemoteDescription(localDescription)]; | ||
case 7: | ||
_d.sent(); | ||
_c.sent(); | ||
this.localPeerConnection.addEventListener('datachannel', this.onDataChannel, { once: true }); | ||
return [4 /*yield*/, this.localPeerConnection.createAnswer()]; | ||
case 8: | ||
originalAnswer = _d.sent(); | ||
originalAnswer = _c.sent(); | ||
updatedAnswer = new RTCSessionDescription({ | ||
@@ -185,6 +187,6 @@ type: 'answer', | ||
case 9: | ||
_d.sent(); | ||
_d.label = 10; | ||
_c.sent(); | ||
_c.label = 10; | ||
case 10: | ||
_d.trys.push([10, 12, , 13]); | ||
_c.trys.push([10, 12, , 13]); | ||
return [4 /*yield*/, fetch(host + "/connections/" + id + "/remote-description", { | ||
@@ -198,8 +200,8 @@ method: 'POST', | ||
case 11: | ||
_d.sent(); | ||
_c.sent(); | ||
return [3 /*break*/, 13]; | ||
case 12: | ||
error_2 = _d.sent(); | ||
error_2 = _c.sent(); | ||
console.error(error_2.message); | ||
return [3 /*break*/, 13]; | ||
return [2 /*return*/, { error: error_2 }]; | ||
case 13: | ||
@@ -216,5 +218,6 @@ waitForDataChannel = function () { | ||
case 14: | ||
_d.sent(); | ||
_d.label = 15; | ||
_c.sent(); | ||
_c.label = 15; | ||
case 15: return [2 /*return*/, { | ||
userData: userData, | ||
localPeerConnection: this.localPeerConnection, | ||
@@ -225,6 +228,6 @@ dataChannel: this.dataChannel, | ||
case 16: | ||
error_3 = _d.sent(); | ||
error_3 = _c.sent(); | ||
console.error(error_3.message); | ||
this.localPeerConnection.close(); | ||
throw error_3; | ||
return [2 /*return*/, { error: error_3 }]; | ||
case 17: return [2 /*return*/]; | ||
@@ -231,0 +234,0 @@ } |
@@ -7,4 +7,10 @@ import ConnectionsManagerClient from './connectionsManager'; | ||
id: ChannelId; | ||
connect(connectionsManager: ConnectionsManagerClient): Promise<Error | null>; | ||
connect(connectionsManager: ConnectionsManagerClient): Promise<{ | ||
error: any; | ||
userData?: undefined; | ||
} | { | ||
userData: {}; | ||
error?: undefined; | ||
}>; | ||
} | ||
//# sourceMappingURL=peerConnection.d.ts.map |
@@ -45,3 +45,3 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var webRTCPcSupported, _a, localPeerConnection, dataChannel, id, error; | ||
var webRTCPcSupported, _a, localPeerConnection, dataChannel, id, userData, error, error; | ||
return __generator(this, function (_b) { | ||
@@ -57,11 +57,15 @@ switch (_b.label) { | ||
case 1: | ||
_a = _b.sent(), localPeerConnection = _a.localPeerConnection, dataChannel = _a.dataChannel, id = _a.id; | ||
_a = _b.sent(), localPeerConnection = _a.localPeerConnection, dataChannel = _a.dataChannel, id = _a.id, userData = _a.userData, error = _a.error; | ||
if (error) | ||
return [2 /*return*/, { error: error }]; | ||
if (!localPeerConnection || !dataChannel || !id || !userData) | ||
return [2 /*return*/, { error: new Error('Something went wrong in "await connectionsManager.connect()"') }]; | ||
this.localPeerConnection = localPeerConnection; | ||
this.dataChannel = dataChannel; | ||
this.id = id; | ||
return [2 /*return*/, null]; | ||
return [2 /*return*/, { userData: userData }]; | ||
case 2: | ||
error = new Error(constants_1.ERRORS.BROWSER_NOT_SUPPORTED); | ||
console.error(error.message); | ||
return [2 /*return*/, error]; | ||
return [2 /*return*/, { error: error }]; | ||
} | ||
@@ -68,0 +72,0 @@ }); |
{ | ||
"name": "@geckos.io/client", | ||
"version": "1.6.0", | ||
"version": "1.6.1", | ||
"description": "Real-time client/server communication over UDP using WebRTC and Node.js", | ||
@@ -46,3 +46,3 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"@geckos.io/common": "^1.6.0" | ||
"@geckos.io/common": "^1.6.1" | ||
}, | ||
@@ -49,0 +49,0 @@ "funding": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
50500
681
4
Updated@geckos.io/common@^1.6.1