New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@cryptovoxels/messages

Package Overview
Dependencies
Maintainers
4
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cryptovoxels/messages - npm Package Compare versions

Comparing version 1.5.0 to 2.0.0-0

.circleci/config.yml

13

dist/index.d.ts

@@ -11,3 +11,2 @@ export { Emotes } from './constant';

createAvatar = 50,
moveAvatar = 52,
destroyAvatar = 53,

@@ -120,11 +119,2 @@ updateAvatar = 54,

export declare const WompMessageEncoder: (msg: WompMessage) => Uint8Array;
export declare type MoveAvatarMessage = {
type: MessageType.moveAvatar;
uuid: string;
position: number[];
rotation: number[];
neckRotation: number[];
animation: string;
};
export declare const MoveAvatarEncoder: (msg: MoveAvatarMessage) => Uint8Array;
export declare type UpdateAvatarMessage = {

@@ -135,3 +125,2 @@ type: MessageType.updateAvatar;

rotation: number[];
neckRotation: number[];
animation: number;

@@ -156,3 +145,3 @@ };

export declare const DestroyAvatarEncoder: (msg: DestroyAvatarMessage) => Uint8Array;
export declare type Message = PingMessage | PongMessage | AnonMessage | LoginMessage | LoginCompleteMessage | TrafficMessage | ChatMessage | AvatarEmoteMessage | MemeCubeMessage | NewCostumeMessage | TypingMessage | VoiceStateMessage | WompMessage | CreateAvatarMessage | MoveAvatarMessage | UpdateAvatarMessage | JoinMessage | WorldStateMessage | DestroyAvatarMessage | AvatarChangedMessage;
export declare type Message = PingMessage | PongMessage | AnonMessage | LoginMessage | LoginCompleteMessage | TrafficMessage | ChatMessage | AvatarEmoteMessage | MemeCubeMessage | NewCostumeMessage | TypingMessage | VoiceStateMessage | WompMessage | CreateAvatarMessage | UpdateAvatarMessage | JoinMessage | WorldStateMessage | DestroyAvatarMessage | AvatarChangedMessage;
export declare const GenericEncoder: (msg: Message) => Uint8Array;

@@ -22,3 +22,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.GenericEncoder = exports.DestroyAvatarEncoder = exports.WorldStateEncoder = exports.JoinEncoder = exports.UpdateAvatarEncoder = exports.MoveAvatarEncoder = exports.WompMessageEncoder = exports.VoiceStateMessageEncoder = exports.AvatarVoiceState = exports.TypingMessageEncoder = exports.NewCostumeEncoder = exports.MemeCubeEncoder = exports.EmoteEncoder = exports.AvatarChangedEncoder = exports.CreateAvatarEncoder = exports.ChatEncoder = exports.TrafficEncoder = exports.LoginCompleteEncoder = exports.LoginEncoder = exports.AnonEncoder = exports.PongEncoder = exports.PingEncoder = exports.decode = exports.MessageType = exports.Emotes = void 0;
exports.GenericEncoder = exports.DestroyAvatarEncoder = exports.WorldStateEncoder = exports.JoinEncoder = exports.UpdateAvatarEncoder = exports.WompMessageEncoder = exports.VoiceStateMessageEncoder = exports.AvatarVoiceState = exports.TypingMessageEncoder = exports.NewCostumeEncoder = exports.MemeCubeEncoder = exports.EmoteEncoder = exports.AvatarChangedEncoder = exports.CreateAvatarEncoder = exports.ChatEncoder = exports.TrafficEncoder = exports.LoginCompleteEncoder = exports.LoginEncoder = exports.AnonEncoder = exports.PongEncoder = exports.PingEncoder = exports.decode = exports.MessageType = exports.Emotes = void 0;
const msgpack_1 = require("@msgpack/msgpack");

@@ -42,3 +42,2 @@ const uuidParse = __importStar(require("uuid-parse"));

