Skip to content

Commit 42c9789

Browse files
fix: update xmldom (#48)
1 parent 59a0e0e commit 42c9789

File tree

6 files changed

+32
-17
lines changed

6 files changed

+32
-17
lines changed

.node-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
12.11.1
1+
13.5.0

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
12.11.1
1+
13.5.0

package-lock.json

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"bin": {
3333
"camera-probe": "dist/camera-probe"
3434
},
35+
"files": ["dist"],
3536
"scripts": {
3637
"test": "jest",
3738
"test.watch": "jest --watch",
@@ -45,11 +46,11 @@
4546
"ping-rx": "^1.0.0",
4647
"rxjs": "^6.5.3",
4748
"typescript-monads": "^3.13.0",
48-
"xmldom": "^0.1.27"
49+
"xmldom": "^0.2.1"
4950
},
5051
"devDependencies": {
51-
"@types/jest": "^24.0.24",
52-
"@types/node": "^13.1.0",
52+
"@types/jest": "^24.0.25",
53+
"@types/node": "^13.1.1",
5354
"@types/xmldom": "^0.1.29",
5455
"jest": "^24.9.0",
5556
"rollup": "^1.27.14",

src/ws-discovery/ws-probe.spec.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { createSocket } from 'dgram'
2-
import { wsProbe } from './ws-probe'
2+
import { wsProbe, mapDeviceStrToPayload } from './ws-probe'
33
import { Subject } from 'rxjs'
4+
import { DOMParser } from 'xmldom'
45

56
const wsXmlResponse = '<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope" xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsdd="http://schemas.xmlsoap.org/ws/2005/04/discovery" xmlns:vfdis="http://www.onvif.org/ver10/network/wsdl/RemoteDiscoveryBinding" xmlns:vfdis2="http://www.onvif.org/ver10/network/wsdl/DiscoveryLookupBinding" xmlns:tdn="http://www.onvif.org/ver10/network/wsdl"><SOAP-ENV:Header><wsa:MessageID>uuid:2709d68a-7dc1-61c2-a205-X3018101811662</wsa:MessageID><wsa:RelatesTo>uuid:NetworkVideoTransmitter</wsa:RelatesTo><wsa:ReplyTo SOAP-ENV:mustUnderstand="true"><wsa:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:Address></wsa:ReplyTo><wsa:To SOAP-ENV:mustUnderstand="true">http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To><wsa:Action SOAP-ENV:mustUnderstand="true">http://schemas.xmlsoap.org/ws/2005/04/discovery/ProbeMatches</wsa:Action></SOAP-ENV:Header><SOAP-ENV:Body><wsdd:ProbeMatches><wsdd:ProbeMatch><wsa:EndpointReference><wsa:Address>urn:uuid:2419d68a-2dd2-21b2-a205-X2018101811779</wsa:Address><wsa:ReferenceProperties></wsa:ReferenceProperties><wsa:ReferenceParameters></wsa:ReferenceParameters><wsa:PortType>ttl</wsa:PortType></wsa:EndpointReference><wsdd:Types>tdn:4655721b-4e0e-4296-ba0b-3180423b5b0c</wsdd:Types><wsdd:Scopes>onvif://www.onvif.org/Profile/Streaming onvif://www.onvif.org/Model/631GA onvif://www.onvif.org/Name/IPCAM onvif://www.onvif.org/location/country/china</wsdd:Scopes><wsdd:XAddrs>http://192.168.1.1:80/onvif/device_service</wsdd:XAddrs><wsdd:MetadataVersion>1</wsdd:MetadataVersion></wsdd:ProbeMatch></wsdd:ProbeMatches></SOAP-ENV:Body></SOAP-ENV:Envelope>'
67

@@ -39,4 +40,17 @@ describe('ws probe', () => {
3940
done()
4041
})
4142
})
43+
44+
it('mapDeviceStrToPayload', () => {
45+
const sut = mapDeviceStrToPayload('test123')
46+
const dom = new DOMParser().parseFromString(sut, 'application/xml')
47+
48+
const elements = dom.documentElement.getElementsByTagNameNS('http://schemas.xmlsoap.org/ws/2004/08/addressing', 'MessageID')
49+
const messsageId = elements.item(0)?.childNodes.item(0).textContent || ''
50+
expect(/uuid:[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}/gi.test(messsageId)).toEqual(true)
51+
52+
const typesElements = dom.documentElement.getElementsByTagName('Types')
53+
const types = typesElements.item(0)?.childNodes.item(0).textContent
54+
expect(types?.trim()).toEqual('dp0:test123')
55+
})
4256
})

src/ws-discovery/ws-probe.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { probe } from '../core/probe'
55
import { IWsProbeConfig, IWsResponse } from './ws-probe.interfaces'
66
import { DEFAULT_WS_PROBE_CONFIG } from './config'
77

8-
const mapDeviceStrToPayload = (str: string) => generateWsDiscoveryProbePayload(generateGuid())(str)
9-
const mapDevicesToPayloads = (devices: readonly string[]) => devices.map(mapDeviceStrToPayload)
8+
export const mapDeviceStrToPayload = (str: string) => generateWsDiscoveryProbePayload(generateGuid())(str)
9+
export const mapDevicesToPayloads = (devices: readonly string[]) => devices.map(mapDeviceStrToPayload)
1010

1111
export const wsProbe =
1212
(config?: Partial<IWsProbeConfig>): IWsResponse => {

0 commit comments

Comments
 (0)