Created
October 30, 2020 01:53
-
-
Save m4rk4/706745226f5a89cb1833dbb4507605e0 to your computer and use it in GitHub Desktop.
espn-fcast
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var socket; | |
var fcastUrl; | |
fetch('https://fastcast.semfs.engsvc.go.com/public/websockethost') | |
.then( | |
function(response) { | |
if (response.status !== 200) { | |
console.log('Looks like there was a problem. Status Code: ' + response.status); | |
return; | |
} | |
// Examine the text in the response | |
response.json().then(function(data) { | |
console.log(data); | |
var wsUri = 'wss://'+data.ip+':'+data.securePort+'/FastcastService/pubsub/profiles/12000?TrafficManager-Token='+data.token; | |
console.log(wsUri); | |
socket = new WebSocket(wsUri); | |
socket.onopen = function(event) { | |
console.log('socket open: ' + event.data); | |
socket.send('{"op": "C"}'); | |
}; | |
socket.onmessage = function(event) { | |
console.log('socket message received from server: ' + event.data); | |
var data = JSON.parse(event.data); | |
console.log('op = ' + data.op); | |
if (data.op == 'C') { | |
var msg = { | |
op: "S", | |
sid: data.sid, | |
tc: "event-topevents" | |
}; | |
socket.send(JSON.stringify(msg)); | |
} else if (data.op == 'H') { | |
fcastUrl = data.pl; | |
} | |
}; | |
}); | |
} | |
) | |
.catch(function(err) { | |
console.log('Fetch Error :-S', err); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@m4rk4 youre a genius. how'd you figure this out?