@needle-tools/engine 3.27.5-beta → 3.28.0-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/needle-engine.js +4692 -4719
- package/dist/needle-engine.light.js +4434 -4461
- package/dist/needle-engine.light.min.js +226 -219
- package/dist/needle-engine.light.umd.cjs +283 -276
- package/dist/needle-engine.min.js +228 -221
- package/dist/needle-engine.umd.cjs +238 -231
- package/lib/engine/engine_shims.js +0 -1
- package/lib/engine/engine_shims.js.map +1 -1
- package/lib/engine-components/Renderer.js +12 -0
- package/lib/engine-components/Renderer.js.map +1 -1
- package/lib/engine-components/export/usdz/ThreeUSDZExporter.d.ts +14 -5
- package/lib/engine-components/export/usdz/ThreeUSDZExporter.js +26 -15
- package/lib/engine-components/export/usdz/ThreeUSDZExporter.js.map +1 -1
- package/package.json +1 -1
- package/src/engine/codegen/register_types.ts +2 -2
- package/src/engine/engine_shims.ts +0 -2
- package/src/engine-components/Renderer.ts +13 -0
- package/src/engine-components/export/usdz/ThreeUSDZExporter.ts +36 -24
- package/src/engine/dist/api.js +0 -73
- package/src/engine/dist/api.js.meta +0 -7
- package/src/engine/dist/engine_networking_streams.js +0 -474
- package/src/engine/dist/engine_networking_streams.js.meta +0 -7
- package/src/engine-components/dist/AudioSource.js +0 -513
- package/src/engine-components/dist/AudioSource.js.meta +0 -7
- package/src/engine-components/dist/ScreenCapture.js +0 -490
- package/src/engine-components/dist/ScreenCapture.js.meta +0 -7
- package/src/engine-components/dist/VideoPlayer.js +0 -888
- package/src/engine-components/dist/VideoPlayer.js.meta +0 -7
- package/src/engine-components/dist/Voip2.js +0 -46
- package/src/engine-components/dist/Voip2.js.meta +0 -7
- package/src/engine-schemes/dist/api.js +0 -17
- package/src/engine-schemes/dist/api.js.meta +0 -7
- package/src/engine-schemes/dist/schemes.js +0 -25
- package/src/engine-schemes/dist/schemes.js.meta +0 -7
- package/src/engine-schemes/dist/synced-camera-model.js +0 -74
- package/src/engine-schemes/dist/synced-camera-model.js.meta +0 -7
- package/src/engine-schemes/dist/synced-transform-model.js +0 -73
- package/src/engine-schemes/dist/synced-transform-model.js.meta +0 -7
- package/src/engine-schemes/dist/transform.js +0 -46
- package/src/engine-schemes/dist/transform.js.meta +0 -7
- package/src/engine-schemes/dist/vec2.js +0 -32
- package/src/engine-schemes/dist/vec2.js.meta +0 -7
- package/src/engine-schemes/dist/vec3.js +0 -36
- package/src/engine-schemes/dist/vec3.js.meta +0 -7
- package/src/engine-schemes/dist/vec4.js +0 -40
- package/src/engine-schemes/dist/vec4.js.meta +0 -7
- package/src/engine-schemes/dist/vr-user-state-buffer.js +0 -110
- package/src/engine-schemes/dist/vr-user-state-buffer.js.meta +0 -7
- package/src/engine-schemes/flatc.exe +0 -0
|
@@ -1,490 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
extendStatics(d, b);
|
|
11
|
-
function __() { this.constructor = d; }
|
|
12
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
13
|
-
};
|
|
14
|
-
})();
|
|
15
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
16
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
17
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
18
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
19
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
20
|
-
};
|
|
21
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
22
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
24
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
25
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
26
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
27
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
|
-
});
|
|
29
|
-
};
|
|
30
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
31
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
32
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
33
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
34
|
-
function step(op) {
|
|
35
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
36
|
-
while (_) try {
|
|
37
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
38
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
39
|
-
switch (op[0]) {
|
|
40
|
-
case 0: case 1: t = op; break;
|
|
41
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
42
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
43
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
44
|
-
default:
|
|
45
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
46
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
47
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
48
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
49
|
-
if (t[2]) _.ops.pop();
|
|
50
|
-
_.trys.pop(); continue;
|
|
51
|
-
}
|
|
52
|
-
op = body.call(thisArg, _);
|
|
53
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
54
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
exports.__esModule = true;
|
|
58
|
-
exports.ScreenCapture = exports.ScreenCaptureMode = exports.ScreenCaptureDevice = void 0;
|
|
59
|
-
var Component_js_1 = require("./Component.js");
|
|
60
|
-
var VideoPlayer_js_1 = require("./VideoPlayer.js");
|
|
61
|
-
var engine_serialization_js_1 = require("../engine/engine_serialization.js");
|
|
62
|
-
var AudioSource_js_1 = require("./AudioSource.js");
|
|
63
|
-
var engine_utils_js_1 = require("../engine/engine_utils.js");
|
|
64
|
-
var index_js_1 = require("../engine/debug/index.js");
|
|
65
|
-
var engine_networking_streams_js_1 = require("../engine/engine_networking_streams.js");
|
|
66
|
-
var debug = engine_utils_js_1.getParam("debugscreensharing");
|
|
67
|
-
var ScreenCaptureDevice;
|
|
68
|
-
(function (ScreenCaptureDevice) {
|
|
69
|
-
ScreenCaptureDevice[ScreenCaptureDevice["Screen"] = 0] = "Screen";
|
|
70
|
-
ScreenCaptureDevice[ScreenCaptureDevice["Camera"] = 1] = "Camera";
|
|
71
|
-
/** Please note that canvas streaming might not work reliably on chrome: https://bugs.chromium.org/p/chromium/issues/detail?id=1156408 */
|
|
72
|
-
ScreenCaptureDevice[ScreenCaptureDevice["Canvas"] = 2] = "Canvas";
|
|
73
|
-
/** When using Microphone only the voice will be sent */
|
|
74
|
-
ScreenCaptureDevice[ScreenCaptureDevice["Microphone"] = 3] = "Microphone";
|
|
75
|
-
})(ScreenCaptureDevice = exports.ScreenCaptureDevice || (exports.ScreenCaptureDevice = {}));
|
|
76
|
-
var ScreenCaptureMode;
|
|
77
|
-
(function (ScreenCaptureMode) {
|
|
78
|
-
ScreenCaptureMode[ScreenCaptureMode["Idle"] = 0] = "Idle";
|
|
79
|
-
ScreenCaptureMode[ScreenCaptureMode["Sending"] = 1] = "Sending";
|
|
80
|
-
ScreenCaptureMode[ScreenCaptureMode["Receiving"] = 2] = "Receiving";
|
|
81
|
-
})(ScreenCaptureMode = exports.ScreenCaptureMode || (exports.ScreenCaptureMode = {}));
|
|
82
|
-
var ScreenCapture = /** @class */ (function (_super) {
|
|
83
|
-
__extends(ScreenCapture, _super);
|
|
84
|
-
function ScreenCapture() {
|
|
85
|
-
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
86
|
-
_this.allowStartOnClick = true;
|
|
87
|
-
// TODO: make this a property
|
|
88
|
-
/** Note: this can not be changed while streaming */
|
|
89
|
-
_this.device = ScreenCaptureDevice.Screen;
|
|
90
|
-
_this._requestOpen = false;
|
|
91
|
-
_this._currentStream = null;
|
|
92
|
-
_this._currentMode = ScreenCaptureMode.Idle;
|
|
93
|
-
_this.onReceiveStream = function (evt) {
|
|
94
|
-
var _a;
|
|
95
|
-
if (((_a = evt.stream) === null || _a === void 0 ? void 0 : _a.active) !== true)
|
|
96
|
-
return;
|
|
97
|
-
_this.setStream(evt.stream, ScreenCaptureMode.Receiving);
|
|
98
|
-
};
|
|
99
|
-
_this.onCallEnded = function (_evt) {
|
|
100
|
-
if (debug)
|
|
101
|
-
console.log("CALL ENDED", _this.isReceiving, _this === null || _this === void 0 ? void 0 : _this.screenspace);
|
|
102
|
-
if (_this.isReceiving)
|
|
103
|
-
_this.screenspace = false;
|
|
104
|
-
};
|
|
105
|
-
return _this;
|
|
106
|
-
// private _cameraSelectionWindow : Window | null = null;
|
|
107
|
-
// private openWindowToSelectCamera(){
|
|
108
|
-
// }
|
|
109
|
-
}
|
|
110
|
-
ScreenCapture.prototype.onPointerEnter = function () {
|
|
111
|
-
if (!this.allowStartOnClick)
|
|
112
|
-
return;
|
|
113
|
-
this.context.input.setCursorPointer();
|
|
114
|
-
};
|
|
115
|
-
ScreenCapture.prototype.onPointerExit = function () {
|
|
116
|
-
if (!this.allowStartOnClick)
|
|
117
|
-
return;
|
|
118
|
-
this.context.input.setCursorNormal();
|
|
119
|
-
};
|
|
120
|
-
ScreenCapture.prototype.onPointerClick = function (evt) {
|
|
121
|
-
var _a;
|
|
122
|
-
if (!this.allowStartOnClick)
|
|
123
|
-
return;
|
|
124
|
-
if (evt && evt.pointerId !== 0)
|
|
125
|
-
return;
|
|
126
|
-
if (this.context.connection.isInRoom === false)
|
|
127
|
-
return;
|
|
128
|
-
if (this.isReceiving && ((_a = this.videoPlayer) === null || _a === void 0 ? void 0 : _a.isPlaying)) {
|
|
129
|
-
if (this.videoPlayer)
|
|
130
|
-
this.videoPlayer.screenspace = !this.videoPlayer.screenspace;
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
if (this.isSending) {
|
|
134
|
-
this.close();
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
this.share();
|
|
138
|
-
};
|
|
139
|
-
Object.defineProperty(ScreenCapture.prototype, "videoPlayer", {
|
|
140
|
-
get: function () { return this._videoPlayer; },
|
|
141
|
-
set: function (val) {
|
|
142
|
-
if (this._videoPlayer && (this.isSending || this.isReceiving)) {
|
|
143
|
-
this._videoPlayer.stop();
|
|
144
|
-
}
|
|
145
|
-
this._videoPlayer = val;
|
|
146
|
-
if (this._videoPlayer && this._currentStream && (this.isSending || this.isReceiving)) {
|
|
147
|
-
this._videoPlayer.setVideo(this._currentStream);
|
|
148
|
-
}
|
|
149
|
-
},
|
|
150
|
-
enumerable: false,
|
|
151
|
-
configurable: true
|
|
152
|
-
});
|
|
153
|
-
Object.defineProperty(ScreenCapture.prototype, "screenspace", {
|
|
154
|
-
get: function () { var _a, _b; return (_b = (_a = this.videoPlayer) === null || _a === void 0 ? void 0 : _a.screenspace) !== null && _b !== void 0 ? _b : false; },
|
|
155
|
-
set: function (v) { if (this.videoPlayer)
|
|
156
|
-
this.videoPlayer.screenspace = v; },
|
|
157
|
-
enumerable: false,
|
|
158
|
-
configurable: true
|
|
159
|
-
});
|
|
160
|
-
Object.defineProperty(ScreenCapture.prototype, "currentScream", {
|
|
161
|
-
get: function () {
|
|
162
|
-
return this._currentStream;
|
|
163
|
-
},
|
|
164
|
-
enumerable: false,
|
|
165
|
-
configurable: true
|
|
166
|
-
});
|
|
167
|
-
Object.defineProperty(ScreenCapture.prototype, "currentMode", {
|
|
168
|
-
get: function () {
|
|
169
|
-
return this._currentMode;
|
|
170
|
-
},
|
|
171
|
-
enumerable: false,
|
|
172
|
-
configurable: true
|
|
173
|
-
});
|
|
174
|
-
Object.defineProperty(ScreenCapture.prototype, "isSending", {
|
|
175
|
-
get: function () {
|
|
176
|
-
var _a;
|
|
177
|
-
return ((_a = this._currentStream) === null || _a === void 0 ? void 0 : _a.active) && this._currentMode === ScreenCaptureMode.Sending;
|
|
178
|
-
},
|
|
179
|
-
enumerable: false,
|
|
180
|
-
configurable: true
|
|
181
|
-
});
|
|
182
|
-
Object.defineProperty(ScreenCapture.prototype, "isReceiving", {
|
|
183
|
-
get: function () {
|
|
184
|
-
if (this._currentMode === ScreenCaptureMode.Receiving) {
|
|
185
|
-
if (!this._currentStream || this._currentStream.active === false)
|
|
186
|
-
return false;
|
|
187
|
-
// if any track is still live consider it active
|
|
188
|
-
var tracks = this._currentStream.getTracks();
|
|
189
|
-
for (var _i = 0, tracks_1 = tracks; _i < tracks_1.length; _i++) {
|
|
190
|
-
var track = tracks_1[_i];
|
|
191
|
-
if (track.readyState === "live")
|
|
192
|
-
return true;
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
return false;
|
|
196
|
-
},
|
|
197
|
-
enumerable: false,
|
|
198
|
-
configurable: true
|
|
199
|
-
});
|
|
200
|
-
Object.defineProperty(ScreenCapture.prototype, "requiresVideoPlayer", {
|
|
201
|
-
get: function () { return this.device !== ScreenCaptureDevice.Microphone; },
|
|
202
|
-
enumerable: false,
|
|
203
|
-
configurable: true
|
|
204
|
-
});
|
|
205
|
-
ScreenCapture.prototype.awake = function () {
|
|
206
|
-
var _this = this;
|
|
207
|
-
if (debug)
|
|
208
|
-
console.log("Screensharing", this.name, this);
|
|
209
|
-
AudioSource_js_1.AudioSource.registerWaitForAllowAudio(function () {
|
|
210
|
-
if (_this.videoPlayer && _this._currentStream && _this._currentMode === ScreenCaptureMode.Receiving) {
|
|
211
|
-
_this.videoPlayer.playInBackground = true;
|
|
212
|
-
_this.videoPlayer.setVideo(_this._currentStream);
|
|
213
|
-
}
|
|
214
|
-
});
|
|
215
|
-
var handle = engine_networking_streams_js_1.PeerHandle.getOrCreate(this.context, this.guid);
|
|
216
|
-
this._net = new engine_networking_streams_js_1.NetworkedStreams(this.context, handle);
|
|
217
|
-
};
|
|
218
|
-
ScreenCapture.prototype.onEnable = function () {
|
|
219
|
-
var _a, _b, _c;
|
|
220
|
-
(_a = this._net) === null || _a === void 0 ? void 0 : _a.enable();
|
|
221
|
-
//@ts-ignore
|
|
222
|
-
(_b = this._net) === null || _b === void 0 ? void 0 : _b.addEventListener(engine_networking_streams_js_1.PeerEvent.ReceiveStream, this.onReceiveStream);
|
|
223
|
-
//@ts-ignore
|
|
224
|
-
(_c = this._net) === null || _c === void 0 ? void 0 : _c.addEventListener(engine_networking_streams_js_1.PeerEvent.CallEnded, this.onCallEnded);
|
|
225
|
-
};
|
|
226
|
-
ScreenCapture.prototype.onDisable = function () {
|
|
227
|
-
var _a, _b, _c;
|
|
228
|
-
//@ts-ignore
|
|
229
|
-
(_a = this._net) === null || _a === void 0 ? void 0 : _a.removeEventListener(engine_networking_streams_js_1.PeerEvent.ReceiveStream, this.onReceiveStream);
|
|
230
|
-
//@ts-ignore
|
|
231
|
-
(_b = this._net) === null || _b === void 0 ? void 0 : _b.removeEventListener(engine_networking_streams_js_1.PeerEvent.CallEnded, this.onCallEnded);
|
|
232
|
-
(_c = this._net) === null || _c === void 0 ? void 0 : _c.disable();
|
|
233
|
-
this.close();
|
|
234
|
-
};
|
|
235
|
-
/** Call to begin screensharing */
|
|
236
|
-
ScreenCapture.prototype.share = function (opts) {
|
|
237
|
-
var _a, _b;
|
|
238
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
239
|
-
var settings, displayMediaOptions, videoOptions, _c, myVideo, fps, stream, myStream, err_1;
|
|
240
|
-
return __generator(this, function (_d) {
|
|
241
|
-
switch (_d.label) {
|
|
242
|
-
case 0:
|
|
243
|
-
if (opts === null || opts === void 0 ? void 0 : opts.device)
|
|
244
|
-
this.device = opts.device;
|
|
245
|
-
if (!this.videoPlayer && this.requiresVideoPlayer) {
|
|
246
|
-
if (!this._videoPlayer) {
|
|
247
|
-
this._videoPlayer = (_a = Component_js_1.GameObject.getComponent(this.gameObject, VideoPlayer_js_1.VideoPlayer)) !== null && _a !== void 0 ? _a : undefined;
|
|
248
|
-
}
|
|
249
|
-
if (!this.videoPlayer) {
|
|
250
|
-
console.warn("Can not share video without a videoPlayer assigned");
|
|
251
|
-
return [2 /*return*/];
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
this._requestOpen = true;
|
|
255
|
-
_d.label = 1;
|
|
256
|
-
case 1:
|
|
257
|
-
_d.trys.push([1, 9, , 10]);
|
|
258
|
-
settings = (_b = opts === null || opts === void 0 ? void 0 : opts.constraints) !== null && _b !== void 0 ? _b : {
|
|
259
|
-
echoCancellation: true,
|
|
260
|
-
autoGainControl: false
|
|
261
|
-
};
|
|
262
|
-
displayMediaOptions = {
|
|
263
|
-
video: settings,
|
|
264
|
-
audio: settings
|
|
265
|
-
};
|
|
266
|
-
videoOptions = displayMediaOptions.video;
|
|
267
|
-
if (videoOptions !== undefined && typeof videoOptions !== "boolean") {
|
|
268
|
-
// Set default video settings
|
|
269
|
-
if (!videoOptions.width)
|
|
270
|
-
videoOptions.width = { max: 1920 };
|
|
271
|
-
if (!videoOptions.height)
|
|
272
|
-
videoOptions.height = { max: 1920 };
|
|
273
|
-
if (!videoOptions.aspectRatio)
|
|
274
|
-
videoOptions.aspectRatio = { ideal: 1.7777777778 };
|
|
275
|
-
if (!videoOptions.frameRate)
|
|
276
|
-
videoOptions.frameRate = { ideal: 24 };
|
|
277
|
-
if (!videoOptions.facingMode)
|
|
278
|
-
videoOptions.facingMode = { ideal: "user" };
|
|
279
|
-
}
|
|
280
|
-
_c = this.device;
|
|
281
|
-
switch (_c) {
|
|
282
|
-
case ScreenCaptureDevice.Camera: return [3 /*break*/, 2];
|
|
283
|
-
case ScreenCaptureDevice.Screen: return [3 /*break*/, 3];
|
|
284
|
-
case ScreenCaptureDevice.Canvas: return [3 /*break*/, 5];
|
|
285
|
-
case ScreenCaptureDevice.Microphone: return [3 /*break*/, 6];
|
|
286
|
-
}
|
|
287
|
-
return [3 /*break*/, 8];
|
|
288
|
-
case 2:
|
|
289
|
-
this.tryShareUserCamera(displayMediaOptions, opts);
|
|
290
|
-
return [3 /*break*/, 8];
|
|
291
|
-
case 3:
|
|
292
|
-
if (!navigator.mediaDevices.getDisplayMedia) {
|
|
293
|
-
console.error("No getDisplayMedia support");
|
|
294
|
-
return [2 /*return*/];
|
|
295
|
-
}
|
|
296
|
-
return [4 /*yield*/, navigator.mediaDevices.getDisplayMedia(displayMediaOptions)];
|
|
297
|
-
case 4:
|
|
298
|
-
myVideo = _d.sent();
|
|
299
|
-
if (this._requestOpen) {
|
|
300
|
-
this.setStream(myVideo, ScreenCaptureMode.Sending);
|
|
301
|
-
}
|
|
302
|
-
else
|
|
303
|
-
engine_networking_streams_js_1.disposeStream(myVideo);
|
|
304
|
-
return [3 /*break*/, 8];
|
|
305
|
-
case 5:
|
|
306
|
-
fps = 0;
|
|
307
|
-
stream = this.context.renderer.domElement.captureStream(fps);
|
|
308
|
-
this.setStream(stream, ScreenCaptureMode.Sending);
|
|
309
|
-
return [3 /*break*/, 8];
|
|
310
|
-
case 6:
|
|
311
|
-
if (!navigator.mediaDevices.getDisplayMedia) {
|
|
312
|
-
console.error("No getDisplayMedia support");
|
|
313
|
-
return [2 /*return*/];
|
|
314
|
-
}
|
|
315
|
-
displayMediaOptions.video = false;
|
|
316
|
-
return [4 /*yield*/, navigator.mediaDevices.getUserMedia(displayMediaOptions)];
|
|
317
|
-
case 7:
|
|
318
|
-
myStream = _d.sent();
|
|
319
|
-
if (this._requestOpen) {
|
|
320
|
-
this.setStream(myStream, ScreenCaptureMode.Sending);
|
|
321
|
-
}
|
|
322
|
-
else
|
|
323
|
-
engine_networking_streams_js_1.disposeStream(myStream);
|
|
324
|
-
return [3 /*break*/, 8];
|
|
325
|
-
case 8: return [3 /*break*/, 10];
|
|
326
|
-
case 9:
|
|
327
|
-
err_1 = _d.sent();
|
|
328
|
-
if (err_1.name === "NotAllowedError") {
|
|
329
|
-
// user cancelled stream selection
|
|
330
|
-
console.log("Selection cancelled");
|
|
331
|
-
this._requestOpen = false;
|
|
332
|
-
return [2 /*return*/];
|
|
333
|
-
}
|
|
334
|
-
console.error("Error opening video", err_1);
|
|
335
|
-
return [3 /*break*/, 10];
|
|
336
|
-
case 10: return [2 /*return*/];
|
|
337
|
-
}
|
|
338
|
-
});
|
|
339
|
-
});
|
|
340
|
-
};
|
|
341
|
-
ScreenCapture.prototype.close = function () {
|
|
342
|
-
var _a;
|
|
343
|
-
this._requestOpen = false;
|
|
344
|
-
if (this._currentStream) {
|
|
345
|
-
if (debug)
|
|
346
|
-
console.warn("Close current stream / disposing resources, stream was active?", this._currentStream.active);
|
|
347
|
-
(_a = this._net) === null || _a === void 0 ? void 0 : _a.stopSendingStream(this._currentStream);
|
|
348
|
-
engine_networking_streams_js_1.disposeStream(this._currentStream);
|
|
349
|
-
this._currentMode = ScreenCaptureMode.Idle;
|
|
350
|
-
this._currentStream = null;
|
|
351
|
-
}
|
|
352
|
-
};
|
|
353
|
-
ScreenCapture.prototype.setStream = function (stream, mode) {
|
|
354
|
-
var _this = this;
|
|
355
|
-
var _a, _b, _c;
|
|
356
|
-
if (stream === this._currentStream)
|
|
357
|
-
return;
|
|
358
|
-
this.close();
|
|
359
|
-
if (!stream)
|
|
360
|
-
return;
|
|
361
|
-
this._currentStream = stream;
|
|
362
|
-
this._requestOpen = true;
|
|
363
|
-
this._currentMode = mode;
|
|
364
|
-
var isVideoStream = this.device !== ScreenCaptureDevice.Microphone;
|
|
365
|
-
var isSending = mode === ScreenCaptureMode.Sending;
|
|
366
|
-
if (isVideoStream) {
|
|
367
|
-
if (this._videoPlayer)
|
|
368
|
-
this._videoPlayer.setVideo(stream);
|
|
369
|
-
else
|
|
370
|
-
console.error("No video player assigned for video stream");
|
|
371
|
-
}
|
|
372
|
-
else {
|
|
373
|
-
if (!this._audioSource) {
|
|
374
|
-
this._audioSource = new AudioSource_js_1.AudioSource();
|
|
375
|
-
this._audioSource.spatialBlend = 0;
|
|
376
|
-
this._audioSource.volume = 1;
|
|
377
|
-
this.gameObject.addComponent(this._audioSource);
|
|
378
|
-
}
|
|
379
|
-
if (!isSending) {
|
|
380
|
-
console.log("PLAY", stream.getAudioTracks());
|
|
381
|
-
this._audioSource.volume = 1;
|
|
382
|
-
(_a = this._audioSource) === null || _a === void 0 ? void 0 : _a.play(stream);
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
if (isSending) {
|
|
386
|
-
(_b = this._net) === null || _b === void 0 ? void 0 : _b.startSendingStream(stream);
|
|
387
|
-
}
|
|
388
|
-
// Mute audio for the video we are sending
|
|
389
|
-
if (isSending) {
|
|
390
|
-
if (this._videoPlayer)
|
|
391
|
-
this._videoPlayer.muted = true;
|
|
392
|
-
(_c = this._audioSource) === null || _c === void 0 ? void 0 : _c.stop();
|
|
393
|
-
}
|
|
394
|
-
var _loop_1 = function (track) {
|
|
395
|
-
track.addEventListener("ended", function () {
|
|
396
|
-
if (debug)
|
|
397
|
-
console.log("Track ended", track);
|
|
398
|
-
_this.close();
|
|
399
|
-
});
|
|
400
|
-
if (debug) {
|
|
401
|
-
if (track.kind === "video") {
|
|
402
|
-
if (isSending)
|
|
403
|
-
console.log("Video →", track.getSettings());
|
|
404
|
-
else
|
|
405
|
-
console.log("Video ←", track.getSettings());
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
};
|
|
409
|
-
for (var _i = 0, _d = stream.getTracks(); _i < _d.length; _i++) {
|
|
410
|
-
var track = _d[_i];
|
|
411
|
-
_loop_1(track);
|
|
412
|
-
}
|
|
413
|
-
};
|
|
414
|
-
ScreenCapture.prototype.tryShareUserCamera = function (opts, options) {
|
|
415
|
-
var _a;
|
|
416
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
417
|
-
var devices, _i, devices_1, dev, id, useDevice, userMedia, err_2;
|
|
418
|
-
return __generator(this, function (_b) {
|
|
419
|
-
switch (_b.label) {
|
|
420
|
-
case 0: return [4 /*yield*/, navigator.mediaDevices.enumerateDevices()];
|
|
421
|
-
case 1:
|
|
422
|
-
devices = (_b.sent()).filter(function (d) { return d.kind === "videoinput"; });
|
|
423
|
-
if (debug)
|
|
424
|
-
console.log("Request camera", devices);
|
|
425
|
-
_i = 0, devices_1 = devices;
|
|
426
|
-
_b.label = 2;
|
|
427
|
-
case 2:
|
|
428
|
-
if (!(_i < devices_1.length)) return [3 /*break*/, 7];
|
|
429
|
-
dev = devices_1[_i];
|
|
430
|
-
_b.label = 3;
|
|
431
|
-
case 3:
|
|
432
|
-
_b.trys.push([3, 5, , 6]);
|
|
433
|
-
if (!this._requestOpen)
|
|
434
|
-
return [3 /*break*/, 7];
|
|
435
|
-
if (dev.kind !== "videoinput")
|
|
436
|
-
return [3 /*break*/, 6];
|
|
437
|
-
id = dev.deviceId;
|
|
438
|
-
if ((options === null || options === void 0 ? void 0 : options.deviceId) !== undefined) {
|
|
439
|
-
if (id !== options.deviceId)
|
|
440
|
-
return [3 /*break*/, 6];
|
|
441
|
-
}
|
|
442
|
-
useDevice = (_a = options === null || options === void 0 ? void 0 : options.deviceFilter) === null || _a === void 0 ? void 0 : _a.call(this, dev);
|
|
443
|
-
if (useDevice === false)
|
|
444
|
-
return [3 /*break*/, 6];
|
|
445
|
-
if (opts.video !== false) {
|
|
446
|
-
if (typeof opts.video === "undefined" || typeof opts.video === "boolean") {
|
|
447
|
-
opts.video = {};
|
|
448
|
-
}
|
|
449
|
-
opts.video.deviceId = id;
|
|
450
|
-
}
|
|
451
|
-
return [4 /*yield*/, navigator.mediaDevices.getUserMedia(opts)];
|
|
452
|
-
case 4:
|
|
453
|
-
userMedia = _b.sent();
|
|
454
|
-
if (this._requestOpen) {
|
|
455
|
-
this.setStream(userMedia, ScreenCaptureMode.Sending);
|
|
456
|
-
}
|
|
457
|
-
else
|
|
458
|
-
engine_networking_streams_js_1.disposeStream(userMedia);
|
|
459
|
-
if (debug)
|
|
460
|
-
console.log("Selected camera", dev);
|
|
461
|
-
return [3 /*break*/, 7];
|
|
462
|
-
case 5:
|
|
463
|
-
err_2 = _b.sent();
|
|
464
|
-
// First message is firefox, second is chrome when the video source is already in use by another app
|
|
465
|
-
if (err_2.message === "Failed to allocate videosource" || err_2.message === "Could not start video source") {
|
|
466
|
-
index_js_1.showBalloonWarning("Failed to start video: Try another camera (Code " + err_2.code + ")");
|
|
467
|
-
console.warn(err_2);
|
|
468
|
-
return [3 /*break*/, 6];
|
|
469
|
-
}
|
|
470
|
-
else {
|
|
471
|
-
console.error("Failed to get user media", err_2.message, err_2.code, err_2);
|
|
472
|
-
}
|
|
473
|
-
return [3 /*break*/, 6];
|
|
474
|
-
case 6:
|
|
475
|
-
_i++;
|
|
476
|
-
return [3 /*break*/, 2];
|
|
477
|
-
case 7: return [2 /*return*/];
|
|
478
|
-
}
|
|
479
|
-
});
|
|
480
|
-
});
|
|
481
|
-
};
|
|
482
|
-
__decorate([
|
|
483
|
-
engine_serialization_js_1.serializable(VideoPlayer_js_1.VideoPlayer)
|
|
484
|
-
], ScreenCapture.prototype, "videoPlayer");
|
|
485
|
-
__decorate([
|
|
486
|
-
engine_serialization_js_1.serializable()
|
|
487
|
-
], ScreenCapture.prototype, "device");
|
|
488
|
-
return ScreenCapture;
|
|
489
|
-
}(Component_js_1.Behaviour));
|
|
490
|
-
exports.ScreenCapture = ScreenCapture;
|