Skip to content

Commit

Permalink
fix: update xmldom (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickmichalina authored Dec 27, 2019
1 parent 59a0e0e commit 42c9789
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .node-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
12.11.1
13.5.0
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
12.11.1
13.5.0
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"bin": {
"camera-probe": "dist/camera-probe"
},
"files": ["dist"],
"scripts": {
"test": "jest",
"test.watch": "jest --watch",
Expand All @@ -45,11 +46,11 @@
"ping-rx": "^1.0.0",
"rxjs": "^6.5.3",
"typescript-monads": "^3.13.0",
"xmldom": "^0.1.27"
"xmldom": "^0.2.1"
},
"devDependencies": {
"@types/jest": "^24.0.24",
"@types/node": "^13.1.0",
"@types/jest": "^24.0.25",
"@types/node": "^13.1.1",
"@types/xmldom": "^0.1.29",
"jest": "^24.9.0",
"rollup": "^1.27.14",
Expand Down
16 changes: 15 additions & 1 deletion src/ws-discovery/ws-probe.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createSocket } from 'dgram'
import { wsProbe } from './ws-probe'
import { wsProbe, mapDeviceStrToPayload } from './ws-probe'
import { Subject } from 'rxjs'
import { DOMParser } from 'xmldom'

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>'

Expand Down Expand Up @@ -39,4 +40,17 @@ describe('ws probe', () => {
done()
})
})

it('mapDeviceStrToPayload', () => {
const sut = mapDeviceStrToPayload('test123')
const dom = new DOMParser().parseFromString(sut, 'application/xml')

const elements = dom.documentElement.getElementsByTagNameNS('http://schemas.xmlsoap.org/ws/2004/08/addressing', 'MessageID')
const messsageId = elements.item(0)?.childNodes.item(0).textContent || ''
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)

const typesElements = dom.documentElement.getElementsByTagName('Types')
const types = typesElements.item(0)?.childNodes.item(0).textContent
expect(types?.trim()).toEqual('dp0:test123')
})
})
4 changes: 2 additions & 2 deletions src/ws-discovery/ws-probe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { probe } from '../core/probe'
import { IWsProbeConfig, IWsResponse } from './ws-probe.interfaces'
import { DEFAULT_WS_PROBE_CONFIG } from './config'

const mapDeviceStrToPayload = (str: string) => generateWsDiscoveryProbePayload(generateGuid())(str)
const mapDevicesToPayloads = (devices: readonly string[]) => devices.map(mapDeviceStrToPayload)
export const mapDeviceStrToPayload = (str: string) => generateWsDiscoveryProbePayload(generateGuid())(str)
export const mapDevicesToPayloads = (devices: readonly string[]) => devices.map(mapDeviceStrToPayload)

export const wsProbe =
(config?: Partial<IWsProbeConfig>): IWsResponse => {
Expand Down

0 comments on commit 42c9789

Please sign in to comment.