Skip to content

thor.js API

Ashwin Kandel edited this page Apr 11, 2017 · 2 revisions

Public functions

thor = new thor(address, enable_server)

creates new instance of thor

The address refers to signalling server address and enable_server is a boolean value

thor.start()

starts thor object. will login once connection is established

thor.connect(name)

connects to user with username name

thor.setPageWise(infoHash)

sets pagewise mode with infohash as infoHash

thor.seedFile(blob, infoHash)

seeds an already existing file blob with info hash infoHash

Private functions

onmessage(message)

decides how to response to signaling server when message received

randomUserName()

generates 20 chracter random user name

login()

sends login message to server

onLogin(success)

captures user name is sucess is true else display failure message

statusLoop()

Sends seeds/request message to tracker server for every file in file dictionary. If pagewise mode, then sends pagewise data also

controlLoop()

runs control loop

onOffer(offer, name)

responds to offer received from peer with name name

onAnswer(answer, name)

responds to answer received from peer name

onReceiveCandidate(candidate, name)

responds to candidate request from peer name

onResponse(answer)

reacts to response received from server as answer