@chaomingd/design 0.0.68
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/LICENSE +21 -0
- package/README.md +23 -0
- package/dist/esm/CheckGroup/context.d.ts +9 -0
- package/dist/esm/CheckGroup/context.js +6 -0
- package/dist/esm/CheckGroup/hooks/useCheckGroup.d.ts +21 -0
- package/dist/esm/CheckGroup/hooks/useCheckGroup.js +180 -0
- package/dist/esm/CheckGroup/index.d.ts +9 -0
- package/dist/esm/CheckGroup/index.js +79 -0
- package/dist/esm/CheckGroup/type.d.ts +28 -0
- package/dist/esm/CheckGroup/type.js +1 -0
- package/dist/esm/Grid/index.d.ts +15 -0
- package/dist/esm/Grid/index.js +64 -0
- package/dist/esm/Grid/index.less +7 -0
- package/dist/esm/KaTeXRenderer/index.d.ts +9 -0
- package/dist/esm/KaTeXRenderer/index.js +33 -0
- package/dist/esm/KaTeXRenderer/index.less +0 -0
- package/dist/esm/PixelPlayer/index.d.ts +28 -0
- package/dist/esm/PixelPlayer/index.js +118 -0
- package/dist/esm/PixelPlayer/index.less +29 -0
- package/dist/esm/PixelPlayer/lib/peer-stream.d.ts +62 -0
- package/dist/esm/PixelPlayer/lib/peer-stream.js +876 -0
- package/dist/esm/PixelPlayer/useAutoLayoutContainer.d.ts +2 -0
- package/dist/esm/PixelPlayer/useAutoLayoutContainer.js +53 -0
- package/dist/esm/PixelPlayer/useVideoWithCustomEvent.d.ts +5 -0
- package/dist/esm/PixelPlayer/useVideoWithCustomEvent.js +37 -0
- package/dist/esm/Resizer/index.d.ts +17 -0
- package/dist/esm/Resizer/index.js +73 -0
- package/dist/esm/Resizer/index.less +73 -0
- package/dist/esm/SetupAntApp/index.d.ts +1 -0
- package/dist/esm/SetupAntApp/index.js +10 -0
- package/dist/esm/Transition/index.d.ts +4 -0
- package/dist/esm/Transition/index.js +132 -0
- package/dist/esm/Transition/type.d.ts +33 -0
- package/dist/esm/Transition/type.js +12 -0
- package/dist/esm/Transition/utils.d.ts +6 -0
- package/dist/esm/Transition/utils.js +15 -0
- package/dist/esm/UploadFile/components/IconButton/index.d.ts +11 -0
- package/dist/esm/UploadFile/components/IconButton/index.js +26 -0
- package/dist/esm/UploadFile/components/IconButton/index.less +58 -0
- package/dist/esm/UploadFile/components/Slash.d.ts +2 -0
- package/dist/esm/UploadFile/components/Slash.js +15 -0
- package/dist/esm/UploadFile/components/SvgIcons.d.ts +11 -0
- package/dist/esm/UploadFile/components/SvgIcons.js +141 -0
- package/dist/esm/UploadFile/hooks/useUploadModel.d.ts +16 -0
- package/dist/esm/UploadFile/hooks/useUploadModel.js +376 -0
- package/dist/esm/UploadFile/index.d.ts +4 -0
- package/dist/esm/UploadFile/index.js +277 -0
- package/dist/esm/UploadFile/index.less +274 -0
- package/dist/esm/UploadFile/type.d.ts +63 -0
- package/dist/esm/UploadFile/type.js +1 -0
- package/dist/esm/UploadFile/utils/formatBitString.d.ts +1 -0
- package/dist/esm/UploadFile/utils/formatBitString.js +9 -0
- package/dist/esm/UploadFile/utils/getExt.d.ts +1 -0
- package/dist/esm/UploadFile/utils/getExt.js +6 -0
- package/dist/esm/UploadFile/utils/isImage.d.ts +1 -0
- package/dist/esm/UploadFile/utils/isImage.js +8 -0
- package/dist/esm/UploadFile/utils/normalizeExt.d.ts +1 -0
- package/dist/esm/UploadFile/utils/normalizeExt.js +4 -0
- package/dist/esm/UploadFile/utils/validateFileTypes.d.ts +13 -0
- package/dist/esm/UploadFile/utils/validateFileTypes.js +83 -0
- package/dist/esm/UploadFile/utils/validateRule.d.ts +3 -0
- package/dist/esm/UploadFile/utils/validateRule.js +22 -0
- package/dist/esm/UploadFile/utils/validateUpload.d.ts +5 -0
- package/dist/esm/UploadFile/utils/validateUpload.js +35 -0
- package/dist/esm/constant/index.d.ts +7 -0
- package/dist/esm/constant/index.js +18 -0
- package/dist/esm/constants/cssPrefix.d.ts +1 -0
- package/dist/esm/constants/cssPrefix.js +1 -0
- package/dist/esm/getAntApp/index.d.ts +8 -0
- package/dist/esm/getAntApp/index.js +17 -0
- package/dist/esm/index.d.ts +10 -0
- package/dist/esm/index.js +10 -0
- package/dist/esm/interface.d.ts +1 -0
- package/dist/esm/interface.js +1 -0
- package/dist/esm/styles/cssVar.less +28 -0
- package/dist/esm/styles/reset.css +3 -0
- package/dist/esm/styles/var.d.ts +1 -0
- package/dist/esm/styles/var.js +1 -0
- package/dist/esm/styles/var.less +2 -0
- package/dist/esm/variable.less +52 -0
- package/dist/lib/CheckGroup/context.d.ts +9 -0
- package/dist/lib/CheckGroup/context.js +12 -0
- package/dist/lib/CheckGroup/hooks/useCheckGroup.d.ts +21 -0
- package/dist/lib/CheckGroup/hooks/useCheckGroup.js +164 -0
- package/dist/lib/CheckGroup/index.d.ts +9 -0
- package/dist/lib/CheckGroup/index.js +93 -0
- package/dist/lib/CheckGroup/type.d.ts +28 -0
- package/dist/lib/CheckGroup/type.js +5 -0
- package/dist/lib/Grid/index.d.ts +15 -0
- package/dist/lib/Grid/index.js +77 -0
- package/dist/lib/Grid/index.less +7 -0
- package/dist/lib/KaTeXRenderer/index.d.ts +9 -0
- package/dist/lib/KaTeXRenderer/index.js +41 -0
- package/dist/lib/KaTeXRenderer/index.less +0 -0
- package/dist/lib/PixelPlayer/index.d.ts +28 -0
- package/dist/lib/PixelPlayer/index.js +108 -0
- package/dist/lib/PixelPlayer/index.less +29 -0
- package/dist/lib/PixelPlayer/lib/peer-stream.d.ts +62 -0
- package/dist/lib/PixelPlayer/lib/peer-stream.js +707 -0
- package/dist/lib/PixelPlayer/useAutoLayoutContainer.d.ts +2 -0
- package/dist/lib/PixelPlayer/useAutoLayoutContainer.js +60 -0
- package/dist/lib/PixelPlayer/useVideoWithCustomEvent.d.ts +5 -0
- package/dist/lib/PixelPlayer/useVideoWithCustomEvent.js +35 -0
- package/dist/lib/Resizer/index.d.ts +17 -0
- package/dist/lib/Resizer/index.js +75 -0
- package/dist/lib/Resizer/index.less +73 -0
- package/dist/lib/SetupAntApp/index.d.ts +1 -0
- package/dist/lib/SetupAntApp/index.js +16 -0
- package/dist/lib/Transition/index.d.ts +4 -0
- package/dist/lib/Transition/index.js +128 -0
- package/dist/lib/Transition/type.d.ts +33 -0
- package/dist/lib/Transition/type.js +18 -0
- package/dist/lib/Transition/utils.d.ts +6 -0
- package/dist/lib/Transition/utils.js +22 -0
- package/dist/lib/UploadFile/components/IconButton/index.d.ts +11 -0
- package/dist/lib/UploadFile/components/IconButton/index.js +29 -0
- package/dist/lib/UploadFile/components/IconButton/index.less +58 -0
- package/dist/lib/UploadFile/components/Slash.d.ts +2 -0
- package/dist/lib/UploadFile/components/Slash.js +22 -0
- package/dist/lib/UploadFile/components/SvgIcons.d.ts +11 -0
- package/dist/lib/UploadFile/components/SvgIcons.js +158 -0
- package/dist/lib/UploadFile/hooks/useUploadModel.d.ts +16 -0
- package/dist/lib/UploadFile/hooks/useUploadModel.js +306 -0
- package/dist/lib/UploadFile/index.d.ts +4 -0
- package/dist/lib/UploadFile/index.js +280 -0
- package/dist/lib/UploadFile/index.less +274 -0
- package/dist/lib/UploadFile/type.d.ts +63 -0
- package/dist/lib/UploadFile/type.js +5 -0
- package/dist/lib/UploadFile/utils/formatBitString.d.ts +1 -0
- package/dist/lib/UploadFile/utils/formatBitString.js +15 -0
- package/dist/lib/UploadFile/utils/getExt.d.ts +1 -0
- package/dist/lib/UploadFile/utils/getExt.js +12 -0
- package/dist/lib/UploadFile/utils/isImage.d.ts +1 -0
- package/dist/lib/UploadFile/utils/isImage.js +14 -0
- package/dist/lib/UploadFile/utils/normalizeExt.d.ts +1 -0
- package/dist/lib/UploadFile/utils/normalizeExt.js +10 -0
- package/dist/lib/UploadFile/utils/validateFileTypes.d.ts +13 -0
- package/dist/lib/UploadFile/utils/validateFileTypes.js +87 -0
- package/dist/lib/UploadFile/utils/validateRule.d.ts +3 -0
- package/dist/lib/UploadFile/utils/validateRule.js +28 -0
- package/dist/lib/UploadFile/utils/validateUpload.d.ts +5 -0
- package/dist/lib/UploadFile/utils/validateUpload.js +31 -0
- package/dist/lib/constant/index.d.ts +7 -0
- package/dist/lib/constant/index.js +24 -0
- package/dist/lib/constants/cssPrefix.d.ts +1 -0
- package/dist/lib/constants/cssPrefix.js +7 -0
- package/dist/lib/getAntApp/index.d.ts +8 -0
- package/dist/lib/getAntApp/index.js +27 -0
- package/dist/lib/index.d.ts +10 -0
- package/dist/lib/index.js +69 -0
- package/dist/lib/interface.d.ts +1 -0
- package/dist/lib/interface.js +5 -0
- package/dist/lib/styles/cssVar.less +28 -0
- package/dist/lib/styles/reset.css +3 -0
- package/dist/lib/styles/var.d.ts +1 -0
- package/dist/lib/styles/var.js +7 -0
- package/dist/lib/styles/var.less +2 -0
- package/dist/lib/variable.less +52 -0
- package/package.json +54 -0
|
@@ -0,0 +1,876 @@
|
|
|
1
|
+
'4.27.2';
|
|
2
|
+
|
|
3
|
+
/* eslint-disable -- hack skills */
|
|
4
|
+
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
|
5
|
+
import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
|
|
6
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
7
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
8
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
9
|
+
import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
|
|
10
|
+
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
11
|
+
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
|
|
12
|
+
import _wrapNativeSuper from "@babel/runtime/helpers/esm/wrapNativeSuper";
|
|
13
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
14
|
+
// Must be kept in sync with JavaScriptKeyCodeToFKey C++ array.
|
|
15
|
+
// special keycodes different from KeyboardEvent.keyCode
|
|
16
|
+
var SpecialKeyCodes = {
|
|
17
|
+
Backspace: 8,
|
|
18
|
+
ShiftLeft: 16,
|
|
19
|
+
ControlLeft: 17,
|
|
20
|
+
AltLeft: 18,
|
|
21
|
+
ShiftRight: 253,
|
|
22
|
+
ControlRight: 254,
|
|
23
|
+
AltRight: 255
|
|
24
|
+
};
|
|
25
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button
|
|
26
|
+
var MouseButton = {
|
|
27
|
+
MainButton: 0,
|
|
28
|
+
// Left button.
|
|
29
|
+
AuxiliaryButton: 1,
|
|
30
|
+
// Wheel button.
|
|
31
|
+
SecondaryButton: 2,
|
|
32
|
+
// Right button.
|
|
33
|
+
FourthButton: 3,
|
|
34
|
+
// Browser Back button.
|
|
35
|
+
FifthButton: 4 // Browser Forward button.
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// Must be kept in sync with PixelStreamingProtocol::EToClientMsg C++ enum.
|
|
39
|
+
var RECEIVE = {
|
|
40
|
+
QualityControlOwnership: 0,
|
|
41
|
+
Response: 1,
|
|
42
|
+
Command: 2,
|
|
43
|
+
FreezeFrame: 3,
|
|
44
|
+
UnfreezeFrame: 4,
|
|
45
|
+
VideoEncoderAvgQP: 5,
|
|
46
|
+
LatencyTest: 6,
|
|
47
|
+
InitialSettings: 7
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// Must be kept in sync with PixelStreamingProtocol::EToUE4Msg C++ enum.
|
|
51
|
+
var SEND = {
|
|
52
|
+
/*
|
|
53
|
+
* Control Messages. Range = 0..49.
|
|
54
|
+
*/
|
|
55
|
+
IFrameRequest: 0,
|
|
56
|
+
RequestQualityControl: 1,
|
|
57
|
+
MaxFpsRequest: 2,
|
|
58
|
+
AverageBitrateRequest: 3,
|
|
59
|
+
StartStreaming: 4,
|
|
60
|
+
StopStreaming: 5,
|
|
61
|
+
LatencyTest: 6,
|
|
62
|
+
RequestInitialSettings: 7,
|
|
63
|
+
/*
|
|
64
|
+
* Input Messages. Range = 50..89.
|
|
65
|
+
*/
|
|
66
|
+
|
|
67
|
+
// Generic Input Messages. Range = 50..59.
|
|
68
|
+
UIInteraction: 50,
|
|
69
|
+
Command: 51,
|
|
70
|
+
// Keyboard Input Message. Range = 60..69.
|
|
71
|
+
KeyDown: 60,
|
|
72
|
+
KeyUp: 61,
|
|
73
|
+
KeyPress: 62,
|
|
74
|
+
// Mouse Input Messages. Range = 70..79.
|
|
75
|
+
MouseEnter: 70,
|
|
76
|
+
MouseLeave: 71,
|
|
77
|
+
MouseDown: 72,
|
|
78
|
+
MouseUp: 73,
|
|
79
|
+
MouseMove: 74,
|
|
80
|
+
MouseWheel: 75,
|
|
81
|
+
// Touch Input Messages. Range = 80..89.
|
|
82
|
+
TouchStart: 80,
|
|
83
|
+
TouchEnd: 81,
|
|
84
|
+
TouchMove: 82
|
|
85
|
+
};
|
|
86
|
+
var customEventsArray = ['initialize', 'connected', 'disconnected', 'tryConnect', 'message', 'error'];
|
|
87
|
+
export var PeerStream = /*#__PURE__*/function (_HTMLVideoElement) {
|
|
88
|
+
_inherits(PeerStream, _HTMLVideoElement);
|
|
89
|
+
var _super = _createSuper(PeerStream);
|
|
90
|
+
function PeerStream() {
|
|
91
|
+
var _this;
|
|
92
|
+
_classCallCheck(this, PeerStream);
|
|
93
|
+
for (var _len = arguments.length, params = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
94
|
+
params[_key] = arguments[_key];
|
|
95
|
+
}
|
|
96
|
+
console.log(params);
|
|
97
|
+
_this = _super.call(this);
|
|
98
|
+
_defineProperty(_assertThisInitialized(_this), "ws", {
|
|
99
|
+
send: function send() {},
|
|
100
|
+
close: function close() {}
|
|
101
|
+
});
|
|
102
|
+
_defineProperty(_assertThisInitialized(_this), "pc", {
|
|
103
|
+
close: function close() {}
|
|
104
|
+
});
|
|
105
|
+
_defineProperty(_assertThisInitialized(_this), "VideoEncoderQP", void 0);
|
|
106
|
+
_defineProperty(_assertThisInitialized(_this), "QualityControlOwnership", void 0);
|
|
107
|
+
_defineProperty(_assertThisInitialized(_this), "InitialSettings", void 0);
|
|
108
|
+
_defineProperty(_assertThisInitialized(_this), "disablepictureinpicture", void 0);
|
|
109
|
+
_defineProperty(_assertThisInitialized(_this), "dc", void 0);
|
|
110
|
+
_defineProperty(_assertThisInitialized(_this), "audio", void 0);
|
|
111
|
+
_defineProperty(_assertThisInitialized(_this), "ping", -1);
|
|
112
|
+
_defineProperty(_assertThisInitialized(_this), "customEvents", {});
|
|
113
|
+
_defineProperty(_assertThisInitialized(_this), "reconnect", -1);
|
|
114
|
+
_defineProperty(_assertThisInitialized(_this), "reconnectCount", 0);
|
|
115
|
+
window.ps = _assertThisInitialized(_this);
|
|
116
|
+
|
|
117
|
+
// this.ws = { send() { }, close() { } }; // WebSocket
|
|
118
|
+
// this.pc = { close() { } }; // RTCPeerConnection
|
|
119
|
+
_this.createCustomEvents();
|
|
120
|
+
_this.setupVideo();
|
|
121
|
+
_this.registerKeyboardEvents();
|
|
122
|
+
_this.registerMouseHoverEvents();
|
|
123
|
+
_this.registerFakeMouseEvents();
|
|
124
|
+
document.addEventListener('pointerlockchange', function () {
|
|
125
|
+
if (document.pointerLockElement === _assertThisInitialized(_this)) {
|
|
126
|
+
_this.registerPointerlockEvents();
|
|
127
|
+
} else {
|
|
128
|
+
_this.registerMouseHoverEvents();
|
|
129
|
+
}
|
|
130
|
+
}, false);
|
|
131
|
+
_this.addEventListener('loadeddata', function (e) {
|
|
132
|
+
_this.style.aspectRatio = "".concat(_this.videoWidth / _this.videoHeight);
|
|
133
|
+
});
|
|
134
|
+
return _this;
|
|
135
|
+
}
|
|
136
|
+
_createClass(PeerStream, [{
|
|
137
|
+
key: "createCustomEvents",
|
|
138
|
+
value: function createCustomEvents() {
|
|
139
|
+
for (var _i = 0, _customEventsArray = customEventsArray; _i < _customEventsArray.length; _i++) {
|
|
140
|
+
var eventName = _customEventsArray[_i];
|
|
141
|
+
var event = new CustomEvent(eventName);
|
|
142
|
+
this.customEvents[eventName] = event;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
// 自定义播放暂停
|
|
146
|
+
}, {
|
|
147
|
+
key: "customPlay",
|
|
148
|
+
value: function customPlay() {
|
|
149
|
+
this.setupWebsocket();
|
|
150
|
+
}
|
|
151
|
+
}, {
|
|
152
|
+
key: "customPause",
|
|
153
|
+
value: function customPause() {
|
|
154
|
+
this.dc.close();
|
|
155
|
+
this.pause();
|
|
156
|
+
}
|
|
157
|
+
}, {
|
|
158
|
+
key: "customStop",
|
|
159
|
+
value: function customStop() {
|
|
160
|
+
this.ws.close(1000, 'Infinity');
|
|
161
|
+
this.pc.close();
|
|
162
|
+
}
|
|
163
|
+
}, {
|
|
164
|
+
key: "setupWebsocket",
|
|
165
|
+
value: function setupWebsocket() {
|
|
166
|
+
var _this2 = this;
|
|
167
|
+
// This will happen each time the node is moved, and may happen before the element"s contents have been fully parsed. may be called once your element is no longer connected
|
|
168
|
+
if (!this.isConnected) return;
|
|
169
|
+
var signal = this.getAttribute('signal');
|
|
170
|
+
if (!signal) {
|
|
171
|
+
var ip = this.getAttribute('ip') || location.hostname || 'localhost';
|
|
172
|
+
var port = this.getAttribute('port') || 88;
|
|
173
|
+
var token = this.getAttribute('token') || 'hello';
|
|
174
|
+
signal = "ws://".concat(ip, ":").concat(port, "/").concat(token);
|
|
175
|
+
}
|
|
176
|
+
// 是否需要ping,配套的是signal.js里的需要pong
|
|
177
|
+
var needPing = false;
|
|
178
|
+
this.ws.close(1000, 'Infinity');
|
|
179
|
+
this.ws = new WebSocket(signal);
|
|
180
|
+
this.ws.onerror = function (e) {
|
|
181
|
+
console.log(e);
|
|
182
|
+
};
|
|
183
|
+
this.ws.onopen = /*#__PURE__*/function () {
|
|
184
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(e) {
|
|
185
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
186
|
+
while (1) switch (_context.prev = _context.next) {
|
|
187
|
+
case 0:
|
|
188
|
+
console.info('✅ connected to', _this2.ws.url);
|
|
189
|
+
_this2.setupPeerConnection();
|
|
190
|
+
// If the new data channel is the first one added to the connection, renegotiation is started by delivering a negotiationneeded event.
|
|
191
|
+
_this2.setupDataChannel();
|
|
192
|
+
// this.pc.restartIce();
|
|
193
|
+
|
|
194
|
+
clearInterval(_this2.ping);
|
|
195
|
+
if (needPing) {
|
|
196
|
+
// @ts-ignore
|
|
197
|
+
_this2.ping = setInterval(function () {
|
|
198
|
+
_this2.ws.send(JSON.stringify({
|
|
199
|
+
type: 'ping',
|
|
200
|
+
time: Date.now()
|
|
201
|
+
}));
|
|
202
|
+
}, 1000 * 50);
|
|
203
|
+
}
|
|
204
|
+
case 5:
|
|
205
|
+
case "end":
|
|
206
|
+
return _context.stop();
|
|
207
|
+
}
|
|
208
|
+
}, _callee);
|
|
209
|
+
}));
|
|
210
|
+
return function (_x) {
|
|
211
|
+
return _ref.apply(this, arguments);
|
|
212
|
+
};
|
|
213
|
+
}();
|
|
214
|
+
this.ws.onmessage = function (e) {
|
|
215
|
+
_this2.onWebSocketMessage(e.data);
|
|
216
|
+
};
|
|
217
|
+
this.ws.onclose = function (e) {
|
|
218
|
+
console.info('❌ signaler closed:', e.reason || e.code);
|
|
219
|
+
clearInterval(_this2.ping);
|
|
220
|
+
var timeout = +e.reason || 3000;
|
|
221
|
+
if (timeout === Infinity) return;
|
|
222
|
+
clearTimeout(_this2.reconnect);
|
|
223
|
+
if (_this2.reconnectCount > 0) {
|
|
224
|
+
// @ts-ignore
|
|
225
|
+
_this2.reconnect = setTimeout(function () {
|
|
226
|
+
_this2.reconnectCount--;
|
|
227
|
+
_this2.dispatchEvent(_this2.customEvents.tryConnect);
|
|
228
|
+
_this2.setupWebsocket();
|
|
229
|
+
}, timeout);
|
|
230
|
+
}
|
|
231
|
+
_this2.dispatchEvent(_this2.customEvents.disconnected);
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
}, {
|
|
235
|
+
key: "setupAttributes",
|
|
236
|
+
value: function setupAttributes() {
|
|
237
|
+
this.poster = this.getAttribute('poster') || '';
|
|
238
|
+
console.log(this.poster);
|
|
239
|
+
this.reconnectCount = +(this.getAttribute('reconnectCount') || Number.MAX_SAFE_INTEGER);
|
|
240
|
+
}
|
|
241
|
+
}, {
|
|
242
|
+
key: "connectedCallback",
|
|
243
|
+
value: function connectedCallback() {
|
|
244
|
+
this.setupAttributes();
|
|
245
|
+
this.setupWebsocket();
|
|
246
|
+
}
|
|
247
|
+
}, {
|
|
248
|
+
key: "disconnectedCallback",
|
|
249
|
+
value: function disconnectedCallback() {
|
|
250
|
+
// WebRTC的生命周期与<video>的生命周期绑定
|
|
251
|
+
this.ws.close(1000, 'Infinity');
|
|
252
|
+
this.pc.close();
|
|
253
|
+
console.log('❌ peer connection closing');
|
|
254
|
+
// this.dc.close();
|
|
255
|
+
}
|
|
256
|
+
}, {
|
|
257
|
+
key: "adoptedCallback",
|
|
258
|
+
value: function adoptedCallback() {}
|
|
259
|
+
}, {
|
|
260
|
+
key: "attributeChangedCallback",
|
|
261
|
+
value:
|
|
262
|
+
// attributeChangedCallback(name, oldValue, newValue) {
|
|
263
|
+
function attributeChangedCallback() {
|
|
264
|
+
if (!this.isConnected) return;
|
|
265
|
+
// fired before connectedCallback when startup 一开始会触发:oldValue从null变成newValue
|
|
266
|
+
this.ws.close(1000, '1');
|
|
267
|
+
}
|
|
268
|
+
}, {
|
|
269
|
+
key: "onWebSocketMessage",
|
|
270
|
+
value: function () {
|
|
271
|
+
var _onWebSocketMessage = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(msgStr) {
|
|
272
|
+
var msg, answer, _iterator, _step, receiver, candidate;
|
|
273
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
274
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
275
|
+
case 0:
|
|
276
|
+
_context2.prev = 0;
|
|
277
|
+
msg = JSON.parse(msgStr);
|
|
278
|
+
_context2.next = 8;
|
|
279
|
+
break;
|
|
280
|
+
case 4:
|
|
281
|
+
_context2.prev = 4;
|
|
282
|
+
_context2.t0 = _context2["catch"](0);
|
|
283
|
+
console.debug('signaler:', msg);
|
|
284
|
+
return _context2.abrupt("return");
|
|
285
|
+
case 8:
|
|
286
|
+
if (!(msg.type === 'answer')) {
|
|
287
|
+
_context2.next = 17;
|
|
288
|
+
break;
|
|
289
|
+
}
|
|
290
|
+
answer = new RTCSessionDescription(msg);
|
|
291
|
+
_context2.next = 12;
|
|
292
|
+
return this.pc.setRemoteDescription(answer);
|
|
293
|
+
case 12:
|
|
294
|
+
console.log('Got answer:', answer);
|
|
295
|
+
// 功能不可用
|
|
296
|
+
_iterator = _createForOfIteratorHelper(this.pc.getReceivers());
|
|
297
|
+
try {
|
|
298
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
299
|
+
receiver = _step.value;
|
|
300
|
+
receiver.playoutDelayHint = 0;
|
|
301
|
+
}
|
|
302
|
+
} catch (err) {
|
|
303
|
+
_iterator.e(err);
|
|
304
|
+
} finally {
|
|
305
|
+
_iterator.f();
|
|
306
|
+
}
|
|
307
|
+
_context2.next = 25;
|
|
308
|
+
break;
|
|
309
|
+
case 17:
|
|
310
|
+
if (!(msg.type === 'iceCandidate')) {
|
|
311
|
+
_context2.next = 24;
|
|
312
|
+
break;
|
|
313
|
+
}
|
|
314
|
+
candidate = new RTCIceCandidate(msg.candidate);
|
|
315
|
+
_context2.next = 21;
|
|
316
|
+
return this.pc.addIceCandidate(candidate);
|
|
317
|
+
case 21:
|
|
318
|
+
console.log('Got candidate:', candidate);
|
|
319
|
+
_context2.next = 25;
|
|
320
|
+
break;
|
|
321
|
+
case 24:
|
|
322
|
+
if (msg.type === 'ping') {
|
|
323
|
+
console.log('↓↓ ping:', msg);
|
|
324
|
+
msg.type = 'pong';
|
|
325
|
+
this.ws.send(JSON.stringify(msg));
|
|
326
|
+
} else {
|
|
327
|
+
console.warn('signaler:', msg);
|
|
328
|
+
}
|
|
329
|
+
case 25:
|
|
330
|
+
case "end":
|
|
331
|
+
return _context2.stop();
|
|
332
|
+
}
|
|
333
|
+
}, _callee2, this, [[0, 4]]);
|
|
334
|
+
}));
|
|
335
|
+
function onWebSocketMessage(_x2) {
|
|
336
|
+
return _onWebSocketMessage.apply(this, arguments);
|
|
337
|
+
}
|
|
338
|
+
return onWebSocketMessage;
|
|
339
|
+
}()
|
|
340
|
+
}, {
|
|
341
|
+
key: "onDataChannelMessage",
|
|
342
|
+
value: function onDataChannelMessage(message) {
|
|
343
|
+
var data = new Uint8Array(message);
|
|
344
|
+
var utf16 = new TextDecoder('utf-16');
|
|
345
|
+
switch (data[0]) {
|
|
346
|
+
case RECEIVE.VideoEncoderAvgQP:
|
|
347
|
+
{
|
|
348
|
+
this.VideoEncoderQP = +utf16.decode(data.slice(1));
|
|
349
|
+
// console.debug("Got QP:", this.VideoEncoderQP);
|
|
350
|
+
break;
|
|
351
|
+
}
|
|
352
|
+
case RECEIVE.Response:
|
|
353
|
+
{
|
|
354
|
+
// user custom message
|
|
355
|
+
var detail = utf16.decode(data.slice(1));
|
|
356
|
+
this.dispatchEvent(new CustomEvent('message', {
|
|
357
|
+
detail: detail
|
|
358
|
+
}));
|
|
359
|
+
console.info('Got ✉:', detail);
|
|
360
|
+
break;
|
|
361
|
+
}
|
|
362
|
+
case RECEIVE.Command:
|
|
363
|
+
{
|
|
364
|
+
var command = JSON.parse(utf16.decode(data.slice(1)));
|
|
365
|
+
console.info('Got command:', command);
|
|
366
|
+
if (command.command === 'onScreenKeyboard') {
|
|
367
|
+
console.info('You should setup a on-screen keyboard');
|
|
368
|
+
}
|
|
369
|
+
break;
|
|
370
|
+
}
|
|
371
|
+
case RECEIVE.FreezeFrame:
|
|
372
|
+
{
|
|
373
|
+
var size = new DataView(data.slice(1, 5).buffer).getInt32(0, true);
|
|
374
|
+
var jpeg = data.slice(1 + 4);
|
|
375
|
+
console.info('Got freezed frame:', jpeg);
|
|
376
|
+
break;
|
|
377
|
+
}
|
|
378
|
+
case RECEIVE.UnfreezeFrame:
|
|
379
|
+
{
|
|
380
|
+
console.info('Got 【unfreeze frame】');
|
|
381
|
+
break;
|
|
382
|
+
}
|
|
383
|
+
case RECEIVE.LatencyTest:
|
|
384
|
+
{
|
|
385
|
+
var latencyTimings = JSON.parse(utf16.decode(data.slice(1)));
|
|
386
|
+
console.info('Got latency timings:', latencyTimings);
|
|
387
|
+
break;
|
|
388
|
+
}
|
|
389
|
+
case RECEIVE.QualityControlOwnership:
|
|
390
|
+
{
|
|
391
|
+
this.QualityControlOwnership = data[1] !== 0;
|
|
392
|
+
console.info('Got Quality Control Ownership:', this.QualityControlOwnership);
|
|
393
|
+
break;
|
|
394
|
+
}
|
|
395
|
+
case RECEIVE.InitialSettings:
|
|
396
|
+
{
|
|
397
|
+
this.InitialSettings = JSON.parse(utf16.decode(data.slice(1)));
|
|
398
|
+
console.log('Got initial setting:', this.InitialSettings);
|
|
399
|
+
break;
|
|
400
|
+
}
|
|
401
|
+
default:
|
|
402
|
+
{
|
|
403
|
+
console.error('Got invalid data:', data);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
}, {
|
|
408
|
+
key: "setupVideo",
|
|
409
|
+
value: function setupVideo() {
|
|
410
|
+
this.tabIndex = -1; // easy to focus..
|
|
411
|
+
this.autofocus = true;
|
|
412
|
+
this.playsInline = true;
|
|
413
|
+
this.disablepictureinpicture = true;
|
|
414
|
+
|
|
415
|
+
// Recently many browsers can only autoplay the videos with sound off
|
|
416
|
+
this.muted = true;
|
|
417
|
+
this.autoplay = true;
|
|
418
|
+
|
|
419
|
+
// this.onsuspend
|
|
420
|
+
// this.onresize
|
|
421
|
+
// this.requestPointerLock();
|
|
422
|
+
|
|
423
|
+
this.style.pointerEvents = 'none';
|
|
424
|
+
this.style.objectFit = 'fill';
|
|
425
|
+
}
|
|
426
|
+
}, {
|
|
427
|
+
key: "setupDataChannel",
|
|
428
|
+
value: function setupDataChannel() {
|
|
429
|
+
var _this3 = this;
|
|
430
|
+
var label = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'hello';
|
|
431
|
+
// See https://www.w3.org/TR/webrtc/#dom-rtcdatachannelinit for values (this is needed for Firefox to be consistent with Chrome.)
|
|
432
|
+
this.dc = this.pc.createDataChannel(label, {
|
|
433
|
+
ordered: true
|
|
434
|
+
});
|
|
435
|
+
// Inform browser we would like binary data as an ArrayBuffer (FF chooses Blob by default!)
|
|
436
|
+
this.dc.binaryType = 'arraybuffer';
|
|
437
|
+
this.dc.safeSend = function () {
|
|
438
|
+
try {
|
|
439
|
+
if (_this3.dc.readyState === 'open') {
|
|
440
|
+
var _this3$dc;
|
|
441
|
+
(_this3$dc = _this3.dc).send.apply(_this3$dc, arguments);
|
|
442
|
+
}
|
|
443
|
+
} catch (error) {
|
|
444
|
+
console.log(error);
|
|
445
|
+
}
|
|
446
|
+
};
|
|
447
|
+
this.dc.onopen = function () {
|
|
448
|
+
_this3.dispatchEvent(_this3.customEvents.connected);
|
|
449
|
+
console.log('✅ data channel connected:', label);
|
|
450
|
+
_this3.style.pointerEvents = 'auto';
|
|
451
|
+
_this3.dc.send(new Uint8Array([SEND.RequestInitialSettings]));
|
|
452
|
+
_this3.dc.send(new Uint8Array([SEND.RequestQualityControl]));
|
|
453
|
+
};
|
|
454
|
+
this.dc.onclose = function () {
|
|
455
|
+
console.info('❌ data channel closed:', label);
|
|
456
|
+
// this.style.pointerEvents = "none";
|
|
457
|
+
};
|
|
458
|
+
this.dc.onmessage = function (e) {
|
|
459
|
+
_this3.onDataChannelMessage(e.data);
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
}, {
|
|
463
|
+
key: "setupPeerConnection",
|
|
464
|
+
value: function setupPeerConnection() {
|
|
465
|
+
var _this4 = this;
|
|
466
|
+
console.log('setupPeerConnection');
|
|
467
|
+
this.pc.close();
|
|
468
|
+
this.pc = new RTCPeerConnection({
|
|
469
|
+
// sdpSemantics: "unified-plan",
|
|
470
|
+
iceServers: [
|
|
471
|
+
// {
|
|
472
|
+
// urls: [
|
|
473
|
+
// "stun:stun.l.google.com:19302",
|
|
474
|
+
// "stun:stun1.l.google.com:19302",
|
|
475
|
+
// "stun:stun2.l.google.com:19302",
|
|
476
|
+
// "stun:stun3.l.google.com:19302",
|
|
477
|
+
// "stun:stun4.l.google.com:19302",
|
|
478
|
+
// ],
|
|
479
|
+
// },
|
|
480
|
+
]
|
|
481
|
+
});
|
|
482
|
+
this.pc.ontrack = function (e) {
|
|
483
|
+
console.log("Got ".concat(e.track.kind, " track:"), e);
|
|
484
|
+
if (e.track.kind === 'video') {
|
|
485
|
+
_this4.srcObject = e.streams[0];
|
|
486
|
+
} else if (e.track.kind === 'audio') {
|
|
487
|
+
_this4.audio = document.createElement('audio');
|
|
488
|
+
_this4.audio.autoplay = true;
|
|
489
|
+
_this4.audio.srcObject = e.streams[0];
|
|
490
|
+
}
|
|
491
|
+
};
|
|
492
|
+
this.pc.onicecandidate = function (e) {
|
|
493
|
+
var _e$candidate;
|
|
494
|
+
// firefox
|
|
495
|
+
if ((_e$candidate = e.candidate) !== null && _e$candidate !== void 0 && _e$candidate.candidate) {
|
|
496
|
+
console.log('sending candidate:', e.candidate);
|
|
497
|
+
_this4.ws.send(JSON.stringify({
|
|
498
|
+
type: 'iceCandidate',
|
|
499
|
+
candidate: e.candidate
|
|
500
|
+
}));
|
|
501
|
+
} else {
|
|
502
|
+
// Notice that the end of negotiation is detected here when the event"s candidate property is null.
|
|
503
|
+
}
|
|
504
|
+
};
|
|
505
|
+
this.pc.onnegotiationneeded = function (e) {
|
|
506
|
+
_this4.setupOffer();
|
|
507
|
+
};
|
|
508
|
+
var setPoster = function setPoster() {
|
|
509
|
+
return _this4.poster = _this4.poster || "data:image/svg+xml;utf8,<svg xmlns=\"http://www.w3.org/2000/svg\"><style>text{font-size:7mm;fill:red;}</style>\n <text x=\"10\" y=\"030\"> Signal: ".concat(_this4.pc.signalingState, " </text>\n <text x=\"10\" y=\"065\"> Connect: ").concat(_this4.pc.connectionState, " </text>\n <text x=\"10\" y=\"100\"> ICE Gather: ").concat(_this4.pc.iceGatheringState, " </text>\n <text x=\"10\" y=\"135\"> ICE Connect: ").concat(_this4.pc.iceConnectionState, " </text>\n </svg>");
|
|
510
|
+
};
|
|
511
|
+
this.pc.onsignalingstatechange = this.pc.onconnectionstatechange = this.pc.oniceconnectionstatechange = this.pc.onicegatheringstatechange = setPoster;
|
|
512
|
+
}
|
|
513
|
+
}, {
|
|
514
|
+
key: "setupOffer",
|
|
515
|
+
value: function () {
|
|
516
|
+
var _setupOffer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
517
|
+
var _offer$sdp;
|
|
518
|
+
var offer;
|
|
519
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
520
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
521
|
+
case 0:
|
|
522
|
+
_context3.next = 2;
|
|
523
|
+
return this.pc.createOffer({
|
|
524
|
+
offerToReceiveAudio: this.hasAttribute('audio'),
|
|
525
|
+
offerToReceiveVideo: true
|
|
526
|
+
// voiceActivityDetection: false,
|
|
527
|
+
});
|
|
528
|
+
case 2:
|
|
529
|
+
offer = _context3.sent;
|
|
530
|
+
// this indicate we support stereo (Chrome needs this)
|
|
531
|
+
offer.sdp = (_offer$sdp = offer.sdp) === null || _offer$sdp === void 0 ? void 0 : _offer$sdp.replace('useinbandfec=1', 'useinbandfec=1;stereo=1;sprop-maxcapturerate=48000');
|
|
532
|
+
this.pc.setLocalDescription(offer);
|
|
533
|
+
this.ws.send(JSON.stringify(offer));
|
|
534
|
+
console.log('sending offer:', offer);
|
|
535
|
+
case 7:
|
|
536
|
+
case "end":
|
|
537
|
+
return _context3.stop();
|
|
538
|
+
}
|
|
539
|
+
}, _callee3, this);
|
|
540
|
+
}));
|
|
541
|
+
function setupOffer() {
|
|
542
|
+
return _setupOffer.apply(this, arguments);
|
|
543
|
+
}
|
|
544
|
+
return setupOffer;
|
|
545
|
+
}()
|
|
546
|
+
}, {
|
|
547
|
+
key: "registerKeyboardEvents",
|
|
548
|
+
value: function registerKeyboardEvents() {
|
|
549
|
+
var _this5 = this;
|
|
550
|
+
this.addEventListener('keydown', function (event) {
|
|
551
|
+
// Handle the keydown event here
|
|
552
|
+
console.log('Key pressed:', event.key);
|
|
553
|
+
});
|
|
554
|
+
this.onkeydown = function (e) {
|
|
555
|
+
console.log(e.code, e.keyCode);
|
|
556
|
+
_this5.dc.safeSend(new Uint8Array([SEND.KeyDown, SpecialKeyCodes[e.code] || e.keyCode, Number(e.repeat)]));
|
|
557
|
+
// whether to prevent browser"s default behavior when keyboard/mouse have inputs, like F1~F12 and Tab
|
|
558
|
+
e.preventDefault();
|
|
559
|
+
// e.stopPropagation
|
|
560
|
+
};
|
|
561
|
+
this.onkeyup = function (e) {
|
|
562
|
+
_this5.dc.safeSend(new Uint8Array([SEND.KeyUp, SpecialKeyCodes[e.code] || e.keyCode]));
|
|
563
|
+
e.preventDefault();
|
|
564
|
+
};
|
|
565
|
+
this.onkeypress = function (e) {
|
|
566
|
+
var data = new DataView(new ArrayBuffer(3));
|
|
567
|
+
data.setUint8(0, SEND.KeyPress);
|
|
568
|
+
data.setUint16(1, SpecialKeyCodes[e.code] || e.keyCode, true);
|
|
569
|
+
_this5.dc.safeSend(data);
|
|
570
|
+
e.preventDefault();
|
|
571
|
+
};
|
|
572
|
+
}
|
|
573
|
+
}, {
|
|
574
|
+
key: "registerTouchEvents",
|
|
575
|
+
value: function registerTouchEvents() {
|
|
576
|
+
var _this6 = this;
|
|
577
|
+
// We need to assign a unique identifier to each finger.
|
|
578
|
+
// We do this by mapping each Touch object to the identifier.
|
|
579
|
+
var fingers = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0];
|
|
580
|
+
var fingerIds = {};
|
|
581
|
+
this.ontouchstart = function (e) {
|
|
582
|
+
// Assign a unique identifier to each touch.
|
|
583
|
+
for (var _i2 = 0, _Array$from = Array.from(e.changedTouches); _i2 < _Array$from.length; _i2++) {
|
|
584
|
+
var touch = _Array$from[_i2];
|
|
585
|
+
// remember touch
|
|
586
|
+
var finger = fingers.pop();
|
|
587
|
+
if (finger === undefined) {
|
|
588
|
+
console.info('exhausted touch indentifiers');
|
|
589
|
+
}
|
|
590
|
+
fingerIds[touch.identifier] = finger;
|
|
591
|
+
}
|
|
592
|
+
_this6.emitTouchData(SEND.TouchStart, e.changedTouches, fingerIds);
|
|
593
|
+
e.preventDefault();
|
|
594
|
+
};
|
|
595
|
+
this.ontouchend = function (e) {
|
|
596
|
+
_this6.emitTouchData(SEND.TouchEnd, e.changedTouches, fingerIds);
|
|
597
|
+
// Re-cycle unique identifiers previously assigned to each touch.
|
|
598
|
+
for (var _i3 = 0, _Array$from2 = Array.from(e.changedTouches); _i3 < _Array$from2.length; _i3++) {
|
|
599
|
+
var touch = _Array$from2[_i3];
|
|
600
|
+
// forget touch
|
|
601
|
+
fingers.push(fingerIds[touch.identifier]);
|
|
602
|
+
delete fingerIds[touch.identifier];
|
|
603
|
+
}
|
|
604
|
+
e.preventDefault();
|
|
605
|
+
};
|
|
606
|
+
this.ontouchmove = function (e) {
|
|
607
|
+
_this6.emitTouchData(SEND.TouchMove, e.touches, fingerIds);
|
|
608
|
+
e.preventDefault();
|
|
609
|
+
};
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
// 触屏模拟鼠标
|
|
613
|
+
}, {
|
|
614
|
+
key: "registerFakeMouseEvents",
|
|
615
|
+
value: function registerFakeMouseEvents() {
|
|
616
|
+
var _this7 = this;
|
|
617
|
+
var finger = undefined;
|
|
618
|
+
var _this$getBoundingClie = this.getBoundingClientRect(),
|
|
619
|
+
left = _this$getBoundingClie.left,
|
|
620
|
+
top = _this$getBoundingClie.top;
|
|
621
|
+
this.ontouchstart = function (e) {
|
|
622
|
+
if (finger === undefined) {
|
|
623
|
+
var firstTouch = e.changedTouches[0];
|
|
624
|
+
finger = {
|
|
625
|
+
id: firstTouch.identifier,
|
|
626
|
+
x: firstTouch.clientX - left,
|
|
627
|
+
y: firstTouch.clientY - top
|
|
628
|
+
};
|
|
629
|
+
// Hack: Mouse events require an enter and leave so we just enter and leave manually with each touch as this event is not fired with a touch device.
|
|
630
|
+
_this7.onmouseenter && _this7.onmouseenter(e);
|
|
631
|
+
_this7.emitMouseDown(MouseButton.MainButton, finger.x, finger.y);
|
|
632
|
+
}
|
|
633
|
+
e.preventDefault();
|
|
634
|
+
};
|
|
635
|
+
this.ontouchend = function (e) {
|
|
636
|
+
for (var _i4 = 0, _Array$from3 = Array.from(e.changedTouches); _i4 < _Array$from3.length; _i4++) {
|
|
637
|
+
var _finger;
|
|
638
|
+
var touch = _Array$from3[_i4];
|
|
639
|
+
if (touch.identifier === ((_finger = finger) === null || _finger === void 0 ? void 0 : _finger.id)) {
|
|
640
|
+
var _x3 = touch.clientX - left;
|
|
641
|
+
var y = touch.clientY - top;
|
|
642
|
+
_this7.emitMouseUp(MouseButton.MainButton, _x3, y);
|
|
643
|
+
// Hack: Manual mouse leave event.
|
|
644
|
+
_this7.onmouseleave && _this7.onmouseleave(e);
|
|
645
|
+
finger = undefined;
|
|
646
|
+
break;
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
e.preventDefault();
|
|
650
|
+
};
|
|
651
|
+
this.ontouchmove = function (e) {
|
|
652
|
+
for (var _i5 = 0, _Array$from4 = Array.from(e.changedTouches); _i5 < _Array$from4.length; _i5++) {
|
|
653
|
+
var _finger2;
|
|
654
|
+
var touch = _Array$from4[_i5];
|
|
655
|
+
if (touch.identifier === ((_finger2 = finger) === null || _finger2 === void 0 ? void 0 : _finger2.id)) {
|
|
656
|
+
var _x4 = touch.clientX - left;
|
|
657
|
+
var y = touch.clientY - top;
|
|
658
|
+
_this7.emitMouseMove(_x4, y, _x4 - finger.x, y - finger.y);
|
|
659
|
+
finger.x = _x4;
|
|
660
|
+
finger.y = y;
|
|
661
|
+
break;
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
e.preventDefault();
|
|
665
|
+
};
|
|
666
|
+
}
|
|
667
|
+
}, {
|
|
668
|
+
key: "registerMouseHoverEvents",
|
|
669
|
+
value: function registerMouseHoverEvents() {
|
|
670
|
+
var _this8 = this;
|
|
671
|
+
this.registerMouseEnterAndLeaveEvents();
|
|
672
|
+
this.onmousemove = function (e) {
|
|
673
|
+
_this8.emitMouseMove(e.offsetX, e.offsetY, e.movementX, e.movementY);
|
|
674
|
+
e.preventDefault();
|
|
675
|
+
};
|
|
676
|
+
this.onmousedown = function (e) {
|
|
677
|
+
_this8.emitMouseDown(e.button, e.offsetX, e.offsetY);
|
|
678
|
+
// e.preventDefault();
|
|
679
|
+
};
|
|
680
|
+
this.onmouseup = function (e) {
|
|
681
|
+
_this8.emitMouseUp(e.button, e.offsetX, e.offsetY);
|
|
682
|
+
// e.preventDefault();
|
|
683
|
+
};
|
|
684
|
+
|
|
685
|
+
// When the context menu is shown then it is safest to release the button which was pressed when the event happened. This will guarantee we will get at least one mouse up corresponding to a mouse down event. Otherwise the mouse can get stuck.
|
|
686
|
+
// https://github.com/facebook/react/issues/5531
|
|
687
|
+
this.oncontextmenu = function (e) {
|
|
688
|
+
_this8.emitMouseUp(e.button, e.offsetX, e.offsetY);
|
|
689
|
+
e.preventDefault();
|
|
690
|
+
};
|
|
691
|
+
this.onwheel = function (e) {
|
|
692
|
+
// console.log(e,e.wheelDeltaY,e.deltaY)
|
|
693
|
+
// 临时处理
|
|
694
|
+
_this8.emitMouseWheel(-e.deltaY, e.offsetX, e.offsetY);
|
|
695
|
+
e.preventDefault();
|
|
696
|
+
};
|
|
697
|
+
}
|
|
698
|
+
}, {
|
|
699
|
+
key: "registerPointerlockEvents",
|
|
700
|
+
value: function registerPointerlockEvents() {
|
|
701
|
+
var _this9 = this;
|
|
702
|
+
this.registerMouseEnterAndLeaveEvents();
|
|
703
|
+
console.info('mouse locked in, ESC to exit');
|
|
704
|
+
var clientWidth = this.clientWidth,
|
|
705
|
+
clientHeight = this.clientHeight;
|
|
706
|
+
var x = clientWidth / 2;
|
|
707
|
+
var y = clientHeight / 2;
|
|
708
|
+
this.onmousemove = function (e) {
|
|
709
|
+
x += e.movementX;
|
|
710
|
+
y += e.movementY;
|
|
711
|
+
x = (x + clientWidth) % clientWidth;
|
|
712
|
+
y = (y + clientHeight) % clientHeight;
|
|
713
|
+
_this9.emitMouseMove(x, y, e.movementX, e.movementY);
|
|
714
|
+
};
|
|
715
|
+
this.onmousedown = function (e) {
|
|
716
|
+
_this9.emitMouseDown(e.button, x, y);
|
|
717
|
+
};
|
|
718
|
+
this.onmouseup = function (e) {
|
|
719
|
+
_this9.emitMouseUp(e.button, x, y);
|
|
720
|
+
};
|
|
721
|
+
this.onwheel = function (e) {
|
|
722
|
+
// 临时处理
|
|
723
|
+
_this9.emitMouseWheel(-e.deltaY, x, y);
|
|
724
|
+
};
|
|
725
|
+
}
|
|
726
|
+
}, {
|
|
727
|
+
key: "registerMouseEnterAndLeaveEvents",
|
|
728
|
+
value: function registerMouseEnterAndLeaveEvents() {
|
|
729
|
+
var _this10 = this;
|
|
730
|
+
this.onmouseenter = function (e) {
|
|
731
|
+
_this10.dc.safeSend(new Uint8Array([SEND.MouseEnter]));
|
|
732
|
+
};
|
|
733
|
+
this.onmouseleave = function (e) {
|
|
734
|
+
_this10.dc.safeSend && _this10.dc.safeSend(new Uint8Array([SEND.MouseLeave]));
|
|
735
|
+
};
|
|
736
|
+
}
|
|
737
|
+
}, {
|
|
738
|
+
key: "emitMouseMove",
|
|
739
|
+
value: function emitMouseMove(x, y, deltaX, deltaY) {
|
|
740
|
+
var coord = this._normalize(x, y);
|
|
741
|
+
deltaX = deltaX * 65536 / this.clientWidth;
|
|
742
|
+
deltaY = deltaY * 65536 / this.clientHeight;
|
|
743
|
+
var data = new DataView(new ArrayBuffer(9));
|
|
744
|
+
data.setUint8(0, SEND.MouseMove);
|
|
745
|
+
data.setUint16(1, coord.x, true);
|
|
746
|
+
data.setUint16(3, coord.y, true);
|
|
747
|
+
data.setInt16(5, deltaX, true);
|
|
748
|
+
data.setInt16(7, deltaY, true);
|
|
749
|
+
this.dc.safeSend(data);
|
|
750
|
+
}
|
|
751
|
+
}, {
|
|
752
|
+
key: "emitMouseDown",
|
|
753
|
+
value: function emitMouseDown(button, x, y) {
|
|
754
|
+
var coord = this._normalize(x, y);
|
|
755
|
+
var data = new DataView(new ArrayBuffer(6));
|
|
756
|
+
data.setUint8(0, SEND.MouseDown);
|
|
757
|
+
data.setUint8(1, button);
|
|
758
|
+
data.setUint16(2, coord.x, true);
|
|
759
|
+
data.setUint16(4, coord.y, true);
|
|
760
|
+
this.dc.safeSend(data);
|
|
761
|
+
}
|
|
762
|
+
}, {
|
|
763
|
+
key: "emitMouseUp",
|
|
764
|
+
value: function emitMouseUp(button, x, y) {
|
|
765
|
+
var coord = this._normalize(x, y);
|
|
766
|
+
var data = new DataView(new ArrayBuffer(6));
|
|
767
|
+
data.setUint8(0, SEND.MouseUp);
|
|
768
|
+
data.setUint8(1, button);
|
|
769
|
+
data.setUint16(2, coord.x, true);
|
|
770
|
+
data.setUint16(4, coord.y, true);
|
|
771
|
+
this.dc.safeSend(data);
|
|
772
|
+
}
|
|
773
|
+
}, {
|
|
774
|
+
key: "emitMouseWheel",
|
|
775
|
+
value: function emitMouseWheel(delta, x, y) {
|
|
776
|
+
var coord = this._normalize(x, y);
|
|
777
|
+
var data = new DataView(new ArrayBuffer(7));
|
|
778
|
+
data.setUint8(0, SEND.MouseWheel);
|
|
779
|
+
data.setInt16(1, delta, true);
|
|
780
|
+
data.setUint16(3, coord.x, true);
|
|
781
|
+
data.setUint16(5, coord.y, true);
|
|
782
|
+
this.dc.safeSend(data);
|
|
783
|
+
}
|
|
784
|
+
}, {
|
|
785
|
+
key: "emitTouchData",
|
|
786
|
+
value: function emitTouchData(type, touches, fingerIds) {
|
|
787
|
+
var data = new DataView(new ArrayBuffer(2 + 6 * touches.length));
|
|
788
|
+
data.setUint8(0, type);
|
|
789
|
+
data.setUint8(1, touches.length);
|
|
790
|
+
var byte = 2;
|
|
791
|
+
for (var _i6 = 0, _Array$from5 = Array.from(touches); _i6 < _Array$from5.length; _i6++) {
|
|
792
|
+
var touch = _Array$from5[_i6];
|
|
793
|
+
var _x5 = touch.clientX - this.offsetLeft;
|
|
794
|
+
var y = touch.clientY - this.offsetTop;
|
|
795
|
+
var coord = this._normalize(_x5, y);
|
|
796
|
+
data.setUint16(byte, coord.x, true);
|
|
797
|
+
byte += 2;
|
|
798
|
+
data.setUint16(byte, coord.y, true);
|
|
799
|
+
byte += 2;
|
|
800
|
+
data.setUint8(byte, fingerIds[touch.identifier]);
|
|
801
|
+
byte += 1;
|
|
802
|
+
data.setUint8(byte, 255 * touch.force); // force is between 0.0 and 1.0 so quantize into byte.
|
|
803
|
+
byte += 1;
|
|
804
|
+
}
|
|
805
|
+
this.dc.safeSend(data);
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
// emit string
|
|
809
|
+
}, {
|
|
810
|
+
key: "emitMessage",
|
|
811
|
+
value: function emitMessage(msg) {
|
|
812
|
+
var messageType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : SEND.UIInteraction;
|
|
813
|
+
if (typeof msg !== 'string') msg = JSON.stringify(msg);
|
|
814
|
+
|
|
815
|
+
// Add the UTF-16 JSON string to the array byte buffer, going two bytes at a time.
|
|
816
|
+
var data = new DataView(new ArrayBuffer(1 + 2 + 2 * msg.length));
|
|
817
|
+
var byteIdx = 0;
|
|
818
|
+
data.setUint8(byteIdx, messageType);
|
|
819
|
+
byteIdx++;
|
|
820
|
+
data.setUint16(byteIdx, msg.length, true);
|
|
821
|
+
byteIdx += 2;
|
|
822
|
+
var _iterator2 = _createForOfIteratorHelper(msg),
|
|
823
|
+
_step2;
|
|
824
|
+
try {
|
|
825
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
826
|
+
var char = _step2.value;
|
|
827
|
+
// charCodeAt() is UTF-16, codePointAt() is Unicode.
|
|
828
|
+
data.setUint16(byteIdx, char.charCodeAt(0), true);
|
|
829
|
+
byteIdx += 2;
|
|
830
|
+
}
|
|
831
|
+
} catch (err) {
|
|
832
|
+
_iterator2.e(err);
|
|
833
|
+
} finally {
|
|
834
|
+
_iterator2.f();
|
|
835
|
+
}
|
|
836
|
+
this.dc.safeSend(data);
|
|
837
|
+
// 有时候前端问:怎么返回undefined?是不是没发送成功?
|
|
838
|
+
return true;
|
|
839
|
+
}
|
|
840
|
+
}, {
|
|
841
|
+
key: "_normalize",
|
|
842
|
+
value: function _normalize(x, y) {
|
|
843
|
+
var normalizedX = x / this.clientWidth;
|
|
844
|
+
var normalizedY = y / this.clientHeight;
|
|
845
|
+
if (normalizedX < 0.0 || normalizedX > 1.0 || normalizedY < 0.0 || normalizedY > 1.0) {
|
|
846
|
+
return {
|
|
847
|
+
inRange: false,
|
|
848
|
+
x: 65535,
|
|
849
|
+
y: 65535
|
|
850
|
+
};
|
|
851
|
+
} else {
|
|
852
|
+
return {
|
|
853
|
+
inRange: true,
|
|
854
|
+
x: normalizedX * 65536,
|
|
855
|
+
y: normalizedY * 65536
|
|
856
|
+
};
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
}, {
|
|
860
|
+
key: "debug",
|
|
861
|
+
value: function debug(NodeJS) {
|
|
862
|
+
// 调试信令服务器
|
|
863
|
+
this.ws.send(JSON.stringify({
|
|
864
|
+
type: 'debug',
|
|
865
|
+
debug: NodeJS
|
|
866
|
+
}));
|
|
867
|
+
}
|
|
868
|
+
}]);
|
|
869
|
+
return PeerStream;
|
|
870
|
+
}( /*#__PURE__*/_wrapNativeSuper(HTMLVideoElement));
|
|
871
|
+
_defineProperty(PeerStream, "observedAttributes", ['signal', 'ip', 'port', 'token']);
|
|
872
|
+
export function initialize(initialSettings) {
|
|
873
|
+
customElements.define('peer-stream', PeerStream, {
|
|
874
|
+
extends: 'video'
|
|
875
|
+
});
|
|
876
|
+
}
|