MessageType[MessageType["createAvatar"] = 50] = "createAvatar";
MessageType[MessageType["moveAvatar"] = 52] = "moveAvatar";
MessageType[MessageType["destroyAvatar"] = 53] = "destroyAvatar";

@@ -130,27 +129,4 @@ MessageType[MessageType["updateAvatar"] = 54] = "updateAvatar";

exports.WompMessageEncoder = encoderCreator();
exports.MoveAvatarEncoder = encoderCreator();
// A codec that only encodes the MoveAvatar data to an array we 'compress' this very common (124b/183b)
// in reality the message is smaller due to the avatar rotation and neck rotations Z axis is zero:d out since we dont tilt avatars
extensionCodec.register({
type: MessageType.moveAvatar,
encode: (input) => {
if (input.type != MessageType.moveAvatar) {
return null;
}
return msgpack_1.encode([uuidParse.parse(input.uuid), input.position, input.rotation, input.neckRotation, input.animation]);
},
decode: (data) => {
const res = msgpack_1.decode(data);
return {
type: MessageType.moveAvatar,
uuid: uuidParse.unparse(res[0]),
position: res[1],
rotation: res[2],
neckRotation: res[3],
animation: res[4],
};
},
});
exports.UpdateAvatarEncoder = encoderCreator();
// A codec that only encodes the MoveAvatar data to an array we 'compress' this very common (124b/183b)
// A codec that only encodes the updateAvatar data to an array we 'compress' this very common (124b/183b)
// in reality the message is smaller due to the avatar rotation and neck rotations Z axis is zero:d out since we dont tilt avatars

@@ -163,3 +139,3 @@ extensionCodec.register({

}
return msgpack_1.encode([uuidParse.parse(input.uuid), Float32Array.from(input.position), Float32Array.from(input.rotation), Float32Array.from(input.neckRotation), input.animation]);
return msgpack_1.encode([uuidParse.parse(input.uuid), Float32Array.from(input.position), Float32Array.from(input.rotation), input.animation]);
},

@@ -173,4 +149,3 @@ decode: (data) => {

rotation: uint8ToFloat32(res[2]),
neckRotation: uint8ToFloat32(res[3]),
animation: res[4],
animation: res[3],
};

@@ -177,0 +152,0 @@ },

{
"name": "@cryptovoxels/messages",
"version": "1.5.0",
"version": "2.0.0-0",
"description": "common protocol for multiplayer messages",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

import { Decoder, Encoder, decode as decodeAlias, encode, ExtensionCodec } from '@msgpack/msgpack'
import * as uuidParse from 'uuid-parse'
export {Emotes} from './constant';
export { Emotes } from './constant'
const extensionCodec = new ExtensionCodec()

@@ -20,3 +20,2 @@

createAvatar = 50,
moveAvatar = 52,
destroyAvatar = 53,

@@ -34,3 +33,3 @@ updateAvatar = 54,

voiceStateAvatar = 64,
womp = 65
womp = 65,
}

@@ -148,3 +147,2 @@

// 57

@@ -204,3 +202,3 @@ export type AvatarChangedMessage = {

uuid: string
state:AvatarVoiceState
state: AvatarVoiceState
}

@@ -214,41 +212,7 @@

uuid: string
id:number
id: number
}
export const WompMessageEncoder = encoderCreator<WompMessage>()
export const WompMessageEncoder = encoderCreator<WompMessage>()
// @deprecated in favor of the update avatar message
export type MoveAvatarMessage = {
type: MessageType.moveAvatar
uuid: string
position: number[]
rotation: number[]
neckRotation: number[]
animation: string
}
export const MoveAvatarEncoder = encoderCreator<MoveAvatarMessage>()
// A codec that only encodes the MoveAvatar data to an array we 'compress' this very common (124b/183b)
// in reality the message is smaller due to the avatar rotation and neck rotations Z axis is zero:d out since we dont tilt avatars
extensionCodec.register({
type: MessageType.moveAvatar,
encode: (input: MoveAvatarMessage) => {
if (input.type != MessageType.moveAvatar) {
return null
}
return encode([uuidParse.parse(input.uuid), input.position, input.rotation, input.neckRotation, input.animation])
},
decode: (data): MoveAvatarMessage => {
const res = decodeAlias(data) as any[]
return {
type: MessageType.moveAvatar,
uuid: uuidParse.unparse(res[0]),
position: res[1],
rotation: res[2],
neckRotation: res[3],
animation: res[4],
}
},
})
// replacement for the MoveAvatarMessage with the difference of sending animation as a number instead
export type UpdateAvatarMessage = {

@@ -259,3 +223,2 @@ type: MessageType.updateAvatar

rotation: number[]
neckRotation: number[]
animation: number

@@ -265,3 +228,3 @@ }

export const UpdateAvatarEncoder = encoderCreator<UpdateAvatarMessage>()
// A codec that only encodes the MoveAvatar data to an array we 'compress' this very common (124b/183b)
// A codec that only encodes the updateAvatar data to an array we 'compress' this very common (124b/183b)
// in reality the message is smaller due to the avatar rotation and neck rotations Z axis is zero:d out since we dont tilt avatars

@@ -274,3 +237,3 @@ extensionCodec.register({

}
return encode([uuidParse.parse(input.uuid), Float32Array.from(input.position), Float32Array.from(input.rotation), Float32Array.from(input.neckRotation), input.animation])
return encode([uuidParse.parse(input.uuid), Float32Array.from(input.position), Float32Array.from(input.rotation), input.animation])
},

@@ -285,4 +248,3 @@ decode: (data): UpdateAvatarMessage => {

rotation: uint8ToFloat32(res[2]),
neckRotation: uint8ToFloat32(res[3]),
animation: res[4],
animation: res[3],
}

@@ -393,3 +355,2 @@ },

| CreateAvatarMessage
| MoveAvatarMessage
| UpdateAvatarMessage

@@ -396,0 +357,0 @@ | JoinMessage

@@ -32,3 +32,2 @@ import test from 'tape'

rotation: arbitraryVector,
neckRotation: arbitraryVector,
animation: fc.integer(),

@@ -121,3 +120,3 @@ })

wallet: arbitraryWalletOrAnon,
cacheKey:fc.integer()
cacheKey: fc.integer(),
}),

@@ -131,3 +130,3 @@ encoder: msg.AvatarChangedEncoder,

uuid: fc.uuid(),
cacheKey:fc.integer()
cacheKey: fc.integer(),
}),

@@ -150,3 +149,3 @@ encoder: msg.NewCostumeEncoder,

uuid: fc.uuid(),
state:fc.integer(),
state: fc.integer(),
}),

@@ -160,14 +159,2 @@ encoder: msg.VoiceStateMessageEncoder,

}),
[msg.MessageType.moveAvatar]: cast<msg.MoveAvatarMessage>({
name: 'moveAvatar',
arbitrary: fc.record({
type: fc.constant(msg.MessageType.moveAvatar),
uuid: fc.uuid(),
position: maybeNullUnsafe(arbitraryVectorWithMaybeNullElements),
rotation: maybeNullUnsafe(arbitraryVectorWithMaybeNullElements),
neckRotation: maybeNullUnsafe(arbitraryVectorWithMaybeNullElements),
animation: fc.string(),
}),
encoder: msg.MoveAvatarEncoder,
}),
[msg.MessageType.updateAvatar]: cast<msg.UpdateAvatarMessage>({

@@ -174,0 +161,0 @@ name: 'updateAvatar',

@@ -24,3 +24,2 @@ import test, { Test } from 'tape'

const tests: TestCase[] = [

@@ -34,11 +33,10 @@ createTestCase(msg.PingEncoder, 7, { type: msg.MessageType.ping }),

createTestCase(msg.ChatEncoder, 74, { type: msg.MessageType.chat, channel: 'a', name: 'b', uuid: uuid, text: 'd' }),
createTestCase(msg.EmoteEncoder, 59, { type: msg.MessageType.emoteAvatar, uuid: uuid, emote:':)' }),
createTestCase(msg.MemeCubeEncoder, 91, { type: msg.MessageType.memecube, uuid: uuid, url:'https://www.giphy.com/whateveer.gif' }),
createTestCase(msg.VoiceStateMessageEncoder, 57, { type: msg.MessageType.voiceStateAvatar, uuid: uuid, state:0 }),
createTestCase(msg.AvatarChangedEncoder, 62, { type: msg.MessageType.avatarChanged, wallet: wallet, cacheKey:5000 }),
createTestCase(msg.NewCostumeEncoder, 62, { type: msg.MessageType.newCostume, uuid: uuid, cacheKey:5000 }),
createTestCase(msg.WompMessageEncoder, 54, { type: msg.MessageType.womp, uuid: uuid,id:5 }),
createTestCase(msg.EmoteEncoder, 59, { type: msg.MessageType.emoteAvatar, uuid: uuid, emote: ':)' }),
createTestCase(msg.MemeCubeEncoder, 91, { type: msg.MessageType.memecube, uuid: uuid, url: 'https://www.giphy.com/whateveer.gif' }),
createTestCase(msg.VoiceStateMessageEncoder, 57, { type: msg.MessageType.voiceStateAvatar, uuid: uuid, state: 0 }),
createTestCase(msg.AvatarChangedEncoder, 70, { type: msg.MessageType.avatarChanged, wallet: wallet, cacheKey: 5000 }),
createTestCase(msg.NewCostumeEncoder, 62, { type: msg.MessageType.newCostume, uuid: uuid, cacheKey: 5000 }),
createTestCase(msg.WompMessageEncoder, 54, { type: msg.MessageType.womp, uuid: uuid, id: 5 }),
createTestCase(msg.TypingMessageEncoder, 50, { type: msg.MessageType.typing, uuid: uuid }),
createTestCase(msg.CreateAvatarEncoder, 71, { type: msg.MessageType.createAvatar, uuid: uuid, description: { name: 'a', wallet: wallet } }),
createTestCase(msg.MoveAvatarEncoder, 125, { type: msg.MessageType.moveAvatar, uuid: uuid, position: [1.23, 4.56, 7.89], rotation: [1.23, 4.56, 7.89], neckRotation: [1.23, 4.56, 7.89], animation: 'Running' }),
]

@@ -59,3 +57,3 @@

const tests: { encoder: (msg: msg.UpdateAvatarMessage) => Uint8Array; size: number; msg: msg.UpdateAvatarMessage }[] = [
{ encoder: msg.UpdateAvatarEncoder, size: 76, msg: { type: msg.MessageType.updateAvatar, uuid: uuid, position: [1.23, 4.56, 7.89], rotation: [1.23, 4.56, 7.89], neckRotation: [1.23, 4.56, 7.89], animation: 2 } },
{ encoder: msg.UpdateAvatarEncoder, size: 62, msg: { type: msg.MessageType.updateAvatar, uuid: uuid, position: [1.23, 4.56, 7.89], rotation: [1.23, 4.56, 7.89], animation: 2 } },
]

@@ -69,3 +67,2 @@ tests.forEach((tc) => {

equalF32Array(t, decoded.rotation, tc.msg.rotation, 'rotation')
equalF32Array(t, decoded.neckRotation, tc.msg.neckRotation, 'neckRotation')
t.equal(encoded.length, tc.size, `encoded size is ${tc.size}`)

@@ -78,9 +75,9 @@ })

const avatars: msg.UpdateAvatarMessage[] = [
{ type: msg.MessageType.updateAvatar, uuid: '11111111-2a2c-47db-abae-e7b3dbf64104', position: [1.23, 4.56, 7.89], rotation: [1.23, 4.56, 7.89], neckRotation: [1.23, 4.56, 7.89], animation: 2 },
{ type: msg.MessageType.updateAvatar, uuid: '22222222-2a2c-47db-abae-e7b3dbf64104', position: [9.87, 6.54, 3.21], rotation: [9.87, 6.54, 3.21], neckRotation: [9.87, 6.54, 3.21], animation: 1 },
{ type: msg.MessageType.updateAvatar, uuid: '33333333-2a2c-47db-abae-e7b3dbf64104', position: [6.54, 9.87, 3.21], rotation: [6.54, 9.87, 3.21], neckRotation: [6.54, 9.87, 3.21], animation: 0 },
{ type: msg.MessageType.updateAvatar, uuid: '11111111-2a2c-47db-abae-e7b3dbf64104', position: [1.23, 4.56, 7.89], rotation: [1.23, 4.56, 7.89], animation: 2 },
{ type: msg.MessageType.updateAvatar, uuid: '22222222-2a2c-47db-abae-e7b3dbf64104', position: [9.87, 6.54, 3.21], rotation: [9.87, 6.54, 3.21], animation: 1 },
{ type: msg.MessageType.updateAvatar, uuid: '33333333-2a2c-47db-abae-e7b3dbf64104', position: [6.54, 9.87, 3.21], rotation: [6.54, 9.87, 3.21], animation: 0 },
]
const encoded = WorldStateEncoder({ type: msg.MessageType.worldState, avatars: avatars })
t.equal(encoded.length, 224, 'encoded message size is correct')
t.equal(encoded.length, 182, 'encoded message size is correct')
const decoded: WorldStateMessage = msg.decode(encoded)

@@ -94,3 +91,2 @@ t.equal(decoded.avatars.length, 3, 'we have three avatar update messages')

equalF32Array(t, v.rotation, avatars[i].rotation, `avatar[${i}] rotation`)
equalF32Array(t, v.neckRotation, avatars[i].neckRotation, `avatar[${i}] neckRotation`)
})

@@ -102,5 +98,5 @@ t.end()

const avatars: msg.UpdateAvatarMessage[] = [
{ type: msg.MessageType.updateAvatar, uuid: '11111111-2a2c-47db-abae-e7b3dbf64104', position: [1.23, 4.56, 7.89], rotation: [1.23, 4.56, 7.89], neckRotation: [1.23, 4.56, 7.89], animation: 2 },
{ type: msg.MessageType.updateAvatar, uuid: '22222222-2a2c-47db-abae-e7b3dbf64104', position: [9.87, 6.54, 3.21], rotation: [9.87, 6.54, 3.21], neckRotation: [9.87, 6.54, 3.21], animation: 1 },
{ type: msg.MessageType.updateAvatar, uuid: '33333333-2a2c-47db-abae-e7b3dbf64104', position: [6.54, 9.87, 3.21], rotation: [6.54, 9.87, 3.21], neckRotation: [6.54, 9.87, 3.21], animation: 0 },
{ type: msg.MessageType.updateAvatar, uuid: '11111111-2a2c-47db-abae-e7b3dbf64104', position: [1.23, 4.56, 7.89], rotation: [1.23, 4.56, 7.89], animation: 2 },
{ type: msg.MessageType.updateAvatar, uuid: '22222222-2a2c-47db-abae-e7b3dbf64104', position: [9.87, 6.54, 3.21], rotation: [9.87, 6.54, 3.21], animation: 1 },
{ type: msg.MessageType.updateAvatar, uuid: '33333333-2a2c-47db-abae-e7b3dbf64104', position: [6.54, 9.87, 3.21], rotation: [6.54, 9.87, 3.21], animation: 0 },
]

@@ -121,3 +117,3 @@

const encoded = JoinEncoder(joinMsg)
t.equal(encoded.length, 403, 'encoded message size is correct')
t.equal(encoded.length, 361, 'encoded message size is correct')
const decoded: JoinMessage = msg.decode(encoded)

@@ -130,3 +126,2 @@ t.equal(decoded.type, msg.MessageType.join)

equalF32Array(t, v.rotation, avatars[i].rotation, `avatar[${i}] rotation`)
equalF32Array(t, v.neckRotation, avatars[i].neckRotation, `avatar[${i}] neckRotation`)
})

@@ -133,0 +128,0 @@ decoded.createAvatars.forEach((v, i: number) => {

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc