123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486 |
- const log$p = new Logger("actions-handler")
- , QueueActions = [Actions.Transfer, Actions.ChangeSkin, Actions.GetOnVehicle, Actions.GetOffVehicle];
- class ActionsHandler {
- constructor(e) {
- E(this, "room");
- E(this, "currentActiveAction");
- E(this, "avatarComponentsSync", e=>{
- const t = {
- action_type: Actions.SetPlayerState,
- set_player_state_action: {
- player_state: {
- avatar_components: JSON.stringify(e)
- }
- }
- };
- this.sendData({
- data: t
- })
- }
- );
- this.room = e
- }
- async sendData(e) {
- await this.beforeSend(e);
- const t = uuid$1();
- if (this.room.networkController.sendRtcData(le(oe({}, e.data), {
- trace_id: t,
- user_id: this.room.options.userId
- })),
- e.track === !1)
- return Promise.resolve(null);
- const {sampleRate: r=1, timeout: n=2e3, tag: o, data: a, special: s} = e;
- return eventsManager.track({
- timeout: n,
- traceId: t,
- event: a.action_type,
- tag: o,
- extra: a
- }, {
- special: s,
- sampleRate: r,
- noReport: this.room.viewMode === "serverless" || this.room.options.viewMode === "serverless"
- }).finally(()=>{
- QueueActions.includes(e.data.action_type) && (this.currentActiveAction = void 0)
- }
- )
- }
- async beforeSend(e) {
- var o;
- const t = (o = this.room._userAvatar) == null ? void 0 : o.isMoving
- , r = e.data.action_type;
- if (QueueActions.includes(r)) {
- if (this.currentActiveAction)
- return log$p.error(`${Actions[this.currentActiveAction]} still pending, reject ${Actions[r]}`),
- Promise.reject(new FrequencyLimitError(`${Actions[r]} action request frequency limit`));
- this.currentActiveAction = r
- }
- if (t && QueueActions.includes(e.data.action_type))
- try {
- await this.stopMoving()
- } catch (a) {
- this.currentActiveAction = void 0,
- log$p.error("before action stopMoving failed", a)
- }
- }
- async moveTo(e) {
- const {point: t, extra: r="", motionType: n} = e
- , o = {
- action_type: Actions.Clicking,
- clicking_action: {
- clicking_point: t,
- clicking_type: ClickType.IgnoreView,
- extra: encodeURIComponent(r),
- attitude: n
- },
- clicking_state: this.room._currentClickingState
- };
- return this.sendData({
- data: o
- })
- }
- transfer(e) {
- const {renderType: t, player: r, camera: n, areaName: o, attitude: a, pathName: s, person: l, noMedia: u, timeout: c, tag: h, special: f} = e
- , d = {
- data: {
- action_type: Actions.Transfer,
- transfer_action: {
- render_type: t,
- player: r,
- camera: n,
- areaName: o,
- attitude: a,
- pathName: s,
- person: {
- type: l
- },
- noMedia: u,
- tiles: [0, 1, 2, 4]
- }
- },
- special: f,
- timeout: c || 4e3,
- tag: h
- };
- return this.sendData(d).then(_=>(typeof l != "undefined" && this.room.updateCurrentNetworkOptions({
- person: l,
- rotationRenderType: t
- }),
- _))
- }
- changeRotationRenderType(e) {
- const {renderType: t, player: r, camera: n, areaName: o, attitude: a, pathName: s} = e;
- return this.transfer({
- renderType: t,
- player: r,
- camera: n,
- areaName: o,
- attitude: a,
- pathName: s,
- tag: "changeToRotationVideo"
- })
- }
- requestPanorama(e, t, r) {
- const {camera: n, player: o, areaName: a, attitude: s, pathName: l, tag: u} = e;
- return this.transfer({
- renderType: RenderType.ClientRotationPano,
- player: o,
- camera: n,
- person: Person.First,
- areaName: a,
- attitude: s,
- pathName: l,
- noMedia: t,
- timeout: r,
- tag: u || "requestPanorama",
- special: !t
- })
- }
- setMotionType(e) {
- return this.transfer({
- attitude: e,
- tag: "setMotionType"
- })
- }
- setNickName(e) {
- const t = {
- action_type: Actions.ChangeNickname,
- change_nickname_action: {
- nickname: e
- }
- };
- return this.sendData({
- data: t
- })
- }
- getReserveSeat({routeId: e, name: t}) {
- const r = {
- action_type: Actions.ReserveSeat,
- reserve_seat_action: {
- route_id: e,
- name: t
- }
- };
- return this.sendData({
- data: r
- })
- }
- getReserveStatus({routeId: e, name: t, need_detail: r}) {
- const n = {
- action_type: Actions.GetReserveStatus,
- get_reserve_status_action: {
- route_id: e,
- name: t,
- need_detail: r
- }
- };
- return this.sendData({
- data: n,
- timeout: 2e3
- }).then(o=>o.reserveDetail)
- }
- stopMoving() {
- const e = {
- action_type: Actions.StopMoving,
- stop_move_action: {}
- };
- return this.sendData({
- data: e
- })
- }
- getOnVehicle({routeId: e, name: t, camera: r}) {
- const n = {
- action_type: Actions.GetOnVehicle,
- get_on_vehicle_action: {
- route_id: e,
- name: t,
- camera: r
- }
- };
- return this.sendData({
- data: n
- })
- }
- getOffVehicle({renderType: e, player: t, camera: r}) {
- const n = {
- action_type: Actions.GetOffVehicle,
- get_off_vehicle_action: {
- render_type: e,
- player: t,
- camera: r
- }
- };
- return this.sendData({
- data: n
- })
- }
- confirmEvent(e) {
- const t = {
- action_type: Actions.ConfirmEvent,
- confirm_event_action: {
- id: e
- }
- };
- return this.sendData({
- data: t,
- track: !1
- })
- }
- echo(e) {
- const t = {
- action_type: Actions.Echo,
- echo_msg: {
- echoMsg: e
- }
- };
- return this.sendData({
- data: t,
- track: !1
- })
- }
- async changeSkin(e) {
- const t = e.special === void 0 ? e.renderType === RenderType.ClientRotationPano : e.special
- , {skinId: r, mode: n, landingType: o=LandingType.Stay, landingPoint: a, landingCamera: s, renderType: l, areaName: u, attitude: c, pathName: h, person: f, noMedia: d, timeout: _, roomTypeId: g=""} = e
- , m = this.room.skinList.filter(y=>y.id === r)[0];
- if (!m) {
- const y = `skin ${r} is invalid`;
- return log$p.error(y),
- Promise.reject(new ParamError(y))
- }
- const v = {
- action_type: Actions.ChangeSkin,
- change_skin_action: {
- skinID: r,
- mode: n === ChangeMode.Preview ? ChangeMode.Preview : ChangeMode.Confirm,
- skin_data_version: r + m.versionId,
- landing_type: o,
- landing_point: a,
- landing_camera: s,
- render_wrapper: {
- render_type: l
- },
- areaName: u,
- attitude: c,
- noMedia: d,
- person: f,
- pathName: h,
- roomTypeId: g
- }
- };
- return this.sendData({
- data: v,
- timeout: _ || 6e3,
- special: t
- }).then(async y=>{
- if (l === RenderType.ClientRotationPano && y) {
- const b = await this.room.modelManager.findRoute(r, h)
- , {camera: T} = getRandomItem(b.birthPointList) || {};
- await this.room.panorama.handleReceivePanorama(y, T)
- }
- return this.handleChangeSkin(e)
- }
- ).catch(y=>d ? this.handleChangeSkin(e) : Promise.reject(y))
- }
- handleChangeSkin(e) {
- const {skinId: t, mode: r, renderType: n, areaName: o, attitude: a, pathName: s} = e;
- return this.room.sceneManager.staticmeshComponent.getCgMesh().show(),
- this.room.sceneManager.cameraComponent.switchToCgCamera(),
- this.room.engineProxy._updateSkinAssets(t).then(()=>{
- this.room.sceneManager.staticmeshComponent.getCgMesh().hide(),
- this.room.sceneManager.cameraComponent.switchToMainCamera(),
- this.room.pathManager.currentArea = o,
- log$p.info("changeSkin _updateSkinAssets susccss"),
- this.room.updateCurrentNetworkOptions({
- pathName: s,
- attitude: a,
- areaName: o
- }),
- this.room.skinChangedHook(),
- this.room.emit("skinChanged", {
- skin: {
- id: t
- },
- mode: r
- }),
- n === RenderType.ClientRotationPano && this.room.sceneManager.cameraComponent.allowMainCameraController()
- }
- )
- }
- rotate({pitch: e, yaw: t}) {
- var n;
- if (this.room.disableRotate || this.room.isPano || ((n = this.room._userAvatar) == null ? void 0 : n._isChangingComponentsMode))
- return;
- const r = {
- action_type: Actions.Rotation,
- rotation_action: {
- vertical_move: e,
- horizontal_move: -t
- }
- };
- this.sendData({
- data: r,
- sampleRate: .02
- })
- }
- turnTo(e) {
- const {point: t, timeout: r=2e3, offset: n=8} = e || {}
- , o = {
- action_type: Actions.TurnTo,
- turn_to_action: {
- turn_to_point: t,
- offset: n
- }
- };
- return this.sendData({
- data: o,
- timeout: r
- })
- }
- rotateTo(e) {
- const {point: t, offset: r=0, speed: n=3} = e || {}
- , o = {
- action_type: Actions.RotateTo,
- rotate_to_action: {
- rotate_to_point: t,
- offset: r,
- speed: n
- }
- };
- return this.sendData({
- data: o
- })
- }
- broadcast(e) {
- const {data: t, msgType: r=MessageHandleType.MHT_FollowListMulticast, targetUserIds: n} = e;
- if (r === MessageHandleType.MHT_CustomTargetSync && !Array.isArray(n))
- return Promise.reject(new ParamError(`param targetUserIds is required when msgType is ${MessageHandleType[r]}`));
- const o = {
- action_type: Actions.Broadcast,
- broadcast_action: {
- data: JSON.stringify(t),
- user_id: this.room.options.userId,
- msgType: r
- }
- };
- return Array.isArray(n) && r === MessageHandleType.MHT_CustomTargetSync && (o.broadcast_action.target_user_ids = n),
- this.room.actionsHandler.sendData({
- data: o,
- tag: t.broadcastType
- })
- }
- getNeighborPoints(e) {
- const {point: t, containSelf: r=!1, searchRange: n=500} = e
- , o = {
- action_type: Actions.GetNeighborPoints,
- get_neighbor_points_action: {
- point: t,
- level: 1,
- containSelf: r,
- searchRange: n
- }
- };
- return this.sendData({
- data: o
- }).then(a=>a.nps)
- }
- playCG(e) {
- const t = {
- action_type: Actions.PlayCG,
- play_cg_action: {
- cg_name: e
- }
- };
- return this.sendData({
- data: t
- })
- }
- audienceToVisitor(e) {
- const {avatarId: t, avatarComponents: r, player: n, camera: o} = e
- , a = {
- action_type: Actions.AudienceChangeToVisitor,
- audienceChangeToVisitorAction: {
- avatarID: t,
- avatarComponents: r,
- player: n,
- camera: o
- }
- };
- return log$p.debug("send data: audience to visitor"),
- this.sendData({
- data: a
- })
- }
- visitorToAudience(e) {
- const {renderType: t, player: r, camera: n, areaName: o, attitude: a, pathName: s, person: l, noMedia: u} = e
- , c = {
- action_type: Actions.VisitorChangeToAudience,
- visitorChangeToAudienceAction: {
- transferAction: {
- render_type: t,
- player: r,
- camera: n,
- areaName: o,
- attitude: a,
- pathName: s,
- person: {
- type: l
- },
- noMedia: u,
- tiles: [0, 1, 2, 4]
- }
- }
- };
- return log$p.debug("send data: visitor to audience"),
- this.sendData({
- data: c
- })
- }
- removeVisitor(e) {
- const {removeType: t, userIDList: r, extraInfo: n=""} = e
- , o = {
- action_type: Actions.RemoveVisitor,
- removeVisitorAction: {
- removeVisitorEvent: t,
- userIDList: r,
- extraInfo: encodeURIComponent(n)
- }
- };
- return log$p.debug("send data: remove visitor"),
- this.sendData({
- data: o
- })
- }
- getUserWithAvatar(e, t) {
- const r = {
- action_type: Actions.GetUserWithAvatar,
- getUserWithAvatarAction: {
- userType: e,
- roomID: t
- }
- };
- return log$p.debug("send data: get user with avatar"),
- this.sendData({
- data: r
- }).then(n=>n.userWithAvatarList)
- }
- joystick(e) {
- const {degree: t, level: r=1} = e
- , n = uuid$1();
- let o = -t + 90 + 360;
- o >= 360 && (o -= 360);
- const a = {
- action_type: Actions.Joystick,
- dir_action: {
- move_angle: o,
- speed_level: r
- },
- trace_id: n,
- user_id: this.room.options.userId,
- packet_id: n
- };
- return this.sendData({
- data: a,
- track: !1
- })
- }
- }
|