Skip to content

Instantly share code, notes, and snippets.

@m4rk4
Created October 30, 2020 01:53
Show Gist options
  • Save m4rk4/706745226f5a89cb1833dbb4507605e0 to your computer and use it in GitHub Desktop.
Save m4rk4/706745226f5a89cb1833dbb4507605e0 to your computer and use it in GitHub Desktop.
espn-fcast
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);
});
@barrars
Copy link

barrars commented Feb 2, 2025

@m4rk4 youre a genius. how'd you figure this out?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment