1 | import DeviceId from './types/DeviceId'
|
2 | import RandomIntGenerator from './RandomIntGenerator'
|
3 |
|
4 | const makeUuidv4 = () => {
|
5 | return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
|
6 | const r = (Math.random() * 16) | 0
|
7 | const v = c === 'x' ? r : (r & 0x3) | 0x8
|
8 | return v.toString(16)
|
9 | })
|
10 | }
|
11 |
|
12 | export default () => {
|
13 | const uuid = makeUuidv4()
|
14 | const deviceId = uuid
|
15 | const clientId = uuid.substring(0, 20)
|
16 | const mqttId = RandomIntGenerator.generate()
|
17 | return { clientId, deviceId, mqttId } as DeviceId
|
18 | }
|